标题:关于Attach
只看楼主
axxiao
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-11-20
 问题点数:0 回复次数:0 
关于Attach

代码: 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 ();
}

搜索更多相关主题的帖子: Attach bitmap lpdis 句柄 CDC 
2007-11-21 11:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-187543-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.253882 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved