void CTrayMenuBtn::OnPaint() { CPaintDC dc(this); // device context for painting CRect rClient; GetClientRect(rClient); CDC MemDC; MemDC.CreateCompatibleDC(&dc); CBitmap MemBMP, *pOldBMP; MemBMP.CreateCompatibleBitmap(&dc, rClient.Width(), rClient.Height()); pOldBMP = MemDC.SelectObject(&MemBMP); CFont *pOldFONT = NULL; if(m_cfFont.GetSafeHandle()) pOldFONT = MemDC.SelectObject(&m_cfFont); BOOL bEnabled = IsWindowEnabled(); if(m_bMouseOver && bEnabled) { FillRect(MemDC.m_hDC, rClient, GetSysColorBrush(COLOR_HIGHLIGHT)); MemDC.SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { FillRect(MemDC.m_hDC, rClient, GetSysColorBrush(COLOR_BTNFACE)); MemDC.SetTextColor(GetSysColor(COLOR_BTNTEXT)); } int iLeftOffset = 0; if(m_bUseIcon) { MemDC.DrawState(CPoint(2,rClient.Height()/2-m_sIcon.cy/2),CSize(16,16),m_hIcon,DST_ICON|DSS_NORMAL,(CBrush*)NULL); iLeftOffset = m_sIcon.cx + 4; } MemDC.SetBkMode(TRANSPARENT); CRect rText(0,0,0,0); MemDC.DrawText(m_strText, rText, DT_CALCRECT|DT_SINGLELINE|DT_LEFT); //CPoint pt((rClient.Width()>>1)-(rText.Width()>>1),(rClient.Height()>>1)-(rText.Height()>>1)); CPoint pt(rClient.left+2+iLeftOffset, rClient.Height()/2-rText.Height()/2); CPoint sz(rText.Width(),rText.Height()); MemDC.DrawState(pt, sz, m_strText, DST_TEXT | (bEnabled ? DSS_NORMAL : DSS_DISABLED), FALSE, m_strText.GetLength(), (CBrush*)NULL); dc.BitBlt(0,0,rClient.Width(),rClient.Height(),&MemDC,0,0,SRCCOPY); MemDC.SelectObject(pOldBMP); if(pOldFONT) MemDC.SelectObject(pOldFONT); }
void WindowSelector::OnNcPaint() { CWnd::OnNcPaint(); CRect rc; GetWindowRect(rc); rc.right = rc.Width() - (::GetSystemMetrics(SM_CXSMSIZE) + ::GetSystemMetrics(SM_CXFRAME) + ::GetSystemMetrics(SM_CXBORDER)); rc.right -= 4; rc.left = rc.right - ::GetSystemMetrics(SM_CXSMSIZE) - 6; rc.top = ::GetSystemMetrics(SM_CYFRAME); rc.bottom = rc.top + ::GetSystemMetrics(SM_CYSMSIZE); CDC* pDC = GetWindowDC(); CDC dcMem; dcMem.CreateCompatibleDC(pDC); CBitmap bitmap; bitmap.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height()); CBitmap* pOldBitmap = dcMem.SelectObject(&bitmap); CRect rect(0, 0, rc.Width(), rc.Height()); if (m_bButtonPinned) { dcMem.DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH|DFCS_CHECKED); dcMem.DrawState(CPoint(1, 1), CSize(rect.Width()-2, rect.Height()-2), &m_bmpPinned, DST_BITMAP); } else { dcMem.DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH); dcMem.DrawState(CPoint(1, 1), CSize(rect.Width()-2, rect.Height()-2), &m_bmpUnpinned, DST_BITMAP); } pDC->BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY); dcMem.SelectObject(pOldBitmap); ReleaseDC(&dcMem); ReleaseDC(pDC); m_rcButton = rc; }
void CMSMoneyDemoView::OnDraw(CDC* pDCView) { CMemDC memDC (*pDCView, this); CDC* pDC = &memDC.GetDC (); CRect rectClient; GetClientRect (rectClient); pDC->FillSolidRect (rectClient, RGB (255, 255, 255)); pDC->DrawState (CPoint (20, 20), m_sizeImage, &m_Image, DSS_NORMAL); }
void CPicButton::DrawItem(LPDRAWITEMSTRUCT lpDIS) { // TODO: Add your code to draw the specified item CDC* pDC = CDC::FromHandle(lpDIS->hDC); CRect iconRect = lpDIS->rcItem; pDC->Rectangle(iconRect); BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED); pDC->DrawState(iconRect.TopLeft(), iconRect.Size(), (m_MouseOnButton == TRUE) ? m_hBmpIn : m_hBmpOut, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), (CBrush*)NULL); }
void CBCGPMSMoneyDemoView::OnDraw(CDC* pDCView) { CBCGPMemDC memDC (*pDCView, this); CDC* pDC = &memDC.GetDC (); CBCGPMSMoneyDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect rectClient; GetClientRect (rectClient); pDC->FillSolidRect (rectClient, RGB (255, 255, 255)); pDC->DrawState (m_ptOffset, m_sizeImage, &m_Image, DSS_NORMAL); }
// CMyButton message handlers void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; UINT state = lpDrawItemStruct->itemState; CString strText; GetWindowText(strText); // draw the control edges (DrawFrameControl is handy!) if (state & ODS_SELECTED) pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED); else pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH); // Deflate the drawing rect by the size of the button's edges rect.DeflateRect( CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE))); // Draw the text if (!strText.IsEmpty()) { CSize Extent = pDC->GetTextExtent(strText); CPoint pt( rect.CenterPoint().x - Extent.cx/2, rect.CenterPoint().y - Extent.cy/2 ); if (state & ODS_SELECTED) pt.Offset(1,1); int nMode = pDC->SetBkMode(TRANSPARENT); if (state & ODS_DISABLED) pDC->DrawState(pt, Extent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL); else pDC->TextOut(pt.x, pt.y, strText); pDC->SetBkMode(nMode); } }
void CBmpButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if(m_bitmap.GetObject==NULL) return; UINT nOffset=0; UINT nFrameStyle=0; BOOL bDRAWFOCUSONLY = FALSE; int nState=lpDrawItemStruct->itemState; UINT nNewAction = lpDrawItemStruct->itemAction; if ( nState & ODS_SELECTED) { nFrameStyle = DFCS_PUSHED; nOffset += 1; } nState=DSS_NORMAL; if (nNewAction == ODA_FOCUS ) bDRAWFOCUSONLY = TRUE; CRect rt; GetClientRect(&rt); if(!bDRAWFOCUSONLY) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rtControl( lpDrawItemStruct->rcItem ); CPoint pt(rtControl.left,rtControl.top); CSize sizeDraw; sizeDraw.cx=rt.Width(); sizeDraw.cy=rt.Height(); pt.Offset(nOffset,nOffset); pDC->Rectangle( &lpDrawItemStruct->rcItem ); pDC->DrawFrameControl(&rtControl, DFC_BUTTON, DFCS_BUTTONPUSH | nFrameStyle); pDC->DrawState(pt,sizeDraw,m_bitmap,DST_BITMAP|nState); } }
void CGuiCheckBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect m_rcClient(lpDrawItemStruct->rcItem); UINT m_State = lpDrawItemStruct->itemState; CBrush cb; CRect m_rcTemp(m_rcClient); CPoint pt; CSize m_Csize; CString m_szCaption; COLORREF m_Over = RGB(255, 193, 111); CPen cpOver(PS_SOLID, 1, RGB(255, 193, 111)); int iMode = pDC->SetBkMode(TRANSPARENT); int iExtile = GetButtonStyle(); // obtenemos orientación del texto CRect m_rcText(m_rcClient); GetWindowText(m_szCaption); if (m_szCaption.GetLength() > 1) m_Csize= pDC->GetTextExtent(m_szCaption); // de acuerdo a la alineación del texto prepare la ubicación // del texto para Drawtex y DrawState if (m_rcClient.Height() > 13) { int Dif = m_rcClient.Height() - 13; Dif /= 2; m_rcTemp.top = Dif; m_rcTemp.bottom = m_rcTemp.top + 13; } if (iExtile & BS_LEFTTEXT) { m_rcTemp.left= m_rcTemp.right - 13; pt = CPoint(m_rcTemp.left, m_rcTemp.top + 1); } else { m_rcTemp.right= m_rcTemp.left + 13; pt = CPoint(m_rcTemp.right + 2, m_rcTemp.top + 1); m_rcText.left = m_rcTemp.right + 1; } // draw frame of checkbox pDC->Draw3dRect(m_rcTemp, m_clrHigh, m_clrHigh); m_rcTemp.DeflateRect(1, 1); DrawOrange(pDC, m_rcTemp); m_rcTemp.DeflateRect(1, 1); if (lpDrawItemStruct->itemState & ODS_DISABLED) pDC->DrawState(pt, m_Csize, m_szCaption, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL); else { pDC->DrawText(m_szCaption, m_rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER); if (lpDrawItemStruct->itemState & ODS_SELECTED) { if (m_bOldTemp == TRUE) DrawCheck(pDC, m_rcTemp); } else { if (m_bCheckBtn == TRUE && m_bPressBtn == FALSE) DrawCheck(pDC, m_rcTemp); else { if (m_bOldTemp == TRUE && m_bPressBtn == TRUE) DrawCheck(pDC, m_rcTemp); } } } }
void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS) { #ifdef ST_USE_MEMDC CDC *pdrawDC = CDC::FromHandle(lpDIS->hDC); CMemDC memDC(pdrawDC); CDC *pDC = &memDC; #else CDC* pDC = CDC::FromHandle(lpDIS->hDC); #endif CPen *pOldPen; BOOL bIsPressed = (lpDIS->itemState & ODS_SELECTED); BOOL bIsFocused = (lpDIS->itemState & ODS_FOCUS); BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED); CRect itemRect = lpDIS->rcItem; if (m_bIsFlat == FALSE) { if (bIsFocused) { CBrush br(RGB(0,0,0)); pDC->FrameRect(&itemRect, &br); itemRect.DeflateRect(1, 1); } } // Prepare draw... paint button's area with background color COLORREF bgColor; if ((m_MouseOnButton == TRUE) || (bIsPressed)) bgColor = GetActiveBgColor(); else bgColor = GetInactiveBgColor(); CBrush br(bgColor); pDC->FillRect(&itemRect, &br); // Disegno lo sfondo del bottone //CBrush br(GetSysColor(COLOR_BTNFACE)); //pDC->FillRect(&itemRect, &br); // Draw pressed button if (bIsPressed) { if (m_bIsFlat == TRUE) { if (m_bDrawBorder == TRUE) { CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // Bianco CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Grigio scuro // Disegno i bordi a sinistra e in alto // Dark gray line pOldPen = pDC->SelectObject(&penBtnShadow); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.left, itemRect.top); pDC->LineTo(itemRect.right, itemRect.top); // Disegno i bordi a destra e in basso // White line pDC->SelectObject(penBtnHiLight); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.right-1, itemRect.bottom-1); pDC->LineTo(itemRect.right-1, itemRect.top-1); // pDC->SelectObject(pOldPen); } } else { CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW)); pDC->FrameRect(&itemRect, &brBtnShadow); } } else // ...else draw non pressed button { CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); // Light gray CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Dark gray CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black if (m_bIsFlat == TRUE) { if (m_MouseOnButton == TRUE && m_bDrawBorder == TRUE) { // Disegno i bordi a sinistra e in alto // White line pOldPen = pDC->SelectObject(&penBtnHiLight); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.left, itemRect.top); pDC->LineTo(itemRect.right, itemRect.top); // Disegno i bordi a destra e in basso // Dark gray line pDC->SelectObject(penBtnShadow); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.right-1, itemRect.bottom-1); pDC->LineTo(itemRect.right-1, itemRect.top-1); // pDC->SelectObject(pOldPen); } } else { // Disegno i bordi a sinistra e in alto // White line pOldPen = pDC->SelectObject(&penBtnHiLight); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.left, itemRect.top); pDC->LineTo(itemRect.right, itemRect.top); // Light gray line pDC->SelectObject(pen3DLight); pDC->MoveTo(itemRect.left+1, itemRect.bottom-1); pDC->LineTo(itemRect.left+1, itemRect.top+1); pDC->LineTo(itemRect.right, itemRect.top+1); // Disegno i bordi a destra e in basso // Black line pDC->SelectObject(pen3DDKShadow); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.right-1, itemRect.bottom-1); pDC->LineTo(itemRect.right-1, itemRect.top-1); // Dark gray line pDC->SelectObject(penBtnShadow); pDC->MoveTo(itemRect.left+1, itemRect.bottom-2); pDC->LineTo(itemRect.right-2, itemRect.bottom-2); pDC->LineTo(itemRect.right-2, itemRect.top); // pDC->SelectObject(pOldPen); } } // Read the button title CString sTitle; GetWindowText(sTitle); // If we don't want the title displayed if (m_bShowText == FALSE) sTitle.Empty(); CRect captionRect = lpDIS->rcItem; // Draw the icon if (m_hIconIn != NULL) { DrawTheIcon(pDC, &sTitle, &lpDIS->rcItem, &captionRect, bIsPressed, bIsDisabled); } // Write the button title (if any) if (sTitle.IsEmpty() == FALSE) { // Disegno la caption del bottone // Se il bottone e' premuto muovo la captionRect di conseguenza if (bIsPressed) captionRect.OffsetRect(1, 1); // ONLY FOR DEBUG // Evidenzia il rettangolo in cui verra' centrata la caption //CBrush brBtnShadow(RGB(255, 0, 0)); //pDC->FrameRect(&captionRect, &brBtnShadow); #ifdef ST_USE_MEMDC // Get dialog's font CFont *pCurrentFont = GetFont(); CFont *pOldFont = pDC->SelectObject(pCurrentFont); #endif if ((m_MouseOnButton == TRUE) || (bIsPressed)) { pDC->SetTextColor(GetActiveFgColor()); pDC->SetBkColor(GetActiveBgColor()); } else { pDC->SetTextColor(GetInactiveFgColor()); pDC->SetBkColor(GetInactiveBgColor()); } // Center text CRect centerRect = captionRect; pDC->DrawText(sTitle, -1, captionRect, DT_SINGLELINE|DT_CALCRECT); captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2); /* RFU captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2); captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2); */ pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), TRUE, 0, (CBrush*)NULL); #ifdef ST_USE_MEMDC pDC->SelectObject(pOldFont); #endif } if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE)) { // Draw the focus rect if (bIsFocused) { CRect focusRect = itemRect; focusRect.DeflateRect(3, 3); pDC->DrawFocusRect(&focusRect); } } } // End of DrawItem
//////////////////////////////////////////////////////////////////////////////// // // FUNCTION: DrawItem // // DESCRIPTION: Called in response to draw the button // // NOTES: // // MAINTENANCE: // Name: Date: Version: Notes: // NT ALMOND 210100 1.0 Origin // //////////////////////////////////////////////////////////////////////////////// void CCoolBtn::DrawItem(DRAWITEMSTRUCT* lpDIS) { if (lpDIS->CtlType != ODT_BUTTON) return; CFont *pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)); CDC dcMem; CBitmap bmp; CRect btnRect(lpDIS->rcItem); CRect trueRect(btnRect); CDC *pDC = CDC::FromHandle(lpDIS->hDC); //////////////////////////////////////// // Button Background // //////////////////////////////////////// pDC->FillRect(trueRect,&CBrush(GetSysColor(COLOR_BTNFACE))); BOOL bDisabled = ODS_DISABLED & lpDIS->itemState; if (m_bDefaultBtn) btnRect.DeflateRect(1,1); CRect rectFocus(btnRect); rectFocus.DeflateRect(4,4); if (!m_bMenuPushed) rectFocus.OffsetRect(m_bPushed,m_bPushed); rectFocus.right -= nDropBtnWidth; //////////////////////////////////////// // Button in a normal state // //////////////////////////////////////// if (!m_bPushed || m_bMenuPushed) { #ifdef _VISUALSTYLE_XP_H_ if (g_xpStyle.IsAppThemed()) { HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON"); g_xpStyle.DrawThemeBackground(hTheme, pDC->GetSafeHdc(), BP_PUSHBUTTON, PBS_NORMAL, &btnRect, 0); g_xpStyle.CloseThemeData(hTheme); } else { #endif pDC->DrawFrameControl(&btnRect,DFC_BUTTON,DFCS_BUTTONPUSH); #ifdef _VISUALSTYLE_XP_H_ } #endif } //////////////////////////////////////// // Default Button State // //////////////////////////////////////// if ((m_bDefaultBtn || m_bPushed) && !bDisabled) { if (m_bPushed && !m_bMenuPushed) { #ifdef _VISUALSTYLE_XP_H_ if (g_xpStyle.IsAppThemed()) { HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON"); g_xpStyle.DrawThemeBackground(hTheme, pDC->GetSafeHdc(), BP_PUSHBUTTON, PBS_PRESSED, &btnRect, 0); g_xpStyle.CloseThemeData(hTheme); } else { #endif pDC->FrameRect(&lpDIS->rcItem,CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH))); pDC->FrameRect(&btnRect,CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH))); #ifdef _VISUALSTYLE_XP_H_ } #endif } } //////////////////////////////////////// // State Hover // //////////////////////////////////////// if (m_bOverControl /*lpDIS->itemState & ODS_HOTLIGHT*/) if (!m_bMenuPushed) { #ifdef _VISUALSTYLE_XP_H_ if (g_xpStyle.IsAppThemed()) { HTHEME hTheme = g_xpStyle.OpenThemeData(GetSafeHwnd(), L"BUTTON"); g_xpStyle.DrawThemeBackground(hTheme, pDC->GetSafeHdc(), BP_PUSHBUTTON, PBS_HOT, &btnRect, 0); g_xpStyle.CloseThemeData(hTheme); } #endif } //////////////////////////////////////// // State Focus // //////////////////////////////////////// if (lpDIS->itemState & ODS_FOCUS || m_bPushed) if (!m_bMenuPushed) pDC->DrawFocusRect(&rectFocus); //////////////////////////////////////// // Action Focus // //////////////////////////////////////// if ((lpDIS->itemAction & ODA_FOCUS)) if (!m_bMenuPushed) pDC->DrawFocusRect(&rectFocus); //////////////////////////////////////// // Draw out bitmap // //////////////////////////////////////// // Draw out bitmap if (m_bLoaded) { if (!bDisabled) { m_IL.DrawIndirect(pDC,0,CPoint(6+m_bPushed,6+m_bPushed), CSize(m_bm.bmWidth, m_bm.bmHeight), CPoint(0,0),ILD_NORMAL); } else { pDC->DrawState(CPoint(6+m_bPushed,6+m_bPushed), CSize(m_bm.bmWidth, m_bm.bmHeight), m_hbmpDisabled, DST_BITMAP | DSS_DISABLED); } } //////////////////////////////////////// // Draw out text // //////////////////////////////////////// pDC->SelectObject(pFont); CRect rectText(rectFocus); rectFocus.left += m_bm.bmWidth + 2; CString strCaption; GetWindowText(strCaption); pDC->SetBkMode(TRANSPARENT); pDC->SetBkColor(GetSysColor(COLOR_BTNFACE)); if (ODS_DISABLED & lpDIS->itemState) { rectFocus.OffsetRect(1,1); pDC->SetTextColor(GetSysColor(COLOR_WINDOW)); pDC->DrawText(strCaption,rectFocus,DT_SINGLELINE|DT_CENTER|DT_VCENTER); rectFocus.OffsetRect(-1,-1); pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); pDC->DrawText(strCaption,rectFocus,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } else { pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); pDC->DrawText(strCaption,rectFocus,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } CRect rectSplit(btnRect); rectSplit.DeflateRect(2,2); rectSplit.right -= nDropBtnWidth; //////////////////////////////////////// // Drop down split // //////////////////////////////////////// CPen brFace(PS_SOLID,1,GetSysColor(COLOR_3DSHADOW)); pDC->SelectObject(&brFace); pDC->MoveTo(rectSplit.right, rectSplit.top); pDC->LineTo(rectSplit.right, rectSplit.bottom); CPen brLite(PS_SOLID,1,GetSysColor(COLOR_3DHILIGHT)); pDC->SelectObject(&brLite); pDC->MoveTo(rectSplit.right+1 , rectSplit.top); pDC->LineTo(rectSplit.right+1, rectSplit.bottom); rectSplit.left = rectSplit.right; rectSplit.right += nDropBtnWidth; CPoint pt(rectSplit.CenterPoint()); pt += CPoint(m_bPushed,m_bPushed); CPen penBlack(PS_SOLID, 1, bDisabled ? GetSysColor(COLOR_GRAYTEXT) : GetSysColor(COLOR_WINDOWTEXT)); pDC->SelectObject(&penBlack); DrawArrow(pDC,pt); //////////////////////////////////////// // Drop down state // //////////////////////////////////////// if (m_bMenuPushed && !bDisabled) { #ifdef _VISUALSTYLE_XP_H_ rectSplit.DeflateRect(1,1); #else rectSplit.InflateRect(1,1); #endif pDC->DrawEdge(rectSplit,BDR_SUNKENOUTER, BF_RECT); } }
void CGfxPopupMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (lpDrawItemStruct->CtlType == ODT_MENU) { UINT id = lpDrawItemStruct->itemID; UINT state = lpDrawItemStruct->itemState; bool bEnab = !(state & ODS_DISABLED); bool bSelect = (state & ODS_SELECTED) ? true : false; bool bChecked = (state & ODS_CHECKED) ? true : false; bool bBold = (state & ODS_DEFAULT) ? true : false; SpawnItem * pItem = (SpawnItem *) lpDrawItemStruct->itemData; if (pItem) { CDC * pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CFont * pft; if (!bBold) pft = CFont::FromHandle((HFONT) hMenuFont ? hMenuFont : hGuiFont); else pft = CFont::FromHandle((HFONT) hMenuBoldFont ? hMenuBoldFont : hGuiFont); CFont * of = pDC->SelectObject(pft); CRect rc(lpDrawItemStruct->rcItem); CRect rcImage(rc), rcText(rc); rcImage.right = rcImage.left + rc.Height(); rcImage.bottom = rc.bottom; if (pItem->iCmd == -3) // is a separator { CPen pnDk(PS_SOLID,1,cr3dShadow); CPen pnLt(PS_SOLID,1,cr3dHilight); CPen * opn = pDC->SelectObject(&pnDk); pDC->MoveTo(rc.left + 2, rc.top + 2); pDC->LineTo(rc.right - 2, rc.top + 2); pDC->SelectObject(&pnLt); pDC->MoveTo(rc.left + 2, rc.top + 3); pDC->LineTo(rc.right - 2, rc.top + 3); pDC->SelectObject(opn); } else if (pItem->iCmd == -4) // is a title item { CString cs(pItem->cText), cs1; CRect rcBdr(rcText); if (bSelect && bEnab) { rcText.top ++; rcText.left += 2; } pDC->FillSolidRect(rcText, crMenu); pDC->DrawText(cs, rcText, DT_VCENTER|DT_CENTER|DT_SINGLELINE); if (bSelect && bEnab) pDC->Draw3dRect(rcBdr,cr3dShadow,cr3dHilight); } else { rcText.left += rcImage.right + 1; int obk = pDC->SetBkMode(TRANSPARENT); COLORREF ocr; if (bSelect) { if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED)) pDC->FillSolidRect(rcText, crHighlight); else pDC->FillSolidRect(rc, crHighlight); ocr = pDC->SetTextColor(crMenuTextSel); } else { if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED)) pDC->FillSolidRect(rcText, crMenu); else pDC->FillSolidRect(rc/*rcText*/, crMenu); ocr = pDC->SetTextColor(crMenuText); } if (pItem->iImageIdx >= 0) { int ay = (rcImage.Height() - szImage.cy) / 2; int ax = (rcImage.Width() - szImage.cx) / 2; if (bSelect && bEnab) pDC->Draw3dRect(rcImage,cr3dHilight,cr3dShadow); else { pDC->Draw3dRect(rcImage,crMenu,crMenu); } if (bEnab) { ilList.Draw(pDC, pItem->iImageIdx, CPoint(rcImage.left + ax, rcImage.top +ay), ILD_NORMAL); } else { HICON hIcon = ilList.ExtractIcon( pItem->iImageIdx ); pDC->DrawState( CPoint(rcImage.left + ax, rcImage.top + ay ), szImage, (HICON)hIcon, DST_ICON | DSS_DISABLED, (CBrush *)NULL ); } } else { if (bChecked) { int ay = (rcImage.Height() - szImage.cy) / 2; int ax = (rcImage.Width() - szImage.cx) / 2; ilOther.Draw(pDC, 0, CPoint(rcImage.left + ax, rcImage.top + ay - 2), ILD_NORMAL); } } CString cs(pItem->cText), cs1; CSize sz; sz = pDC->GetTextExtent(cs); int ay1 = (rcText.Height() - sz.cy) / 2; rcText.top += ay1; rcText.left += 2; rcText.right -= 15; int tf = cs.Find('\t'); if (tf >= 0) { cs1 = cs.Right(cs.GetLength() - tf - 1); cs = cs.Left(tf); if (!bEnab) { if (!bSelect) { CRect rcText1(rcText); rcText1.InflateRect(-1,-1); pDC->SetTextColor(cr3dHilight); pDC->DrawText(cs, rcText1, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText1, DT_VCENTER|DT_RIGHT); pDC->SetTextColor(crGrayText); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT); } else { pDC->SetTextColor(crMenu); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT); } } else { pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT); pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT); } } else { if (!bEnab) { if (!bSelect) { CRect rcText1(rcText); rcText1.InflateRect(-1,-1); pDC->SetTextColor(cr3dHilight); pDC->DrawText(cs, rcText1, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); pDC->SetTextColor(crGrayText); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); } else { pDC->SetTextColor(crMenu); pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); } } else pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS); } pDC->SetTextColor(ocr); pDC->SetBkMode(obk); } pDC->SelectObject(of); } } }
void CRoundSliderCtrl::OnPaint() { const int nMin = GetRangeMin(); const int nMax = GetRangeMax()+1; const bool bDisabled = !IsWindowEnabled(); CPaintDC dc(this); // device context for painting #ifdef USE_MEM_DC CMemDC pDC(&dc); #else CDC* pDC = &dc; #endif int nRadius = m_nRadius; // Draw (clear) the background CRect rc; GetClientRect(rc); pDC->SelectStockObject(NULL_BRUSH); pDC->SelectStockObject(NULL_PEN); pDC->FillSolidRect(rc, ::GetSysColor(COLOR_BTNFACE)); // Draw the sliders channel if(!m_bDrawRadioButton) { DrawCircle(pDC, m_ptCenter, nRadius--, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DHIGHLIGHT)); DrawCircle(pDC, m_ptCenter, nRadius, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DLIGHT)); } int nPos = (((GetPos()-nMin)*360/(nMax-nMin)) + m_nZero + 360) % 360; if(m_bInverted) nPos = 360-nPos; const double dPos = ((double)(nPos))*pi/180.0; CPoint ptKnobCenter; #pragma warning(disable:4244) // Disable warning "Converting 'double' to 'int', possible loss of data" if(m_bDrawRadioButton) { ptKnobCenter = CPoint(m_ptCenter.x + (nRadius-m_nKnobRadius) * sin(dPos), m_ptCenter.y - (nRadius-m_nKnobRadius) * cos(dPos)); } else { ptKnobCenter = CPoint(m_ptCenter.x + (nRadius) * sin(dPos), m_ptCenter.y - (nRadius) * cos(dPos)); } #pragma warning(default:4244) m_ptKnobCenter = ptKnobCenter; if(m_bDrawRadioButton) { nRadius += 2; } else { nRadius -= 2; } if(!bDisabled) { CBrush* pOldBrush = pDC->SelectObject(CBrush::FromHandle(m_hDialBrush)); pDC->Ellipse(m_ptCenter.x - nRadius + 1, m_ptCenter.y - nRadius + 1, m_ptCenter.x + nRadius + 1, m_ptCenter.y + nRadius + 1); pDC->SelectObject(pOldBrush); } DrawCircle(pDC, m_ptCenter, nRadius--, ::GetSysColor(COLOR_3DHIGHLIGHT), ::GetSysColor(COLOR_3DDKSHADOW)); DrawCircle(pDC, m_ptCenter, nRadius--, ::GetSysColor(COLOR_3DLIGHT), ::GetSysColor(COLOR_3DSHADOW)); // Draw the knob int nKnobRadius = m_nKnobRadius; if(m_bDrawRadioButton) { nKnobRadius *= 4; nKnobRadius /= 5; } const CRect rcKnob(ptKnobCenter.x - nKnobRadius + 2, ptKnobCenter.y - nKnobRadius + 2, ptKnobCenter.x + nKnobRadius, ptKnobCenter.y + nKnobRadius); CRgn rgnKnob; rgnKnob.CreateEllipticRgnIndirect(rcKnob); if(bDisabled) { pDC->FillRgn(&rgnKnob, CBrush::FromHandle(::GetSysColorBrush(COLOR_BTNFACE))); } else { pDC->FillRgn(&rgnKnob, CBrush::FromHandle(m_hKnobBrush)); } rgnKnob.DeleteObject(); if(m_bDrawRadioButton || m_bDragging) { DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DHIGHLIGHT)); DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DLIGHT)); } else { DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DHIGHLIGHT), ::GetSysColor(COLOR_3DDKSHADOW)); DrawCircle(pDC, ptKnobCenter, --nKnobRadius, ::GetSysColor(COLOR_3DLIGHT), ::GetSysColor(COLOR_3DSHADOW)); } // Draw the focus circle on the inside of the knob if(!m_bDrawRadioButton && (GetFocus() == this)) { DrawCircle(pDC, ptKnobCenter, nKnobRadius-2, RGB(0, 0, 0), TRUE); } // Draw the text const CString strFormattedText = OnFormatText(); if(!strFormattedText.IsEmpty()) { CFont* pOldFont = pDC->SelectObject(&m_font); const CSize szExtent = pDC->GetTextExtent(strFormattedText); const CPoint ptText = CPoint(m_ptCenter.x - szExtent.cx/2, m_ptCenter.y - szExtent.cy/2); const int nOldTextColor = pDC->SetTextColor(m_crText); pDC->SetBkMode(TRANSPARENT); if(bDisabled) { pDC->DrawState(ptText, szExtent, strFormattedText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL); } else { pDC->TextOut(ptText.x, ptText.y, strFormattedText); } // Clean up pDC->SelectObject(pOldFont); pDC->SetTextColor(nOldTextColor); } // Don't call CSliderCtrl::OnPaint() }
void CSkinBtn::DrawButton() { CPoint posText(0,0); if(m_bRePain == FALSE) { CClientDC dc(this); CRect rect; GetClientRect(&rect); CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap Screen; Screen.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()); memDC.SelectObject(&Screen); Screen.DeleteObject(); //画背景 memDC.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &m_memDC, 0, 0, SRCCOPY); CString str(_T("")); GetWindowText(str); memDC.SetBkMode(TRANSPARENT); memDC.SelectObject(m_pFont); CDC MemDC; MemDC.CreateCompatibleDC(&dc); BITMAP bm; if(m_IconDraw) { CRect rImage; rImage.top = 0; rImage.left = 0; BOOL bRetValue; ICONINFO ii; ::ZeroMemory(&ii, sizeof(ICONINFO)); bRetValue = ::GetIconInfo(m_IconIn, &ii); if (bRetValue == FALSE) { if (m_IconIn) ::DestroyIcon(m_IconIn); rImage.bottom = 16; rImage.right = 16; } else { rImage.right = (DWORD)(ii.xHotspot * 2); rImage.bottom = (DWORD)(ii.yHotspot * 2); } ::DeleteObject(ii.hbmMask); ::DeleteObject(ii.hbmColor); //int nXOffset = (rect.Width() - rImage.right)/2; int nYOffset = (rect.Height() - rImage.bottom)/2;//rect.Width(), rect.Height() if(nYOffset < 0) nYOffset = 0; rImage.top += nYOffset; posText.x = rImage.right + 2; posText.y = (rect.Height() - 20)/2; if(posText.y < 0) posText.y = 0; switch(m_state) { case NORMAL: // Ole'! memDC.DrawState(rImage.TopLeft(), rImage.Size(), m_IconIn, DSS_NORMAL, (CBrush*)NULL); memDC.SetTextColor(GetFGColor()); // memDC.TextOut(m_textPos.x,m_textPos.y,str); break; case HOVER: // Ole'! memDC.DrawState(rImage.TopLeft(), rImage.Size(), m_IconOut, DSS_NORMAL, (CBrush*)NULL); memDC.SetTextColor(RGB(36,93,219)); // memDC.TextOut(m_textPos.x,m_textPos.y,str); if(m_bDrawRantage) { memDC.MoveTo(rect.left,rect.top); memDC.LineTo(rect.right,rect.top); memDC.MoveTo(rect.left,rect.top); memDC.LineTo(rect.left,rect.bottom); memDC.MoveTo(rect.left,rect.bottom - 1); memDC.LineTo(rect.right,rect.bottom - 1); memDC.MoveTo(rect.right - 1,rect.top); memDC.LineTo(rect.right - 1,rect.bottom); } // memDC.SetBkColor(TRANSPARENT); // memDC.Rectangle(rect); break; case DOWN: // Ole'! // SetTimer(2,20,NULL); memDC.DrawState(rImage.TopLeft(), rImage.Size(), m_IconOut, DSS_NORMAL, (CBrush*)NULL); memDC.SetTextColor(GetBGColor()); // memDC.TextOut(m_textPos.x,m_textPos.y,str); break; case DISABLE: memDC.DrawState(rImage.TopLeft(), rImage.Size(), m_IconIn, DSS_NORMAL, (CBrush*)NULL); memDC.SetTextColor(GetFGColor()); // memDC.TextOut(m_textPos.x,m_textPos.y,str); break; default: break; } } else { CString ss; GetWindowText(ss); m_imgNormal.GetBitmap(&bm); int nYOffset = (rect.Height() - bm.bmHeight)/2;//rect.Width(), rect.Height() if(nYOffset < 0) nYOffset = 0; posText.x = rect.left + bm.bmWidth + 2; posText.y = (rect.Height() - 20)/2; if(posText.y < 0) posText.y = 0; posText = m_textPos; if(m_ShowState == 1) {//强制设成选取中状态 m_imgDown.GetBitmap(&bm); // SetTimer(2,20,NULL); MemDC.SelectObject(&m_imgDown); if(bm.bmHeight>rect.bottom || bm.bmWidth>rect.right) memDC.StretchBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,bm.bmWidth, bm.bmHeight,SRCCOPY); else memDC.BitBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY); memDC.SetTextColor(GetBGColor()); } else { switch(m_state) { case NORMAL: m_imgNormal.GetBitmap(&bm); MemDC.SelectObject(&m_imgNormal); if(bm.bmHeight>rect.bottom || bm.bmWidth>rect.right) memDC.StretchBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,bm.bmWidth, bm.bmHeight,SRCCOPY); else memDC.BitBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY); memDC.SetTextColor(GetFGColor()); // memDC.TextOut(m_textPos.x,m_textPos.y,str); break; case HOVER: m_imgHover.GetBitmap(&bm); MemDC.SelectObject(&m_imgHover); if(bm.bmHeight>rect.bottom || bm.bmWidth>rect.right) memDC.StretchBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,bm.bmWidth, bm.bmHeight,SRCCOPY); else memDC.BitBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY); if(m_bDrawRantage) { memDC.SetTextColor(GetBGColor()); memDC.TextOut(m_textPos.x,m_textPos.y,str); memDC.MoveTo(rect.left,rect.top); memDC.LineTo(rect.right,rect.top); memDC.MoveTo(rect.left,rect.top); memDC.LineTo(rect.left,rect.bottom); memDC.MoveTo(rect.left,rect.bottom - 1); memDC.LineTo(rect.right,rect.bottom - 1); memDC.MoveTo(rect.right - 1,rect.top); memDC.LineTo(rect.right - 1,rect.bottom); } break; case DOWN: m_imgDown.GetBitmap(&bm); // SetTimer(2,20,NULL); MemDC.SelectObject(&m_imgDown); if(bm.bmHeight>rect.bottom || bm.bmWidth>rect.right) memDC.StretchBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,bm.bmWidth, bm.bmHeight,SRCCOPY); else memDC.BitBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY); memDC.SetTextColor(GetBGColor()); // memDC.TextOut(m_textPos.x,m_textPos.y,str); break; case DISABLE: m_imgDisable.GetBitmap(&bm); MemDC.SelectObject(&m_imgDisable); if(bm.bmHeight>rect.bottom || bm.bmWidth>rect.right) memDC.StretchBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,bm.bmWidth, bm.bmHeight,SRCCOPY); else memDC.BitBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY); memDC.SetTextColor(GetFGColor()); // memDC.TextOut(m_textPos.x,m_textPos.y,str); break; default: break; } } } if(!str.IsEmpty()) { memDC.TextOut(posText.x,posText.y,str); } dc.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY); memDC.DeleteDC(); MemDC.DeleteDC(); } }
void CButtonXP::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //从lpDrawItemStruct获取控件的相关信息 CRect rect = lpDrawItemStruct->rcItem; CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); int nSaveDC = pDC->SaveDC(); UINT state = lpDrawItemStruct->itemState; POINT pt ; TCHAR strText[MAX_PATH + 1]; ::GetWindowText(m_hWnd, strText, MAX_PATH); //画按钮的外边框,它是一个半径为5的圆角矩形 pt.x = 5; pt.y = 5; CPen* hOldPen = pDC->SelectObject(&m_BoundryPen); pDC->RoundRect(&rect, pt); //获取按钮的状态 if (state & ODS_FOCUS) { m_bFocus = TRUE; m_bSelected = TRUE; } else { m_bFocus = FALSE; m_bSelected = FALSE; } if (state & ODS_SELECTED || state & ODS_DEFAULT) { m_bFocus = TRUE; } pDC->SelectObject(hOldPen); rect.DeflateRect(CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE))); //根据按钮的状态填充按钮的底色 CBrush* pOldBrush; if (m_bOver) { pOldBrush = pDC->SelectObject(&m_FillActive); DoGradientFill(pDC, &rect); } else { pOldBrush = pDC->SelectObject(&m_FillInactive); DoGradientFill(pDC, &rect); } //根据按钮的状态绘制内边框 if (m_bOver || m_bSelected) DrawInsideBorder(pDC, &rect); pDC->SelectObject(pOldBrush); //显示按钮的文本 if (strText!=NULL) { CFont* hFont = GetFont(); CFont* hOldFont = pDC->SelectObject(hFont); CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText)); CPoint pt( rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2); if (state & ODS_SELECTED) pt.Offset(1, 1); int nMode = pDC->SetBkMode(TRANSPARENT); if (state & ODS_DISABLED) pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL); else pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL); pDC->SelectObject(hOldFont); pDC->SetBkMode(nMode); } pDC->RestoreDC(nSaveDC); }
void CRoundButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { ASSERT(lpDrawItemStruct != NULL); CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; UINT state = lpDrawItemStruct->itemState; UINT nStyle = GetStyle(); int nRadius = m_nRadius; int nSavedDC = pDC->SaveDC(); pDC->SelectStockObject(NULL_BRUSH); pDC->FillSolidRect(rect, ::GetSysColor(COLOR_BTNFACE)); // Draw the focus circle around the button if ((state & ODS_FOCUS) && m_bDrawDashedFocusCircle) DrawCircle(pDC, m_ptCentre, nRadius--, RGB(0,0,0)); // Draw the raised/sunken edges of the button (unless flat) if (nStyle & BS_FLAT) { DrawCircle(pDC, m_ptCentre, nRadius--, RGB(0,0,0)); DrawCircle(pDC, m_ptCentre, nRadius--, ::GetSysColor(COLOR_3DHIGHLIGHT)); } else { if ((state & ODS_SELECTED)) { DrawCircle(pDC, m_ptCentre, nRadius--, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DHIGHLIGHT)); DrawCircle(pDC, m_ptCentre, nRadius--, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DLIGHT)); } else { DrawCircle(pDC, m_ptCentre, nRadius--, ::GetSysColor(COLOR_3DHIGHLIGHT), ::GetSysColor(COLOR_3DDKSHADOW)); DrawCircle(pDC, m_ptCentre, nRadius--, ::GetSysColor(COLOR_3DLIGHT), ::GetSysColor(COLOR_3DSHADOW)); } } // draw the text if there is any CString strText; GetWindowText(strText); if (!strText.IsEmpty()) { CRgn rgn; rgn.CreateEllipticRgn(m_ptCentre.x-nRadius, m_ptCentre.y-nRadius, m_ptCentre.x+nRadius, m_ptCentre.y+nRadius); pDC->SelectClipRgn(&rgn); CSize Extent = pDC->GetTextExtent(strText); CPoint pt = CPoint( m_ptCentre.x - Extent.cx/2, m_ptCentre.x - Extent.cy/2 ); if (state & ODS_SELECTED) pt.Offset(1,1); pDC->SetBkMode(TRANSPARENT); if (state & ODS_DISABLED) pDC->DrawState(pt, Extent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL); else pDC->TextOut(pt.x, pt.y, strText); pDC->SelectClipRgn(NULL); rgn.DeleteObject(); } // Draw the focus circle on the inside of the button if ((state & ODS_FOCUS) && m_bDrawDashedFocusCircle) DrawCircle(pDC, m_ptCentre, nRadius-2, RGB(0,0,0), TRUE); pDC->RestoreDC(nSavedDC); }
CRect TranscriptWindow::DrawButton( CDC& dc, CRect& rect, bool centre, const char* text, Button button, bool enable) { // Select the font and measure the text in it CFont* oldFont = dc.SelectObject(theApp.GetFont(InformApp::FontDisplay)); CSize size = dc.GetTextExtent(text); // Adjust the width of the button if (centre) { rect.left = rect.right-(size.cx/2)-m_layout.margin.cx; rect.right = rect.left+size.cx+m_layout.margin.cx*2; } else rect.left = rect.right-size.cx-m_layout.margin.cx*2; // Determine the button's state CPoint mousePoint = GetCurrentMessage()->pt; ScreenToClient(&mousePoint); bool over = (rect.PtInRect(mousePoint) != 0); bool down = (m_buttonDown == button); if (theOS.IsAppThemed()) { // Open the button theme HTHEME theme = theOS.OpenThemeData(this,L"Button"); if (theme) { UINT state = PBS_NORMAL; if (!enable) state = PBS_DISABLED; else if (over && down) state = PBS_PRESSED; else if (down) state = PBS_HOT; else if (over && (m_buttonDown == Button())) state = PBS_HOT; // Draw the themed control frame theOS.DrawThemeBackground(theme,&dc,BP_PUSHBUTTON,state,rect); // Get the background size CRect backRect(rect); theOS.GetThemeBackgroundContentRect(theme,&dc,BP_PUSHBUTTON,state,backRect); // Draw the themed button text CStringW textW(text); theOS.DrawThemeText(theme,&dc,BP_PUSHBUTTON,state,textW, DT_CENTER|DT_VCENTER|DT_SINGLELINE,DTT_GRAYED,backRect); // Close the button theme theOS.CloseThemeData(theme); } } else { UINT state = DFCS_BUTTONPUSH; if (!enable) state |= DFCS_INACTIVE; else if (over && down) state |= DFCS_PUSHED; // Draw the control background dc.DrawFrameControl(rect,DFC_BUTTON,state); // Work out the bounding rectangle for the button text CRect textRect(rect); textRect.DeflateRect((rect.Width()-size.cx)/2,(rect.Height()-size.cy)/2); if (state & DFCS_PUSHED) { textRect.top++; textRect.left++; } // Draw the button text dc.DrawState(textRect.TopLeft(),textRect.Size(),text, (state & DFCS_INACTIVE) ? DSS_DISABLED : DSS_NORMAL,TRUE,0,(HBRUSH)0); } // Select the previous font dc.SelectObject(oldFont); // Store the button rectangle if (enable) m_buttons.push_back(std::make_pair(rect,button)); // Return the button rectangle return rect; }