KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Return Main Screen number
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: November 25, 2015

Below is an utility method to get the screen number that the main screen is assigned to in 4D. This number can be used in 4D commands like SCREEN COORDINATES, SCREEN WIDTH, and SCREEN HEIGHT.

//Method name:SCREEN_GET_MAIN
//Gets the number of the main screen.
//This number can be used in 4D's Screen commands
//
//$0 - Main screen's number

C_LONGINT($numScreens;$mainScreen;$i)
C_LONGINT($mLeft;$mTop;$mRight;$mBottom)
C_LONGINT($left;$right;$top;$bottom)

$numScreens:=Count screens

//Get main screen coordinates
SCREEN COORDINATES($mLeft;$mTop;$mRight;$mBottom)

$mainScreen:=-1
For ($i;1;$numScreens)
   SCREEN COORDINATES($left;$top;$right;$bottom;$i)
   If ($left=$mLeft) & ($top=$mTop) & ($right=$mRight) & ($bottom=$mBottom)
      $mainScreen:=$i
   End if
End for
$0:=$mainScreen

Example:
$mainScreenNum:=SCREEN_GET_MAIN