getScreenSize()

Reads the current size of the given screens in pixel.

Synopsis

int getScreenSize(int &width, int &height [[, bool availableSize], int &startX, int &startY, int screenNum = -1]);

Parameters

Parameter Description
&width Screen width in pixel
&height Screen height in pixel
availableSize Optional parameter. When availableSize is set to true, the returned screen size will exclude the area for the taskbar. In other words, it returns only the available screen size.
&startX Optional parameter. Left start position of this screen
&startY Optional parameter. Top start position of this screen
screenNum Optional parameter. Screen number ((-1 = all; 0 = primary; 1 = second etc.)

Return value

Screen size

Description

This function reads the current resolution of the screen. The values written to the parameters are pixels.

Example

main()
{
   int x, y;
   getScreenSize(x, y);
   DebugN("Screen width:" + x, "Screen height:" + y);
}

Please note that the screen numbers used in WinCC OA may not be matching with the screen numbers displayed inside of the Windows screen configuration. To create a usable order of the screen numbers following code can be used:

 *  This function delivers the real screen informations for the current workstation.
 *  The monitor numbers are sorted by following order and not by the numbers given in the Windows monitor setting.
 *  The monitors are numbered from left top to right bottom, which means that the top left monitor uses the number 1.
 *
 *  The mapping looks for example like this:
 *    mapping 2 items
 *      1 :     mapping 4 items
 *        "ScreenStartX" : 0
 *        "ScreenStartY" : 0
 *        "ScreenWidth" : 1680
 *        "ScreenHeight" : 1050
 *      2 :     mapping 4 items
 *        "ScreenStartX" : 1680
 *        "ScreenStartY" : 0
 *        "ScreenWidth" : 1680
 *        "ScreenHeight" : 1050
 *
 *  @param -
 *
 *  @return will return mapping with the real screensizes from this machine
 */
//----------------------------------------------------------------------------------------------
private mapping mmGetMyRealScreenSizes()
{
  mapping mMyScreenSize;
  dyn_dyn_int ddiScreenSituation;

  // iterate through the existing screens and save there size and location
  for(int i = 0; i <= getScreenCount()-1; i++)
  {
    ddiScreenSituation[i+1] = makeDynInt();
    getScreenSize(ddiScreenSituation[i+1][1], ddiScreenSituation[i+1][2],
                  ddiScreenSituation[i+1][3], ddiScreenSituation[i+1][4], i);
  }
  // Sort the screens by location X and Y
  dynDynSort(ddiScreenSituation, makeDynInt(4,3));

  // Fill the mapping in the order of the sorting with the size information
  for(int i=1; i<=dynlen(ddiScreenSituation); i++)
  {
    mMyScreenSize[i] = makeMapping();
    mMyScreenSize[i][MM_KEY_SCREEN_WIDTH]    = ddiScreenSituation[i][1];
    mMyScreenSize[i][MM_KEY_SCREEN_HEIGHT]   = ddiScreenSituation[i][2];
    mMyScreenSize[i][MM_KEY_SCREEN_START_X]  = ddiScreenSituation[i][3];
    mMyScreenSize[i][MM_KEY_SCREEN_START_Y]  = ddiScreenSituation[i][4];
  }
  return mMyScreenSize;
}

Assignment

Miscellaneous functions

Availability

UI