GetClientRect function
Applies to: desktop apps only
Retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).
Syntax
BOOL WINAPI GetClientRect( __in HWND hWnd, __out LPRECT lpRect );
Parameters
- hWnd [in]
-
Type: HWND
A handle to the window whose client coordinates are to be retrieved.
- lpRect [out]
-
Type: LPRECT
A pointer to a RECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window.
Return value
Type:
Type: BOOL
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.
Examples
For example, see Creating, Enumerating, and Sizing Child Windows.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- GetWindowRect
- Conceptual
- Windows
- Other Resources
- RECT
Send comments about this topic to Microsoft
Build date: 2/3/2012
- 10/21/2011
- Michael Loft
No, it doesn't. It always returns size of whole window except borders and title bar. Because I write in DirectX, I would say that this function return size of the area that I can render to.
For example, when I created a window 750 px width and 500 px height using style WS_BORDER|WS_CAPTION|WS_CLIPCHILDREN, GetClientRect() function gave me a RECT 744 px width and 472 px height. This function could be very useful, unless you create apps that work in fullscreen mode - in this case, you will mostly use WS_POPUP style, when window size is always equal to its client size (because this kind of window doesn't have any borders, nor title bar).
- 8/26/2011
- Draconis
- 8/27/2010
- rogerdpack2
It is not strange to set the opengl viewport to the width and height of a window's client area. Opengl is generally painted upon the main window of an application.
However you might change your mind and try to draw upon a child window. Specifically, one that has WM_CHILD set in dwStyles. This can generate issued as such windows don't seem to be able to return their client area's width and height via the GetClientRect function. If you use these values, the viewport will collapse, and only the clearing color will be visible.
- 8/11/2008
- Xilliah