Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals
CRect Recto;
m_Panel.GetWindowRect(&Recto);
CClientDC dc(this);
CBrush BlueBrush(RGB(0, 128, 192));
CBrush *pOldBrush = dc.SelectObject(&BlueBrush);
ScreenToClient(Recto);
dc.Rectangle(Recto);
dc.SelectObject(pOldBrush);
}
This time, even if the dialog box moves, the GetWindowRect() method returns the same
rectangle.
If the location and/or dimension are given in client coordinates, to convert them to screen
coordinates, call the ScreenToClient() method. It is overloaded as follows:
void ScreenToClient(LPPOINT lpPoint) const;
void ScreenToClient(LPRECT lpRect) const;
This method follows the opposite logic of the ClientToScreen() method.
Practical Learning: Using Client and Screen Coordinates
- The Geometry application should still be opened.
From the Resource View tab open the IDD_CIRCULAR dialog box - On the Controls toolbox, click the Picture control and draw a rectangular shape
on the left side of the dialog box