本文整理汇总了C++中CDC::DrawState方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::DrawState方法的具体用法?C++ CDC::DrawState怎么用?C++ CDC::DrawState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::DrawState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnPaint
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);
}
示例2: OnNcPaint
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;
}
示例3: OnDraw
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);
}
示例4: DrawItem
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);
}
示例5: OnDraw
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);
}
示例6: DrawItem
// 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);
}
}
示例7: DrawItem
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);
}
}
示例8: DrawItem
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);
}
}
}
}
示例9: DrawItem
//.........这里部分代码省略.........
}
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
示例10: DrawItem
//.........这里部分代码省略.........
}
#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);
}
示例11: DrawItem
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
//.........这里部分代码省略.........
示例12: OnPaint
//.........这里部分代码省略.........
#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()
}
示例13: DrawButton
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);
//.........这里部分代码省略.........
示例14: DrawItem
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);
}
示例15: DrawItem
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);
}