//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CIconComboBox::SetDisabledBrushAndPen( LPDRAWITEMSTRUCT lpDrawItemStruct, CBrush **ppOldBrush, CPen **ppOldPen ) { // get the device context CDC* pDC = CDC::FromHandle( lpDrawItemStruct->hDC ); // set brush and pen to light gray CBrush brushDisabled( RGB( 192, 192, 192 ) ); CPen penDisabled( PS_SOLID, 1, RGB( 192, 192, 192 ) ); // set the brush and pen current -- saving the old brush and pen state *ppOldBrush = pDC->SelectObject( &brushDisabled ); *ppOldPen = pDC->SelectObject( &penDisabled ); }
void CAdvComboBox::OnPaint() { CPaintDC dc(this); // device context for painting if( m_nCurSel != -1 ) { m_iter = m_list.begin(); advance( m_iter, m_nCurSel ); if( m_iter != m_list.end() ) { m_strEdit = m_iter->strText; } if( m_bFirstPaint ) { if( m_pEdit ) { m_pEdit->SetWindowText( m_strEdit.c_str() ); m_bFirstPaint = false; m_pEdit->EnableWindow( IsWindowEnabled() ); } } } CRect rect; CRect rcText; GetClientRect(rect); rcText = rect; rect.left = rect.right - ::GetSystemMetrics(SM_CXHSCROLL); rcText.right = rect.left-1; m_rcDropButton = rect; GetClientRect(rect); BOOL bWndEnabled = IsWindowEnabled(); COLORREF clrDisabledBkg = ::GetSysColor(COLOR_BTNFACE); COLORREF clrDisabledBorder = ::GetSysColor(COLOR_3DDKSHADOW); COLORREF clrDisabledText = ::GetSysColor(COLOR_GRAYTEXT); if( !bWndEnabled ) { if( 1 ) // Draw disabled flat control with border? Change to '0'. { dc.FillSolidRect( rect, clrDisabledBkg ); } else { CBrush brDisabled(clrDisabledBkg); CBrush* pOldBrush = dc.SelectObject(&brDisabled); CPen penDisabled( PS_SOLID, 0, clrDisabledBorder); CPen* pOldPen = dc.SelectObject(&penDisabled); dc.Rectangle(rect); dc.SelectObject(pOldBrush); dc.SelectObject(pOldPen); } } else { COLORREF clrEnabledBkg = ::GetSysColor(COLOR_WINDOW); dc.FillSolidRect( rect, clrEnabledBkg ); } DWORD dwBtnStyle = 0; if( !bWndEnabled ) { dwBtnStyle |= DFCS_INACTIVE; } dwBtnStyle |= m_bDropListVisible ? (DFCS_SCROLLDOWN|DFCS_PUSHED|DFCS_FLAT) : DFCS_SCROLLDOWN; BOOL bThemeActive = FALSE; HRESULT hr; bThemeActive = g_xpStyle.UseVisualStyles(); HTHEME hTheme = NULL; if( bThemeActive ) hTheme = g_xpStyle.OpenThemeData( m_hWnd, L"COMBOBOX" ); // Theme drop btn style int nDropBtnThemeStyle = 0; if( m_bDropListVisible ) { nDropBtnThemeStyle = CBXS_PRESSED; } else { nDropBtnThemeStyle = CBXS_NORMAL; if( m_bDropButtonHot ) nDropBtnThemeStyle = CBXS_HOT; if( !bWndEnabled ) nDropBtnThemeStyle = CBXS_DISABLED; } #if 0 // ----------------------------------------------------------- if( m_dwACBStyle & ACBS_FLAT ) { if( bThemeActive ) { hr = g_xpStyle.DrawThemeBackground( hTheme, dc.m_hDC, CP_DROPDOWNBUTTON, nDropBtnThemeStyle, &m_rcDropButton, NULL); } else { dc.DrawFrameControl(m_rcDropButton, DFC_SCROLL, dwBtnStyle ); } } else if( m_dwACBStyle & ACBS_STANDARD ) #endif // ----------------------------------------------------------- { if( bThemeActive ) { COLORREF clrBorder; hr = g_xpStyle.GetThemeColor( hTheme, BP_PUSHBUTTON, bWndEnabled ? PBS_NORMAL : PBS_DISABLED, TMT_BORDERCOLOR, &clrBorder ); if( FAILED( hr ) ) { clrBorder = RGB(0,0,0); } CPen penBorder( PS_SOLID, 0, clrBorder ); CPen* oldBorderPen = dc.SelectObject( &penBorder ); dc.Rectangle( &rect ); m_rcDropButton.DeflateRect(0,1,0,1); m_rcDropButton.left -= 1; m_rcDropButton.right -= 1; if( !bWndEnabled ) { COLORREF clrDisabledLightBorder; COLORREF clrDisabledFill; hr = g_xpStyle.GetThemeColor( hTheme, BP_PUSHBUTTON, bWndEnabled ? PBS_NORMAL : PBS_DISABLED, TMT_FILLCOLOR, &clrDisabledLightBorder ); if( FAILED( hr ) ) { clrDisabledLightBorder = RGB(255,255,255); } hr = g_xpStyle.GetThemeColor( hTheme, WP_DIALOG, 0, TMT_FILLCOLOR, &clrDisabledFill ); if( FAILED( hr ) ) { clrDisabledFill = RGB(255,0,0); } CPen penDisBorder( PS_SOLID, 0, clrDisabledLightBorder ); CBrush brFill( clrDisabledBkg );//clrDisabledFill ); CRect rcl = rect; rcl.DeflateRect(1,1); rcl.right = m_rcDropButton.left; CBrush *oldBr = dc.SelectObject( &brFill ); dc.SelectObject( &penDisBorder ); dc.Rectangle( &rcl ); dc.SelectObject( oldBr ); } dc.SelectObject( &oldBorderPen ); // Button hr = g_xpStyle.DrawThemeBackground( hTheme, dc.m_hDC, CP_DROPDOWNBUTTON, nDropBtnThemeStyle, &m_rcDropButton, NULL); } else { COLORREF clrTopLeft = ::GetSysColor(COLOR_3DSHADOW); COLORREF clrBottomRight = ::GetSysColor(COLOR_3DHILIGHT); dc.Draw3dRect( &rect, clrTopLeft, clrBottomRight ); clrTopLeft = ::GetSysColor(COLOR_3DDKSHADOW); clrBottomRight = ::GetSysColor(COLOR_3DLIGHT); rect.DeflateRect(1,1); dc.Draw3dRect( &rect, clrTopLeft, clrBottomRight ); m_rcDropButton.DeflateRect(0,2,0,2); m_rcDropButton.left -= 2; m_rcDropButton.right -= 2; // Button dc.DrawFrameControl(m_rcDropButton, DFC_SCROLL, dwBtnStyle ); } // // Adjust rects rcText.DeflateRect(4,3,2,3); } if( bThemeActive ) hr = g_xpStyle.CloseThemeData( hTheme ); if( (GetStyle() & CBS_DROPDOWN) && (GetStyle() & CBS_SIMPLE) ) // == CBS_DROPDOWNLIST { // // Draw Text as selected COLORREF clrBackground; COLORREF clrOldBkColor; COLORREF clrOldTextColor; clrBackground = ::GetSysColor(COLOR_HIGHLIGHT); clrOldBkColor = dc.SetBkColor( clrBackground ); // clrOldTextColor = dc.SetTextColor( ::GetSysColor(COLOR_HIGHLIGHTTEXT) ); int nOldBkMode = dc.SetBkMode( TRANSPARENT ); CFont* pOldFont = dc.SelectObject( m_pFont ); rcText.top -= 2; rcText.bottom += 2; rcText.left -= 2; rcText.right += 1; if( m_bHasFocus && !m_bDropListVisible ) { dc.FillSolidRect( rcText, bWndEnabled ? clrBackground : clrDisabledBkg ); clrOldTextColor = dc.SetTextColor( bWndEnabled ? ::GetSysColor(COLOR_HIGHLIGHTTEXT) : clrDisabledText ); dc.DrawText( m_strEdit.c_str(), &rcText, DT_SINGLELINE|DT_VCENTER); } else { //+++dc.FillSolidRect( rcText, //+++ bWndEnabled ? ::GetSysColor(COLOR_HIGHLIGHTTEXT) : clrDisabledBkg ); dc.FillSolidRect( rcText, bWndEnabled ? ::GetSysColor(COLOR_WINDOW) : clrDisabledBkg ); clrOldTextColor = dc.SetTextColor( bWndEnabled ? ::GetSysColor(COLOR_BTNTEXT) : clrDisabledText ); dc.DrawText( m_strEdit.c_str(), &rcText, DT_SINGLELINE|DT_VCENTER); } dc.SelectObject( pOldFont ); dc.SetBkMode( nOldBkMode ); } else { if( m_pEdit ) { m_pEdit->SetFont( m_pFont ); } } // Do not call CWnd::OnPaint() for painting messages }
void CBeautifulCanlendarYearCombox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); if (!IsWindowEnabled()) { CBrush brDisabled(RGB(192,192,192)); // light gray CBrush* pOldBrush = pDC->SelectObject(&brDisabled); CPen penDisabled(PS_SOLID, 1, RGB(192,192,192)); CPen* pOldPen = pDC->SelectObject(&penDisabled); //以下是绘制文本的部分 CRect textRect = lpDrawItemStruct->rcItem; textRect.left = textRect.left + 6; CString strText; if(lpDrawItemStruct->itemID != LB_ERR) { GetLBText( lpDrawItemStruct->itemID,strText); } pDC->SetTextColor(RGB(160,160,160)); CFont newFont,*oldFont; newFont.CreatePointFont(90,"宋体"); oldFont = (CFont *)pDC->SelectObject(&newFont); pDC->DrawText(strText,&textRect,DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS); pDC->SelectObject(oldFont); pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); return; } CString strText; if(lpDrawItemStruct->itemID != LB_ERR) { GetLBText( lpDrawItemStruct->itemID,strText); } if(strText == "-" || strText == "+")//如果文本是- 则表示要创建减少年数的按钮 { CBrush brHighlight(RGB(231,241,245)); CBrush* pOldBrush = pDC->SelectObject(&brHighlight); CPen penHighlight(PS_SOLID, 1, RGB(107,141,162)); CPen* pOldPen = pDC->SelectObject(&penHighlight); CRect rcBackground; rcBackground.left = lpDrawItemStruct->rcItem.left + 2; rcBackground.right = lpDrawItemStruct->rcItem.right - 2; rcBackground.top = lpDrawItemStruct->rcItem.top + 2; rcBackground.bottom = lpDrawItemStruct->rcItem.bottom - 2; pDC->Rectangle(&rcBackground); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); //以下是绘制文本的部分 pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); return; } // Selected if ((lpDrawItemStruct->itemState & ODS_SELECTED) && (lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE))) { CBrush brHighlight(RGB(231,241,245)); CBrush* pOldBrush = pDC->SelectObject(&brHighlight); CPen penHighlight(PS_SOLID, 1, RGB(107,141,162)); CPen* pOldPen = pDC->SelectObject(&penHighlight); pDC->Rectangle(&lpDrawItemStruct->rcItem); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); //以下是绘制文本的部分 CRect textRect = lpDrawItemStruct->rcItem; textRect.left = textRect.left + 6; CString strText; if(lpDrawItemStruct->itemID != LB_ERR) { GetLBText( lpDrawItemStruct->itemID,strText); } CFont newFont,*oldFont; newFont.CreatePointFont(90,"宋体"); oldFont = (CFont *)pDC->SelectObject(&newFont); pDC->DrawText(strText,&textRect,DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS); pDC->SelectObject(oldFont); pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); } // De-Selected if (!(lpDrawItemStruct->itemState & ODS_SELECTED) && (lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE))) { CBrush brWindow(::GetSysColor(COLOR_WINDOW)); CBrush* pOldBrush = pDC->SelectObject(&brWindow); CPen penHighlight(PS_SOLID, 1, ::GetSysColor(COLOR_WINDOW)); CPen* pOldPen = pDC->SelectObject(&penHighlight); pDC->Rectangle(&lpDrawItemStruct->rcItem); pDC->SetBkColor(::GetSysColor(COLOR_WINDOW)); pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT)); //以下是绘制文本的部分 CRect textRect = lpDrawItemStruct->rcItem; textRect.left = textRect.left + 6; CString strText; if(lpDrawItemStruct->itemID != LB_ERR) { GetLBText( lpDrawItemStruct->itemID,strText); } CFont newFont,*oldFont; newFont.CreatePointFont(90,"宋体"); oldFont = (CFont *)pDC->SelectObject(&newFont); pDC->DrawText(strText,&textRect,DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS); pDC->SelectObject(oldFont); pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); } }