|
The following is a piece of code in MSDN. I have put them into VC and can run, but why are there several places to use it like this?
void CBrushView :: OnDraw (CDC * pDC)
{
CBrushDoc * pDoc = GetDocument ();
ASSERT_VALID (pDoc);
// CBrush :: CBrush.
CBrush brush1; // Must initialize!
brush1.CreateSolidBrush (RGB (0,0,255)); // Blue brush.
CBrush * pTempBrush = NULL;
CBrush OrigBrush;
CRect rc;
GetClientRect (&rc);
ScreenToClient (&rc); // It seems unnecessary here!
pTempBrush = (CBrush *) pDC-> SelectObject (brush1);
// SelectObject () parameter should be a pointer! Why is this possible?
// Save original brush.
OrigBrush.FromHandle ((HBRUSH) pTempBrush);
// Paint upper left corner with blue brush.
pDC-> Rectangle (0, 0, rc.Width () / 2, rc.Height () / 2);
// Reselect original brush into device context.
pDC-> SelectObject (&OrigBrush);
}
After modifying it like this, that is, replacing the OrigBrush with a pointer,
Compilation works, but error reports pop up at runtime! !!
CBrush * OrigBrush;
...
OrigBrush = (CBrush *) pDC-> SelectObject (brush1);
// Paint upper left corner with blue brush.
pDC-> Rectangle (0, 0, rc.Width () / 2, rc.Height () / 2);
// Reselect original brush into device context.
pDC-> SelectObject (OrigBrush);
Everyone enlighten me !!! |
|