Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPropertyPage::OnPaint();
}
}
- Test the application:
- Close the application and return to MSVC
14.2.3..The Screen and Client Coordinates..................................................
When calling either the GetClientRect() or the GetWindowRect() methods to get the
location and the dimensions of a control or another object, it is important to know the
origin of the produced rectangle. By default, the rectangle returned by the
GetWindowRect() method called by a control has its origin on the top left corner of the
monitor and not on the top-left corner of the parent window. Consider the following
event. It gets the location and dimensions of a control and stores them in a CRect
variable. Then it paints a rectangle (it is supposed to paint the control) located on, and
equal to the dimensions of, the control:
void CTabDlg::OnBtnInfo()
{
// TODO: Add your control notification handler code here
CRect Recto;
m_Panel.GetWindowRect(&Recto);
CClientDC dc(this);
CBrush BlueBrush(RGB(0, 128, 192));
CBrush *pOldBrush = dc.SelectObject(&BlueBrush);
dc.Rectangle(Recto);