Getwindowrect is used to obtain the rect coordinates of the window in the screen coordinate system (including the customer and non-customer areas). In this way, the size of the window and the position relative to the upper left corner (0, 0) of the screen are obtained.
Getclientrect obtains the rect coordinates of the window client (excluding non-customer regions) in the client coordinate system. The size of the window is obtained, but the location of the screen is not obtained, this matrix is located in the client coordinate system (relative to the upper left corner of the window customer area.
The top left of the rect structure returned by getclientrect is zero, and the bottom right is the width and height of the customer area;
Screentoclient converts the rect coordinates in the screen coordinate system to the rect coordinates in the client coordinate system.
We first getwindowrect A rect for the same window, and then use screentoclient to convert it to the customer coordinate system.
Then, getclientrect gets a rect and converts it to the screen Coordinate System Using clienttoscreen.
Obviously, the matrix obtained by getwindowrect is not smaller than that obtained by getclientrect. Because the former includes non-customer areas and then the customer areas.
After screentoclient is obtained for the matrix obtained by getwindowrect, the size of the matrix is not reduced. Left and top are the coordinates in the upper left corner of the window, which are relative to the upper left corner of the window customer area.
After obtaining the clienttoscreen matrix obtained by getclientrect, the size of the matrix does not increase. The new matrix is the rect of the window client area in the screen coordinate system.
---------------------------
Example:
Obtain the position of a widget relative to the dialog box:
Crect RT;
Getdlgitem (idc_cb)-> getwindowrect (RT); // obtain the position on the screen
Screentoclient (RT); // switch to the position in the dialog box
Rt. Left and RT. Top are the positions of the control in the dialog box;
Getdlgitem (idc_cb)-> setwindowpos (null, Rt. left, Rt. top, swp_nosize); // set this location (in fact, it is still in the original location, because RT. left and RT. top is the position of the control in the dialog box. To adjust the position of the control, modify the second and third parameters );