在树型控件中移动鼠标产生字体及颜色的变化
2007-03-22 21:30:39 来源:WEB开发网核心提示: void CDirTreeCtrl::OnPaint() { CPaintDC dc(this); // paint设备环境 CDC memDC; memDC.CreateCompatibleDC(&dc); CRect rcClip,rcClient; dc.GetClipBox(&r
void CDirTreeCtrl::OnPaint()
{
CPaintDC dc(this); // paint设备环境
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CRect rcClip,rcClient;
dc.GetClipBox(&rcClip);
GetClientRect(&rcClient);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
memDC.SelectObject(&bitmap);
CWnd::DefWindowProc(WM_PAINT,(WPARAM)memDC.m_hDC,0);
if(hItem_bc != NULL) {
CRect rect;
UINT selflog=TVIS_DROPHILITED|TVIS_SELECTED;
Color_Font cf;
if(!(GetItemState(hItem_bc,selflog) & selflog) && m_mapColorFont.Lookup(hItem_bc,cf))
{
CFont *pFontDC;
CFont fontDC;
LOGFONT logfont;
logfont=logfont_old;
logfont.lfUnderline=TRUE; //设置字体的下划线属性
fontDC.CreateFontIndirect(&logfont); //创建新字体
pFontDC=memDC.SelectObject(&fontDC); //将新字体选入设备环境
memDC.SetTextColor(cf.color);
CString sItem=GetItemText(hItem_bc);
GetItemRect(hItem_bc,&rect,TRUE);
memDC.TextOut(rect.left+2,rect.top+2,sItem);
memDC.SelectObject(pFontDC);//在设备环境中恢复原字体
fontDC.DeleteObject();
}
}
dc.BitBlt(rcClip.left,rcClip.top,rcClip.Width(),rcClip.Height(),
&memDC,rcClip.left,rcClip.top,SRCCOPY);
bitmap.DeleteObject();
hItem_bc=NULL;
}
更多精彩
赞助商链接