GetClientRect (), GetWindowRect (), getwindowrect

Source: Internet
Author: User

GetClientRect (), GetWindowRect (), getwindowrect

GetClientRect () is the RECT of the customer zone in the coordinate system of the customer zone.

GetWindowRect () is the RECT of the entire window in the screen coordinate system.

 

GetSystemMetrics () is used to obtain the screen resolution size.

Based on different parameters:

Int width = GetSystemMetrics (SM_CXSCREEN );
Int height = GetSystemMetrics (SM_CYSCREEN );

Obtain the screen width and height respectively.

Int width = GetSystemMetrics (SM_CXVIRTUALSCREEN );
Int height = GetSystemMetrics (SM_CXVIRTUALSCREEN );

Obtain the width and height of the virtual screen respectively. For example, if the computer is connected to a dual screen, use this to obtain the sum of the resolutions of the dual screen.

 

Verification process:

Create a window and add the following code

    CRect rc;    GetWindowRect(&rc);    MoveWindow(rc.left, rc.top,rc.Width(), rc.Height());

The window does not change when you click the button. Because GetWindowRect is relative to the screen, MoveWindow moves the window to its original position, that is, the position remains unchanged.

    CRect rc;    GetWindowRect(&rc);    MoveWindow(rc.left-20, rc.top,rc.Width(), rc.Height());

When you click the button, the window moves to the left
GetWindowRect obtains the window size in the screen coordinate system.

 

    CRect rc;    GetClientRect(&rc);    MoveWindow(rc.left, rc.top, rc.Width(), rc.Height());

When you click the button, the window is moved to the upper-left corner of the screen, because GetClientRect obtains the position of the customer zone relative to the customer zone coordinate system, and its left and top are both 0, moveWindow will move the window to the screen origin before the customer zone coordinate conversion is set to the screen coordinate (ClientToScreen. The window becomes smaller because the window is inserted into the RECT of the original customer zone.

 

If you add a ClientToScreen process in the middle, the window will not be moved to the upper-left corner of the screen, but the window will become smaller.

CRect rc; GetClientRect (& rc); int e = rc. left; // 0 int f = rc. top; // 0 int g = rc. width (); // 560 int h = rc. height (); // 50 ClientToScreen (& rc); int x = rc. left; // 360 int y = rc. top; // 296 int z = rc. width (); // 560 int u = rc. height (); // 350 // because the size of the customer area is smaller than the window size, MoveWindow moves the window to the rectangle of the customer area width and customer area length, so the window will become smaller MoveWindow (rc. left, rc. top, rc. width (), rc. height ());

It indicates that ClientToScreen only changes the reference coordinates. The only change is the left and top values of RECT.

 

However, after GetWindowRect and ClientToScreen, it is found that the left and top of the RECT window are added with the left and top of the customer area. As a result, after pressing the button, the window moves down the height of a customer area, shifted the width of a customer area to the right.

CRect rc; GetClientRect (& rc); int e = rc. left; // 0 int f = rc. top; // 0 int g = rc. width (); // 560 int h = rc. height (); // 350 GetWindowRect (& rc); int I = rc. left; // 357 int j = rc. top; // 271 int k = rc. width (); // 566 int m = rc. height (); // 378 ClientToScreen (& rc); int x = rc. left; // 717 = 360 (left position of the client area relative to the screen) + 357 (left position of the window relative to the screen) int y = rc. top; // 567 = 296 (top position of the client area relative to the screen) + 271 (top position of the window relative to the screen) int z = rc. width (); // 566 int u = rc. height (); /// 378 MoveWindow (rc. left, rc. top, rc. width (), rc. height ());

That is, perform the ClientToScreen operation on the RECT of a window. The left of the RECT of the window will be added to the left of the customer area, and the top will be added to the top of the customer area. This is

Why?

Try again and perform the ClientToScreen operation on a RECT that has been referenced by the screen coordinate system. It is found that the left and top of the client area are added to the position of the window.

    CRect rc;    GetClientRect(&rc);    int i = rc.left;    //0    int j = rc.top;     //0    int k = rc.Width(); //560    int m = rc.Height();//350    ClientToScreen(&rc);    int x = rc.left;   //360       int y = rc.top;    //296      int z = rc.Width();//560      int u = rc.Height();//350     ClientToScreen(&rc);    int n = rc.left;    //720 = 2 * 360    int q = rc.top;     //592 = 2 * 296    int w = rc.Width(); //560      int e = rc.Height();//350      MoveWindow(rc.left, rc.top,rc.Width(), rc.Height());

Therefore, before ClientToScreen (RECT), you must determine that the RECT parameter must be a RECT with the customer zone as the reference. If the RECT parameter is a screen-referenced RECT, the problem may occur.

 

Related Article

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.