void CXTFlatComboBoxTheme::DrawDownArrow(CDC* pDC, const CRect& rcItem, int eState, CXTFlatComboBox* pCombo) { // determine background size. CRect rcArrow(rcItem); DrawArrowBack(pDC, rcArrow, eState, pCombo); CPoint pt; pt.x = (rcArrow.left + rcArrow.right - 4) / 2; pt.y = (rcArrow.top + rcArrow.bottom - 2) / 2; if (eState == xtMouseSelect) pt.Offset(1, 1); COLORREF cr = pCombo->IsWindowEnabled() ? GetXtremeColor(COLOR_WINDOWTEXT) : GetXtremeColor(COLOR_3DSHADOW); pDC->SetPixel(pt.x, pt.y, cr); pDC->SetPixel(pt.x+1, pt.y, cr); pDC->SetPixel(pt.x+2, pt.y, cr); pDC->SetPixel(pt.x+3, pt.y, cr); pDC->SetPixel(pt.x+4, pt.y, cr); pDC->SetPixel(pt.x+1, pt.y+1, cr); pDC->SetPixel(pt.x+2, pt.y+1, cr); pDC->SetPixel(pt.x+3, pt.y+1, cr); pDC->SetPixel(pt.x+2, pt.y+2, cr); }
// 绘制弹出式菜单箭头 void CUIMenu::DrawArrow(HDC hDC, CRect& rect) { if (m_lpArrowImg != NULL && !m_lpArrowImg->IsNull()) { int cxArrow = m_lpArrowImg->GetWidth(); int cyArrow = m_lpArrowImg->GetHeight(); int x = rect.right - 8 - cxArrow; int y = (rect.Height() - cyArrow + 1) / 2; CRect rcArrow(x, y, x + cxArrow, y + cyArrow); m_lpArrowImg->Draw(hDC, 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; }