64,653
社区成员
发帖
与我相关
我的任务
分享
void CButtonH::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC ButtonDC;
ButtonDC.Attach(lpDrawItemStruct->hDC);
ButtonDC.SetBkMode(TRANSPARENT);
CRect rectBtn;
BITMAP bmpinfo;
CBitmap bmp;
CDC MemDC;
MemDC.CreateCompatibleDC(&ButtonDC);
UINT state=lpDrawItemStruct->itemState;
rectBtn=lpDrawItemStruct->rcItem;
CBitmap *pOldBmp;
if(state & ODS_FOCUS)
{
//bmp.LoadBitmap(m_nIDBmpFocus);
bmp.LoadBitmap(m_nIDBmpFocus);
bmp.GetBitmap(&bmpinfo);
pOldBmp=MemDC.SelectObject(&bmp);
ButtonDC.StretchBlt(rectBtn.left,rectBtn.top,rectBtn.right,rectBtn.bottom,&MemDC,
0,0,bmpinfo.bmWidth,bmpinfo.bmHeight,SRCCOPY);
MemDC.SelectObject(pOldBmp);
bmp.DeleteObject();
}
else
{
bmp.LoadBitmap(m_nIDBmpNomal);
bmp.GetBitmap(&bmpinfo);
pOldBmp=MemDC.SelectObject(&bmp);
ButtonDC.StretchBlt(rectBtn.left,rectBtn.top,rectBtn.right,rectBtn.bottom,&MemDC,
0,0,bmpinfo.bmWidth,bmpinfo.bmHeight,SRCCOPY);
MemDC.SelectObject(pOldBmp);
bmp.DeleteObject();
}
ButtonDC.DrawText(m_strText,&rectBtn,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
ButtonDC.Detach();
MemDC.DeleteDC();
}