Welcome: Hunan Intelligent Applications Tecgnology CO.,ltd.-HNIAT.com
Language: Chinese ∷  English

Basic knowledge

MFC drawing coordinate system learning

1. Coordinate system and its definition
There are mainly three coordinate systems: window coordinate system, client area coordinate system, and screen coordinate system.

Window coordinate system: Use the upper left corner of the dialog window as the origin of the coordinates, including the window's title bar, menu bar, toolbar, etc.
Client area coordinate system: The client area coordinates must have a client object, with the upper left corner of the client object as the coordinate origin.
The client object can be the client area of a dialog window or the area of a control.
Screen coordinate system: The upper left corner of the computer screen is the origin of coordinates, which is an absolute coordinate.

2. Coordinate transformation of different coordinate systems

The coordinate system can be converted to each other. Such as: CPoint point;
2-1 Screen coordinate system is transformed into client area coordinate system
This-> ScreenToClient (& point); (converts the point point under the screen coordinate system to the point under this client area coordinate system)

MPicViemStatic.ScreenToClient (& point) (converts a point point in the screen coordinate system to a point in the mPicViemStatic client area coordinate system)

2-2 Client Area Coordinates to Screen Coordinate System
This-> ClientToScreen (& point) (converts the point point in the client area coordinate system to a point in the screen coordinate system)

MPicViemStatic.ClientToScreen (& point) (Converts the point point in the mPicViemStatic client area coordinate system to a point in the screen coordinate system)

2-3 Coordinate Transformation of Different Client Areas
Intermediate transformations need to be performed through screen coordinates:

This-> ClientToScreen (& point); (first convert the point point in the client area coordinate system to Diang in the screen coordinate system),

MPicViemStatic.ScreenToClient (& point); (Then point point in the screen coordinate system is converted to point in the mPicViemStatic client area coordinate system)

The final point obtained is the coordinate system point of the mPicViemStatic client area.

Zh
3. Common ways to obtain screen coordinates:
BOOL GetCursorPos (__ out LPPOINT lpPoint); // Get the current mouse screen coordinates
BOOL GetWindowRect (LPRECT lpRect) const throw (); // If it is used on the dialog class, the upper left point of lpRect is the top of the window, including the window's title bar, menu bar, and toolbar
MPicViemStatic.GetWindowRect (LPRECT lpRect); // Get the screen coordinates of the control mPicViemStatic rectangle
Zh
4. Common methods for obtaining the coordinates of the client area:
BOOL GetClientRect (__ out LPRECT lpRect); // Get the current client area rectangle
CPoint point in the mouse event response function is the client area coordinates, such as:
OnMouseMove (UINT nFlags, CPoint point);
OnLButtonUp (UINT nFlags, CPoint point);
OnLButtonDown (UINT nFlags, CPoint point);
As for the client area, see where the message definition is. If it is a dialog-type message, it is the client area of the dialog window. Zh
Zh
5.When MFC draws, GetDC () must confirm to draw on the DC in that client area
For example, CDC * pDC = mColorPicStatic.GetDC (); indicates that the drawing is drawn according to the mColorPicStatic client area coordinate system.

CDC * pDC = GetDC (); indicates drawing in this client area coordinate system.
————————————————
Copyright statement: This article is the original article of the CSDN blogger "Bai Baijiao Jiao", which follows the CC 4.0 BY-SA copyright agreement. Please reprint the original source link and this statement.
Original link: https://blog.csdn.net/qq_20828983/article/details/52275127

CONTACT US

Contact: Manager Xu

Phone: 13907330718

Tel: 0731-22222718

Email: hniatcom@163.com

Add: Room 603, 6th Floor, Shifting Room, No. 2, Orbit Zhigu, No. 79 Liancheng Road, Shifeng District, Zhuzhou City, Hunan Province

Scan the qr codeClose
the qr code