13 out of 18 rated this helpful - Rate this topic

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

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
GetWindowRect
Conceptual
Windows
Other Resources
RECT

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
chinese msdn
it there chinese msdn?
Magnifier GOTHCA
FYI: On win7, if "desktop magnification" is in effect, screenshots will be scaled yielding pixel-sizes different from the client/window-RECTS returned by the API.
@Down

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).

returns 0's for x,y
as far as I know, this method just return's 0's into the x and y of the rect.  If you want the "real" window coords for x,y then use GetWindowRect (this one just returns the client's part within that window)
Opengl and using GetClientRect

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.