I try to draw a rectangle on a mfc window using the instructions by: http://msdn.microsoft.com/en-US/library/8w4fzfxf%28v=VS.80%29.aspx . Much though I tried, the Rectangle appears on the border of the window covering the whole of it. What is the problem with the following code int the function OnDraw(CDC* pDC) ? What can be done to draw a Rectangle with particular coordinates in the window?
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
CPoint pt(10, 10);
CSize sz(100, 50);
CRect myRect(pt, sz);
GetClientRect(&myRect);
pDC->Rectangle(&myRect);
Drop the call to
GetClientRect.That function will write to the rectangle object passed to it, so by calling, you’re overwriting your specific coordinates that you set up just before the call using
ptandsz.