Vc:getwindowrect, GetClientRect, ScreenToClient and ClientToScreen

Source: Internet
Author: User

GetWindowRect is the RECT coordinates of the window in the screen coordinate system (both client and non-client areas), which gives the window size and position relative to the upper-left corner of the screen (0,0).

GetClientRect gets the rect coordinates of the window client area (excluding the non-client area) in the client area coordinate system, can get the size of the window, and cannot get the relative screen position, because this matrix is in the customer area coordinate system (relative to the upper left corner of the window client area).
The RECT structure returned with GetClientRect is left zero, and the lower right side corresponds to the width and height of the client area respectively;

ScreenToClient converts the RECT coordinates in the screen coordinate system to the RECT coordinates under the client area coordinate system.
We getwindowrect the same window first to obtain a rect, and then convert the screentoclient to the customer coordinate system.
Then GetClientRect gets a rect and then converts it to the screen coordinate system with ClientToScreen.
Obviously, the matrix obtained by GetWindowRect is not less than the matrix obtained by GetClientRect. Because the former includes the non-client area, and then the customer area.

After GetWindowRect obtained matrix screentoclient, the size of the matrix is not smaller, left,top is the coordinates of the upper left corner of the window, relative to the upper left corner of the window client area.

After the matrix ClientToScreen obtained by GetClientRect, the size of the matrix is not larger, and the newly obtained matrix is the Rect of the window client area on the screen coordinate system.

---------------------------

Cases:

Gets the position of a control relative to the dialog box:

CRect RT;
GetDlgItem (IDC_CB)->getwindowrect (RT); Get the position in the screen
ScreenToClient (RT); Convert to a location in a dialog box
Rt.left and Rt.top for the position of the control in the dialog box;
GetDlgItem (IDC_CB)->setwindowpos (null,rt.left,rt.top,0,0,swp_nosize);//Set the location (in fact, in the original position, Because Rt.left and Rt.top are the controls in the dialog box, if you want to adjust the position of the control, you can modify the second and third parameters

The upper-left corner of the window coordinates O (left,top) in the lower-right corner coordinates O (rightk,bottom)

width = right-left;

Hight = Bottom-top

Cret WR,CR;

Pframe->getwindowrect (&WR);//pframe is a pointer to a window
Pframe->getclientrect (&CR)

Where the distance form size WR (including customer and non-client areas) >CR (client area only)

CDialog also follow the above rules (CDialog is also a window)

"Original URL": http://bbs.xml.org.cn/blog/more.asp?name=oceanblue&id=44420

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.