如何在树型控件中使用背景位图,如何在树型控件中使用背景位图
【 tulaoshi.com - C语言心得技巧 】
如何在树型控件中使用背景位图BOOL CMyTreeCtrl::SetBKImage(LPCTSTR LpszResource){if( m_bitmap.m_hObject != NULL )m_bitmap.DeleteObject();HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), LpszResource, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);if( hbmp == NULL ) return FALSE;m_bitmap.Attach( hbmp );return TRUE;}3.2 为WM_PAINT加入消息句柄
void CMyTreeCtrl::OnPaint() {CPaintDC dc(this);CRect rcclient;GetClientRect(&rcclient);CDC memdc;memdc.CreateCompatibleDC(&dc);CBitmap bitmap;bitmap.CreateCompatibleBitmap(&dc, rcclient.Width(), rcclient.Height());memdc.SelectObject( &bitmap );CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0);CDC maskdc;maskdc.CreateCompatibleDC(&dc);CBitmap maskbitmap;maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1, 1, NULL);maskdc.SelectObject( &maskbitmap );maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top, SRCCOPY);CBrush brush;brush.CreatePatternBrush(&m_bitmap);dc.FillRect(rcclient, &brush);memdc.SetBkColor(RGB(0,0,0)); memdc.SetTextColor(RGB(255,255,255)); memdc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &maskdc, rcclient.left, rcclient.top, SRCAND);dc.SetBkColor(RGB(255,255,255));dc.SetTextColor(RGB(0,0,0));dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &maskdc, rcclient.left, rcclient.top, SRCAND);dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(), &memdc, rcclient.left, rcclient.top,SRCPAINT);brush.DeleteObject();}3.3 处理tvn_itemexpanding
void CMyTreeCtrl::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) {NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;SetRedraw(FALSE);*pResult = 0;}3.4 处理tvn_itemexpanded
void CMyTreeCtrl::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult) {NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;Invalidate();SetRedraw(TRUE);*pResult = 0;}3.5 加入WM_ERASEBKGND消息处理函数
BOOL CMyTreeCtrl::OnEraseBkgnd(CDC* pDC) {return TRUE;}(完)
来源:http://www.tulaoshi.com/n/20160129/1484363.html
看过《如何在树型控件中使用背景位图》的人还看了以下文章 更多>>