//测量位置 VOID CUIMenu::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { //效验参数 ASSERT(lpMeasureItemStruct->CtlType==ODT_MENU); if (lpMeasureItemStruct->CtlType!=ODT_MENU) return; //获取数据 CEasySkinMenuItem * pEasySkinMenuItem=(CEasySkinMenuItem *)lpMeasureItemStruct->itemData; if (pEasySkinMenuItem==NULL) { //获取信息 MENUITEMINFO MenuItemInfo; MenuItemInfo.cbSize=sizeof(MenuItemInfo); MenuItemInfo.fMask=MIIM_FTYPE|MIIM_STRING; GetMenuItemInfo(lpMeasureItemStruct->itemID,&MenuItemInfo); return; } //界面菜单 switch (pEasySkinMenuItem->m_MenuItemType) { case MenuItemType_String: //字符菜单 { //变量定义 CEasySkinMenuString * pEasySkinMenuString=(CEasySkinMenuString *)pEasySkinMenuItem; //设置 DC HDC hDC=GetDC(NULL); SelectObject(hDC,GetCtrlFont()); //计算长度 CSize SizeString; GetTextExtentPoint32(hDC,pEasySkinMenuString->m_strString,pEasySkinMenuString->m_strString.GetLength(),&SizeString); //计算位置 lpMeasureItemStruct->itemHeight=MENU_ITEM_CY; lpMeasureItemStruct->itemWidth=SizeString.cx+MENU_BAR_CX+SPACE_LEFT+SPACE_RIGHT; //释放资源 ReleaseDC(NULL,hDC); break; } case MenuItemType_Separator: //拆分菜单 { lpMeasureItemStruct->itemWidth=0; lpMeasureItemStruct->itemHeight=SEPARATOR_CY; break; } } return; }
void CMyButtonEx::DrawCheckButton(CDC* pDC,RECT &rcClient) { int nWidth = 15, nHeight = 15; if (m_pCheckImgN != NULL && !m_pCheckImgN->IsNull()) { nWidth = m_pCheckImgN->GetWidth(); nHeight = m_pCheckImgN->GetHeight(); } CRect rcCheck, rcText; rcCheck.left = rcClient.left; rcCheck.right = rcClient.left + nWidth; rcCheck.top = (rcClient.bottom - rcClient.top - nHeight) / 2 ; rcCheck.bottom = rcCheck.top + nHeight; rcText = rcClient; rcText.left = rcCheck.right + 5; BOOL bCheck = ((GetCheck() == BST_CHECKED) ? TRUE : FALSE); if (m_bHover) { if (bCheck) { if (m_pCheckImgTichH != NULL && !m_pCheckImgTichH->IsNull()) m_pCheckImgTichH->DrawImage(pDC, rcCheck); } else { if (m_pCheckImgH != NULL && !m_pCheckImgH->IsNull()) m_pCheckImgH->DrawImage(pDC, rcCheck); } } else { if (bCheck) { if (m_pCheckImgTickN != NULL && !m_pCheckImgTickN->IsNull()) m_pCheckImgTickN->DrawImage(pDC, rcCheck); } else { if (m_pCheckImgN != NULL && !m_pCheckImgN->IsNull()) m_pCheckImgN->DrawImage(pDC, rcCheck); } } CString strText; GetWindowText(strText); if (strText.GetLength() > 0) { UINT nFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS; int Mode = pDC->SetBkMode(TRANSPARENT); // CFont* pFont = GetFont(); CFont* pFont = CFont::FromHandle(GetCtrlFont()); CFont* pOldFont = pDC->SelectObject(pFont); pDC->SetTextColor(RGB(255, 0, 0)); pDC->DrawText(strText, rcText, nFormat); pDC->SelectObject(pOldFont); pDC->SetBkMode(Mode); } }
void CSkinComboBox_ListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //变量定义 CRect rcItem=lpDrawItemStruct->rcItem; CDC * pDCControl=CDC::FromHandle(lpDrawItemStruct->hDC); //创建缓冲 CDC BufferDC; CBitmap ImageBuffer; BufferDC.CreateCompatibleDC(pDCControl); ImageBuffer.CreateCompatibleBitmap(pDCControl,rcItem.Width(),rcItem.Height()); //设置环境 BufferDC.SelectObject(&ImageBuffer); BufferDC.SelectObject(GetCtrlFont()); //获取字符 CString strString; GetText(lpDrawItemStruct->itemID,strString); //计算位置 CRect rcString; rcString.SetRect(4,0,rcItem.Width()-8,rcItem.Height()); //颜色定义 COLORREF crTextColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?m_colSelectText:m_colNormalText; COLORREF crBackColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?RGB(10,36,106):RGB(255,255,255); //绘画背景 BufferDC.FillSolidRect(0,0,rcItem.Width(),rcItem.Height(),crBackColor); if ( (lpDrawItemStruct->itemState&ODS_SELECTED) != 0 ) { if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() ) { rcItem.DeflateRect(1,1,1,1); m_pSelectImg->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height())); } } //绘画字符 BufferDC.SetBkMode(TRANSPARENT); BufferDC.SetTextColor(crTextColor); BufferDC.DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE); //绘画界面 pDCControl->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,0,0,SRCCOPY); //清理资源 BufferDC.DeleteDC(); ImageBuffer.DeleteObject(); }
//重画函数 VOID CEasySkinHeaderCtrl::OnPaint() { CPaintDC dc(this); //获取位置 CRect rcRect; GetClientRect(&rcRect); CMemoryDC BufferDC(&dc,rcRect); //设置 DC BufferDC.SetBkMode(TRANSPARENT); BufferDC.SetTextColor(m_colNormalText); BufferDC.SelectObject(GetCtrlFont()); //绘画背景 if (m_pBackImg != NULL && !m_pBackImg->IsNull()) m_pBackImg->Draw(&BufferDC,rcRect); if (m_pPressImg != NULL && !m_pPressImg->IsNull() && m_bPress) { CRect rcItem; GetItemRect(m_uActiveItem,&rcItem); m_pPressImg->Draw(&BufferDC,rcItem); } //绘画子项 CRect rcItem; HDITEM HDItem; TCHAR szBuffer[64]; for (INT i=0;i<GetItemCount();i++) { //构造变量 HDItem.mask=HDI_TEXT; HDItem.pszText=szBuffer; HDItem.cchTextMax=CountArray(szBuffer); //获取信息 GetItem(i,&HDItem); GetItemRect(i,&rcItem); if (m_pGridImg != NULL && !m_pGridImg->IsNull()) m_pGridImg->DrawImage(&BufferDC,(rcItem.right-m_pGridImg->GetWidth()),(rcItem.Height()-m_pGridImg->GetHeight())/2); //绘画标题 rcItem.DeflateRect(3,1,3,1); BufferDC.DrawText(szBuffer,lstrlen(szBuffer),&rcItem,DT_END_ELLIPSIS|DT_SINGLELINE|DT_VCENTER|DT_CENTER); } return; }
//绘画函数 VOID CEasySkinListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //变量定义 CRect rcItem=lpDrawItemStruct->rcItem; CDC * pDC=CDC::FromHandle(lpDrawItemStruct->hDC); CMemoryDC BufferDC(pDC,rcItem); //获取属性 INT nItemID=lpDrawItemStruct->itemID; INT nColumnCount=m_EasySkinHeaderCtrl.GetItemCount(); //绘画区域 CRect rcClipBox; BufferDC.GetClipBox(&rcClipBox); //设置环境 BufferDC.SetBkMode(TRANSPARENT); BufferDC.SetTextColor(m_colNormalText); BufferDC.SelectObject(GetCtrlFont()); BufferDC->FillSolidRect(&rcItem,m_colBack); //绘画焦点 if (lpDrawItemStruct->itemState&ODS_SELECTED) { if (m_pSelectImg != NULL && !m_pSelectImg->IsNull()) m_pSelectImg->Draw(&BufferDC,rcItem); } else if ( m_uActiveItem == nItemID ) { if (m_pHovenImg != NULL && !m_pHovenImg->IsNull()) m_pHovenImg->Draw(&BufferDC,rcItem); } //绘画子项 for (INT i=0;i<nColumnCount;i++) { //获取位置 CRect rcSubItem; GetSubItemRect(nItemID,i,LVIR_BOUNDS,rcSubItem); //绘画判断 if (rcSubItem.left>rcClipBox.right) break; if (rcSubItem.right<rcClipBox.left) continue; //绘画数据 DrawReportItem(&BufferDC,nItemID,rcSubItem,i); } return; }
VOID CEasySkinTreeCtrl::DrawItemString( CDC * pDC, CRect rcRect, HTREEITEM hTreeItem, bool bSelected ) { //设置环境 pDC->SelectObject(GetCtrlFont()); pDC->SetBkMode(TRANSPARENT); if( !IsWindowEnabled() ) pDC->SetTextColor(m_colDisableText); else pDC->SetTextColor(bSelected?m_colSelectText:m_colNormalText); //绘画字体 rcRect.right += 5; CString strString=GetItemText(hTreeItem); pDC->DrawText(strString,rcRect,DT_LEFT|DT_VCENTER|DT_SINGLELINE); return; }
void CSkinTabCtrl::DrawItem(CDC*pDC, int nIndex) { CSkinTabCtrlItem * lpItem = GetItemByIndex(nIndex); if (NULL == lpItem) return; CRect rcItem; GetItemRectByIndex(nIndex, rcItem); if (m_nSelIndex == nIndex) { if (lpItem->m_lpBgImgD != NULL && !lpItem->m_lpBgImgD->IsNull()) lpItem->m_lpBgImgD->Draw(pDC, rcItem); else if (m_lpItemBgImgD != NULL && !m_lpItemBgImgD->IsNull()) m_lpItemBgImgD->Draw(pDC, rcItem); } else if (m_nHoverIndex == nIndex) { if (lpItem->m_lpBgImgH != NULL && !lpItem->m_lpBgImgH->IsNull()) lpItem->m_lpBgImgH->Draw(pDC, rcItem); else if (m_lpItemBgImgH != NULL && !m_lpItemBgImgH->IsNull()) m_lpItemBgImgH->Draw(pDC, rcItem); } else { if (lpItem->m_lpBgImgN != NULL && !lpItem->m_lpBgImgN->IsNull()) lpItem->m_lpBgImgN->Draw(pDC, rcItem); else if (m_lpItemBgImgN != NULL && !m_lpItemBgImgN->IsNull()) m_lpItemBgImgN->Draw(pDC, rcItem); } CImageEx * lpIconImg = NULL; if (m_nSelIndex == nIndex) lpIconImg = lpItem->m_lpSelIconImg; else lpIconImg = lpItem->m_lpIconImg; BOOL bHasText = FALSE; if (lpItem->m_strText.GetLength() > 0) bHasText = TRUE; BOOL bHasIcon = FALSE; if (lpIconImg != NULL && !lpIconImg->IsNull()) bHasIcon = TRUE; if (bHasIcon && bHasText) // 带图标和文字 { int cxIcon = lpIconImg->GetWidth(); int cyIcon = lpIconImg->GetHeight(); int nMode = pDC->SetBkMode(TRANSPARENT); pDC->SelectObject(GetCtrlFont()); pDC->SetTextColor(m_colNormalText); CRect rcText(0,0,0,0); // 计算文字宽高 pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, DT_SINGLELINE | DT_CALCRECT); int cx = cxIcon+1+rcText.Width(); int cy = cyIcon; CRect rcCenter; CalcCenterRect(rcItem, cx, cy, rcCenter); CRect rcIcon(rcCenter.left, rcCenter.top, rcCenter.left+cxIcon, rcCenter.bottom); lpIconImg->Draw(pDC, rcIcon); UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; rcText = CRect(rcIcon.right+1, rcItem.top, rcIcon.right+1+rcText.Width(), rcItem.bottom); pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, nFormat); pDC->SetBkMode(nMode); } else if (bHasIcon) // 仅图标 { int cxIcon = lpIconImg->GetWidth(); int cyIcon = lpIconImg->GetHeight(); CRect rcIcon; CalcCenterRect(rcItem, cxIcon, cyIcon, rcIcon); lpIconImg->Draw(pDC, rcIcon); } else if (bHasText) // 仅文字 { UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; int nMode = pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(m_colNormalText); pDC->SelectObject(GetCtrlFont()); pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcItem, nFormat); pDC->SetBkMode(nMode); } if (m_nSelIndex == nIndex) { if (lpItem->m_dwStyle & STCI_STYLE_DROPDOWN) { CRect rcArrow; rcArrow.left = rcItem.left+lpItem->m_nLeftWidth; rcArrow.top = rcItem.top; rcArrow.bottom = rcItem.bottom; rcArrow.right = rcArrow.left + lpItem->m_nRightWidth; if (m_bPressArrow) { if (lpItem->m_lpArrowImgD != NULL && !lpItem->m_lpArrowImgD->IsNull()) lpItem->m_lpArrowImgD->Draw(pDC, rcArrow); else if (m_lpArrowImgD != NULL && !m_lpArrowImgD->IsNull()) m_lpArrowImgD->Draw(pDC, rcArrow); } else if (m_nHoverIndex == nIndex) { if (lpItem->m_lpArrowImgH != NULL && !lpItem->m_lpArrowImgH->IsNull()) lpItem->m_lpArrowImgH->Draw(pDC, rcArrow); else if (m_lpArrowImgH != NULL && !m_lpArrowImgH->IsNull()) m_lpArrowImgH->Draw(pDC, rcArrow); } } } }
//绘画函数 VOID CUIMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //效验参数 ASSERT(lpDrawItemStruct->CtlType==ODT_MENU); if (lpDrawItemStruct->CtlType!=ODT_MENU) return; //变量定义 CRect rcItem=lpDrawItemStruct->rcItem; CDC * pDC=CDC::FromHandle(lpDrawItemStruct->hDC); CEasySkinMenuItem * pEasySkinMenuItem=(CEasySkinMenuItem *)lpDrawItemStruct->itemData; CMemoryDC BufferDC(pDC,rcItem); //状态变量 bool bChecked=((lpDrawItemStruct->itemState&ODS_CHECKED)!=0); bool bSelected=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0); bool bGrayed=((lpDrawItemStruct->itemState&ODS_DISABLED)||(lpDrawItemStruct->itemState&ODS_GRAYED)); //绘画背景 COLORREF crMenuBar=RGB(255,255,255); COLORREF crBorder=RGB(213,233,242); COLORREF crNormalBack=RGB(255,255,255); //菜单左边 if ( m_pMenuBar != NULL && m_pMenuBar->IsNull() == false ) m_pMenuBar->Draw(&BufferDC,CRect(rcItem.left,rcItem.top,MENU_BAR_CX,rcItem.bottom)); else BufferDC.FillSolidRect(rcItem.left,rcItem.top,MENU_BAR_CX,rcItem.Height(),crMenuBar); //菜单节点的背景 if ( m_pMenuBack != NULL && m_pMenuBack->IsNull() == false ) m_pMenuBack->Draw(&BufferDC,CRect(rcItem.left+MENU_BAR_CX,rcItem.top,rcItem.Width(),rcItem.bottom)); else BufferDC.FillSolidRect(rcItem.left+MENU_BAR_CX,rcItem.top,rcItem.Width()-MENU_BAR_CX,rcItem.Height(),crNormalBack); //焦点边框 if ((bSelected==true)&&(bGrayed==false)&&(pEasySkinMenuItem!=NULL)&&(pEasySkinMenuItem->m_MenuItemType!=MenuItemType_Separator)) { if ( m_pMenuHoven != NULL && m_pMenuHoven->IsNull() == false ) { CRect rcSelItem(rcItem); rcSelItem.left += 1; rcSelItem.top += 1; rcSelItem.bottom -= 1; m_pMenuHoven->Draw(&BufferDC,CRect(rcSelItem.left+1,rcSelItem.top+1,rcSelItem.Width()-1,rcSelItem.top+rcSelItem.Height()-1)); } else BufferDC.FillSolidRect(rcItem.left+2,rcItem.top+2,rcItem.Width()-4,rcItem.Height()-4,crBorder); } //绘制箭头 if ( pEasySkinMenuItem->m_hSubMenu != NULL ) { if ( m_pArrow != NULL && m_pArrow->IsNull() == false ) { CRect rcArrow(rcItem.right-5-m_pArrow->GetWidth(),rcItem.top+(rcItem.Height()-m_pArrow->GetHeight())/2,rcItem.right-5,rcItem.top+(rcItem.Height()+m_pArrow->GetHeight())/2); m_pArrow->DrawImage(&BufferDC,rcArrow.left,rcArrow.top); } } //选择标志 if (bChecked) { if ( m_pCheck != NULL && m_pCheck->IsNull() == false ) { CRect rcIcon(rcItem.left,rcItem.top,MENU_BAR_CX,rcItem.bottom); m_pCheck->DrawImage(&BufferDC,(rcIcon.Width()-m_pCheck->GetWidth())/2,rcIcon.top+(rcIcon.Height()-m_pCheck->GetHeight())/2); } } //其他菜单 if (pEasySkinMenuItem==NULL) { //获取信息 MENUITEMINFO MenuItemInfo; MenuItemInfo.cbSize=sizeof(MenuItemInfo); MenuItemInfo.fMask=MIIM_FTYPE|MIIM_BITMAP; GetMenuItemInfo(lpDrawItemStruct->itemID,&MenuItemInfo); return; } //界面菜单 switch (pEasySkinMenuItem->m_MenuItemType) { case MenuItemType_String: //字符菜单 { //变量定义 CEasySkinMenuString * pEasySkinMenuString=(CEasySkinMenuString *)pEasySkinMenuItem; CRect rcIcon(rcItem.left,rcItem.top,MENU_BAR_CX,rcItem.bottom); if ( bSelected ) { if ( pEasySkinMenuString->m_pImageH != NULL && pEasySkinMenuString->m_pImageH->IsNull() == false ) pEasySkinMenuString->m_pImageH->DrawImage(&BufferDC,(rcIcon.Width()-pEasySkinMenuString->m_pImageH->GetWidth())/2,rcIcon.top+(rcIcon.Height()-pEasySkinMenuString->m_pImageH->GetHeight())/2); else if ( pEasySkinMenuString->m_pImageN != NULL && pEasySkinMenuString->m_pImageN->IsNull() == false ) pEasySkinMenuString->m_pImageN->DrawImage(&BufferDC,(rcIcon.Width()-pEasySkinMenuString->m_pImageN->GetWidth())/2,rcIcon.top+(rcIcon.Height()-pEasySkinMenuString->m_pImageN->GetHeight())/2); } else { if ( pEasySkinMenuString->m_pImageN != NULL && pEasySkinMenuString->m_pImageN->IsNull() == false ) pEasySkinMenuString->m_pImageN->DrawImage(&BufferDC,(rcIcon.Width()-pEasySkinMenuString->m_pImageN->GetWidth())/2,rcIcon.top+(rcIcon.Height()-pEasySkinMenuString->m_pImageN->GetHeight())/2); } //设置颜色 BufferDC.SetBkMode(TRANSPARENT); BufferDC.SelectObject(GetCtrlFont()); //设置颜色 if (bGrayed==true) BufferDC.SetTextColor(m_colDisableText); else if (bSelected==true) BufferDC.SetTextColor(m_colSelectText); else BufferDC.SetTextColor(m_colNormalText); //绘画字符 CRect rcString; rcString.top=rcItem.top; rcString.bottom=rcItem.bottom; rcString.right=rcItem.right-SPACE_RIGHT; rcString.left=rcItem.left+MENU_BAR_CX+SPACE_LEFT; BufferDC.DrawText(pEasySkinMenuString->m_strString,pEasySkinMenuString->m_strString.GetLength(),&rcString,DT_SINGLELINE|DT_VCENTER|DT_NOCLIP); break; } case MenuItemType_Separator: //拆分菜单 { //绘画拆分 if ( m_pSeparator != NULL && m_pSeparator->IsNull() == false ) m_pSeparator->Draw(&BufferDC,CRect(rcItem.left+MENU_BAR_CX+SPACE_LEFT,rcItem.top+1,rcItem.right-SPACE_RIGHT,rcItem.Height()-2)); else BufferDC.FillSolidRect(rcItem.left+MENU_BAR_CX+SPACE_LEFT,rcItem.top+1,rcItem.Width()-MENU_BAR_CX-SPACE_LEFT-SPACE_RIGHT,rcItem.Height()-2,m_crSeparator); //补齐分隔条处的边框颜色 UIRenderEngine->DrawLine(BufferDC.GetSafeHdc(),CRect(rcItem.left,rcItem.top,rcItem.left+1,rcItem.top+rcItem.Height()+1),1,m_colFrameNormal); UIRenderEngine->DrawLine(BufferDC.GetSafeHdc(),CRect(rcItem.right-1,rcItem.top,rcItem.right,rcItem.top+rcItem.Height()+1),1,m_colFrameNormal); break; } } //绘制边框色 int nSeparatorCount = GetSeparatorCount(); CRect rcClient(0,0,rcItem.right,0); rcClient.bottom = rcItem.Height()*(GetMenuItemCount()-nSeparatorCount)+SEPARATOR_CY*nSeparatorCount; UIRenderEngine->DrawRect(BufferDC.GetSafeHdc(),rcClient,1,m_colFrameNormal); //绘画界面 pDC->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,rcItem.left,rcItem.top,SRCCOPY); //抠掉子节点区域,从而屏蔽系统绘制的倒三角 if ( (pEasySkinMenuItem->m_hSubMenu != NULL) && (m_pArrow != NULL && m_pArrow->IsNull() == false)) pDC->ExcludeClipRect(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom); return; }
void CSkinListBox::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClient; GetClientRect(&rcClient); CMemoryDC BufferDC(&dc,rcClient); //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32); //变量定义 CDC * pBufferDC=CDC::FromHandle(ImageBuffer.GetDC()); //变量定义 CRect rcItem; pBufferDC->SelectObject(GetCtrlFont()); //绘画背景 pBufferDC->FillSolidRect(0,0,rcClient.Width(),rcClient.Height(),m_colBack); DrawParentWndBg(GetSafeHwnd(),pBufferDC->GetSafeHdc()); if (m_pBackImgN != NULL && !m_pBackImgN->IsNull()) m_pBackImgN->Draw(pBufferDC, rcClient); for (int i=0;i<GetCount();i++) { GetItemRect(i,&rcItem); //获取字符 CString strString; GetText(i,strString); //计算位置 CRect rcString; rcString.SetRect(rcItem.left+4,rcItem.top,rcItem.right-8,rcItem.bottom); bool bSelect = GetSel(i); //颜色定义 COLORREF crTextColor=bSelect?m_colSelectText:m_colNormalText; //节点选中 if ( bSelect ) { if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() ) { m_pSelectImg->Draw(pBufferDC,CRect(rcItem.left,rcItem.top,rcItem.right,rcItem.bottom)); } } //节点高亮 else if ( m_nHovenItem == i ) { if ( m_pBackImgH!= NULL && !m_pBackImgH->IsNull() ) { m_pBackImgH->Draw(pBufferDC,CRect(rcItem.left,rcItem.top,rcItem.right,rcItem.bottom)); } } //绘画字符 pBufferDC->SetBkMode(TRANSPARENT); pBufferDC->SetTextColor(crTextColor); pBufferDC->DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE); } //绘画界面 BufferDC.BitBlt(0,0,rcClient.Width(),rcClient.Height(),pBufferDC,0,0,SRCCOPY); //清理资源 ImageBuffer.ReleaseDC(); }
void CSkinListBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) { return; //没有节点就不用继续执行了 if( GetCount()==0 ) return; //变量定义 CRect rcItem=lpDrawItemStruct->rcItem; CDC * pDCControl=CDC::FromHandle(lpDrawItemStruct->hDC); //创建缓冲 CDC BufferDC; CBitmap ImageBuffer; BufferDC.CreateCompatibleDC(pDCControl); ImageBuffer.CreateCompatibleBitmap(pDCControl,rcItem.Width(),rcItem.Height()); //设置环境 BufferDC.SelectObject(&ImageBuffer); BufferDC.SelectObject(GetCtrlFont()); //获取字符 CString strString; GetText(lpDrawItemStruct->itemID,strString); //计算位置 CRect rcString; rcString.SetRect(4,0,rcItem.Width()-8,rcItem.Height()); //颜色定义 COLORREF crTextColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?m_colSelectText:m_colNormalText; //绘画背景 BufferDC.FillSolidRect(0,0,rcItem.Width(),rcItem.Height(),m_colBack); //节点选中 if ( (lpDrawItemStruct->itemState&ODS_SELECTED) != 0 ) { if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() ) { m_pSelectImg->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height())); } } //节点高亮 else if ( m_nHovenItem == lpDrawItemStruct->itemID ) { if ( m_pBackImgH!= NULL && !m_pBackImgH->IsNull() ) { m_pBackImgH->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height())); } } //绘画字符 BufferDC.SetBkMode(TRANSPARENT); BufferDC.SetTextColor(crTextColor); BufferDC.DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE); //绘画界面 pDCControl->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,0,0,SRCCOPY); //清理资源 BufferDC.DeleteDC(); ImageBuffer.DeleteObject(); }