|
以下是MSDN中的一段代码,我已经把它们靠到VC中,可以运行,但有几个地方为什么这样用呢?
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); // 这里似乎没有必要吧!
pTempBrush = (CBrush*)pDC->SelectObject(brush1);
//SelectObject()参数应该是一个指针吧!为什么这样也可以呢?
// 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);
}
修改成这样后,也就是把 OrigBrush 换成了指针,
编译可以通过,但运行时会弹出错误报告!!
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);
大家赐教了!!!
|
|