代码: dc.Attach (lpdis->hDC) MSDN里说是将句柄与对象连接起来,有的地方说就是把句柄转换为对象等的说法,
究竟是什么,还是云里雾里啊?
void CMainFrame::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
BITMAP bm;
CBitmap bitmap;
bitmap.LoadOEMBitmap (OBM_CHECK);
bitmap.GetObject (sizeof (bm), &bm);
CDC dc;
dc.Attach (lpdis->hDC);
CBrush* pBrush = new CBrush (::GetSysColor ((lpdis->itemState &
ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU));
dc.FrameRect (&(lpdis->rcItem), pBrush);
delete pBrush;
if (lpdis->itemState & ODS_CHECKED) {
CDC dcMem;
dcMem.CreateCompatibleDC (&dc);
CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
dc.BitBlt (lpdis->rcItem.left + 4, lpdis->rcItem.top +
(((lpdis->rcItem.bottom - lpdis->rcItem.top) -
bm.bmHeight) / 2), bm.bmWidth, bm.bmHeight, &dcMem,
0, 0, SRCCOPY);
dcMem.SelectObject (pOldBitmap);
}
UINT itemID = lpdis->itemID & 0xFFFF; // Fix for Win95/98 bug
pBrush = new CBrush (m_wndView.m_clrColors[itemID - ID_COLOR_RED]);
CRect rect = lpdis->rcItem;
rect.DeflateRect (6, 4);
rect.left += bm.bmWidth;
dc.FillRect (rect, pBrush);
delete pBrush;
dc.Detach ();
}