The difference between GetWindowRect and GetClientRect [turn]

Source: Internet
Author: User

GetWindowRect
function function: This function returns the dimensions of the bounding rectangle of the specified window. The dimension is given in screen coordinates relative to the upper-left corner of the screen coordinates.
Function prototype: BOOL GetWindowRect (HWND hwnd,lprectlprect);
In Visual Studio 2005, the function prototype is void GetWindowRect (LPRECT LPRECT) const;
is a function that belongs to the CWnd class.
Parameters:
HWnd: Window handle.
LpRect: A pointer to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
Return value: If the function succeeds, the return value is not 0: If the function fails, the return value is zero. To get more error information, call the GetLastError function.
Quick check: Windows nt:3.1 above version: Windows:95 or above, Windows ce:1.0 or above; header file: Winuser.h; library file: User32.lib.

Call GetWindowRect before calling ScreenToClient, this time the resulting rect and the direct use of GetClientRect get the value is equal.

Sometimes you need to get the value of both the size of the window rectangle and the size of the client area rectangle, so you need to call GetWindowRect and GetClientRect separately.

If you only need to get the size of the client area rectangle, call GetClientRect.

The GetWindowRect and GetClientRect functions are described as follows:

cwnd::getclientrect  
    void GetClientRect (LPRECT LPRECT) const;
Parameters:
LpRect
    Points to a RECT structure or a CRect object to receive the client coordinates . The left and top members would be 0. The right and bottom members would contain the width and height of the window.
Remarks:
    Copies The client coordinates of the CWND client area into the structure pointed to by LpRect. The client coordinates specify the Upper-left and Lower-right corners of the client area. Since client coordinates is relative to the upper-left corners of the CWnd client area, the coordinates of the Upper-left Corner is (0,0).

Cwnd::getwindowrect
void GetWindowRect (LPRECT LPRECT) const;
Parameters:
LpRect
Points to a CRect object or a RECT structure that would receive the screen coordinates of the Upper-left and Lower-right Co Rners.
Remarks:
Copies the dimensions of the bounding rectangle of the CWnd object to the structure pointed to by LpRect. The dimensions is given in screens coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.

GetWindowRect () is a rect in the screen coordinate system (i.e., the origin point in the upper left corner of the screen)
GetClientRect () is a rect in the client area coordinate system (i.e. the origin in the upper left corner of the window)

GetWindowRect () takes a rectangle of the entire window;
GetClientRect () is only the client area of the rectangle, that is, not including the title bar, bounding box, etc.;

The first function obtains the position of the window on the screen, and the resulting result may be such crect (10,10,240,240);
The second function differs from it in that it only obtains the size of the client area, so the result is always such crect (0,0,width,height);

ScreenToClient () converts the RECT coordinates in the screen coordinate system to the RECT coordinates of the client area coordinate system.

The GetClientRect function 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 is relative to the Upper-left corner of a window's client area, the coordinates of the upper-l EFT Corner is (0,0).

GetClientRect gets the size of the client area, which means that the upper left corner will always be (0,0)

The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions is given in screens coordinates that is relative to the upper-left corner of the.

GetWindowRect is the coordinates of the window relative to the entire screen, and the upper left point of the screen is 0,0

ScreenToClient or ClientToScreen for mutual conversion

ClientToScreen
The ClientToScreen function converts the client coordinates of a specified point-to-screen coordinate s. 
BOOL clienttoscreen (
   HWND hwnd,       //Window handle for source coordinates
   lppoint lppoint  //Pointer to structure containing screen Coordi Nates
);
Parameters
hwnd 
Handle to the window whose client area was used for the conversion. 
lppoint 
Pointer to a point structure this contains the client coordinates to be converted. The new screen coordinates is copied into this structure if the function succeeds. 
Return Values
If the funct Ion succeeds, the return value is nonzero.
If The function fails, the return value is zero.

Although there is a call to GetWindowRect before calling Screentoclient==getclientrect, ScreenToClient () and ClientToScreen () are both part of the Windows API function. There may be some redundancy in the design, but the meaning is different.
However, the Windows API functions have been re-organized and optimized under the. Net framework, making it easier to get the screen coordinates and client area coordinates of a control or window, and simply to get the values of the screen coordinates and client area coordinates of the corresponding control or window.

ScreenToClient
The ScreenToClient function converts the screen coordinates of a specified point in the screen to client coordinates.
BOOL ScreenToClient (
HWND hwnd,//window handle for source coordinates
Lppoint Lppoint//address of structure containing coordinates
);
Parameters:
HWnd
Handle to the window whose client area is used for the conversion.
Lppoint
Pointer to a point structure that contains the screens coordinates to be converted.
Return Values:
If The function succeeds, the return value is nonzero.
If The function fails, the return value is zero.

This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/dadalan/archive/2010/02/22/5316599.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.