GetWindowRect

2.x

  void GetWindowRect(hwnd, lprc)    
  HWND hwnd; /* handle of window, */  
  RECT FAR* lprc; /* address of structure for window coordinates */

The GetWindowRect function retrieves the dimensions of the bounding rectangle of a given window. The dimensions are given in screen coordinates, relative to the upper-left corner of the display screen, and include the title bar, border, and scroll bars, if present.

Parameters

hwnd

Identifies the window.

lprc

Points to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window. The RECT structure has the following form:

typedef struct tagRECT {    /* rc */
   int left;
   int top;
   int right;
   int bottom;
} RECT;

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

This function does not return a value.

Example

The following example calls the GetWindowRect function to retrieve the dimensions of the desktop window, and uses the dimensions to create a window that fills the right third of the desktop window:

RECT rc;
WORD wWidth;

GetWindowRect(GetDesktopWindow(), &rc);

/* Set the width to be 1/3 of the desktop window's width. */

wWidth = (rc.right - rc.left) / 3;


/* Create a main window for this application instance. */

hwndFrame = CreateWindow("MyClass", "My Title", WS_OVERLAPPEDWINDOW,
    rc.right - wWidth,      /* horizontal position */
    0,                      /* vertical position   */
    wWidth,                 /* width               */
    rc.bottom,              /* height              */
    (HWND) NULL, (HMENU) NULL, hinst, (LPSTR) NULL);

See Also

GetClientRect, MoveWindow, SetWindowPos