Windows window coordinates

Source: Internet
Author: User

Not just the rectangle with the largest and smallest close button is called a window.
All controls are windows. The child window in the window is a window.


"The composition of the Window"
The outer border. When the window border property is Thin, resizing has a 3-pixel-wide border.
System Area: The upper part of the window, the blue part, with the largest minimum close button.
Client area: Removes the outer border and part of the system area. System area has a unified mechanism for processing, customer area
Is the part of the client programmer that defines the appearance and behavior.


coordinate system
Screen coordinate system: Defines the (0,0) origin of the upper-left corner of the screen
The window is placed on a two-dimensional plane, usually on the visual plane where the computer monitor is located.
The coordinate unit is "pixels". Assuming the display resolution is (800*600), then
The lower-right corner of the screen coordinates (800,600).


Customer area Coordinate system: the 0,0 origin is the upper-left corner of the client area of the window. Right is the x-axis positive direction.
Down is the y-axis positive direction.


"Common Functions"
GetWindowRect
Gets the position information for the window, including the border and system area, in the screen coordinate system.
If the window is a control such as a button, the whole of the control, including the border, is positioned in the screen coordinate system.


GetClientRect
Gets the location information for the window in the customer coordinate system.


CRect RC;
dialog box->getclientrect (&RC); Gets the dialog box customer Area dimension information.
The RC returned is always (0,0,width,height), where width is the client area wide (per pixel)
Height is the client area.


CRect RC;
Control->getclientrect (&RC); Gets the control customer Area dimension information.
The return RC is always (0,0,width,height), where width is the width of the control (per pixel)
The height of the control.


ClientToScreen
Translates the customer area coordinate system into a screen coordinate system.


Description Formula Crect= (left, top, right, bottom)


Example 1:
CRect rect;
Control->getclientrect (&rect); Rect = (0,0,20,10)
CRect rect2 = rect;
Control->clienttoscreen (&RECT2); Rect2 = (a,b,a+20,b+10)
Where A, B is the coordinate of the screen coordinate system for a control point (that point in the upper-left corner).


Example 2:
CRect rect;
dialog box->getclientrect (&rect); Rect = (0,0,20,10)
CRect rect2 = rect;
dialog box->clienttoscreen (&RECT2); Rect2 = (a,b,a+20,b+10)
Where A, B is the coordinate of the screen coordinate system at a point in the dialog box (that point in the upper-left corner).


ScreenToClient
Translates the screen coordinate system into the customer area coordinate system.


Example 3:
CRect rect;
Control->getwindowrect (&rect); Rect = (l,t,r,b)
CRect rect2 = rect;
Control->screentoclient (&RECT2); Rect2 = (0,0,r-l,b-t)


Example 4:
CRect rect;
dialog box->getwindowrect (&rect); Rect = (l,t,r,b)
CRect rect2 = rect;
dialog box->screentoclient (&RECT2); Rect2 =
(-e,-(E+h), (r-l)-E, (B-T)-(E+H))
Where: E represents the window's border width, which is typically 3 pixels.
H represents the height of the title-bar of the system area, typically 26 pixels.
Where does a negative number come from? GetWindowRect is to take the entire window (including system area and border)
So when you transition to the customer area coordinate system, the left side of the dialog box is to the right of the customer area coordinate system origin (negative direction)
So the left coordinate is-3.


(The geometric area of the rectangle does not change, the position value is changed.) Coordinate transformation belongs to rigid body motion transformation)


Example 5:
CRect rect;
Control->getwindowrect (&rect);
CRect rect2 = rect;
dialog box->screentoclient (&RECT2); The parent window of the control is a dialog box


This is useful for calculating the coordinates of a control relative to the parent window's client area coordinate system.

Windows window coordinates

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.