本文整理汇总了C++中CBrush::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ CBrush::Attach方法的具体用法?C++ CBrush::Attach怎么用?C++ CBrush::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBrush
的用法示例。
在下文中一共展示了CBrush::Attach方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnPaint
void CTextProgressCtrl::OnPaint() {
CPaintDC dc(this); // device context for painting
int saveDC = dc.SaveDC();
CRect rcClient;
GetClientRect(&rcClient);
CBrush brHollow;
brHollow.Attach(::GetStockObject(NULL_BRUSH));
dc.SelectObject(&brHollow);
// frame
CPen pen(PS_SOLID, SCALEX(1), ::GetSysColor(COLOR_WINDOWFRAME));
dc.SelectObject(&pen);
HIDPI_BorderRectangle(dc.GetSafeHdc(), rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
// inside
rcClient.DeflateRect(SCALEX(1), SCALEY(1));
int nWd = (Hi - Lo);
double pos = (double) Pos / nWd;
// bar
int nPhysPos = (int) (rcClient.Width() * pos);
COLORREF clrBar = ::GetSysColor(COLOR_HIGHLIGHT);
CRect rcBar(rcClient.left, rcClient.top, rcClient.left + nPhysPos, rcClient.bottom);
dc.FillSolidRect(&rcBar, clrBar);
COLORREF clrBkgnd = ::GetSysColor(COLOR_3DSHADOW);
CRect rcBack(rcClient.left + nPhysPos, rcClient.top, rcClient.right, rcClient.bottom);
dc.FillSolidRect(&rcBack, clrBkgnd);
// draw text over the progress bar
rcClient.DeflateRect(SCALEX(4), -1, SCALEX(4), 1);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
CRect rcSize(0, 0, 0, 0);
if (!m_strSize.IsEmpty()) {
dc.SelectObject(&m_fntSize);
rcSize = rcClient;
dc.DrawText(m_strSize, rcSize, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
dc.DrawText(m_strSize, rcClient, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
}
dc.SelectObject(&m_fntText);
CRect rcProgress = rcClient;
rcProgress.right -= rcSize.Width() - SCALEX(6);
DrawTextEndEllipsis(dc, m_strText, rcProgress, DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
// validate
GetClientRect(&rcClient);
ValidateRect(rcClient);
dc.RestoreDC(saveDC);
}
示例2: OnPaint
void CMyLabel::OnPaint() {
CPaintDC dc(this); // device context for painting
DWORD dwFlags = DT_LEFT | DT_WORDBREAK;
CRect rc;
GetClientRect(rc);
CString strText;
GetWindowText(strText);
CBitmap bmp;
CDC* pDCMem;
CBitmap* pOldBitmap = NULL;
pDCMem = new CDC;
pDCMem->CreateCompatibleDC(&dc);
bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
pOldBitmap = pDCMem->SelectObject(&bmp);
UINT nMode = pDCMem->SetBkMode(TRANSPARENT);
COLORREF crText;
if (IsWindowEnabled()) {
crText = pDCMem->SetTextColor(m_textColor);
} else {
crText = pDCMem->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
}
CFont *pOldFont = pDCMem->SelectObject(&m_font);
CBrush br;
br.Attach(m_brush);
pDCMem->FillRect(rc,&br);
br.Detach();
pDCMem->DrawText(strText,rc,dwFlags);
// Restore DC's State
pDCMem->SetBkMode(nMode);
pDCMem->SelectObject(pOldFont);
pDCMem->SetTextColor(crText);
dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY);
// continue DC restore
pDCMem->SelectObject ( pOldBitmap ) ;
delete pDCMem;
}
示例3: OnPaint
void CLabel::OnPaint()
{
CPaintDC dc(this); // device context for painting
DWORD dwFlags = 0;
CRect rc;
GetClientRect(rc);
CString strText;
GetWindowText(strText);
CBitmap bmp;
///////////////////////////////////////////////////////
//
// Set up for double buffering...
//
CDC* pDCMem;
CBitmap* pOldBitmap = NULL;
if (!m_bTransparent)
{
pDCMem = new CDC;
pDCMem->CreateCompatibleDC(&dc);
bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
pOldBitmap = pDCMem->SelectObject(&bmp);
}
else
{
pDCMem = &dc;
}
UINT nMode = pDCMem->SetBkMode(TRANSPARENT);
COLORREF crText = pDCMem->SetTextColor(m_crText);
CFont *pOldFont = pDCMem->SelectObject(&m_font);
// Fill in backgound if not transparent
if (!m_bTransparent)
{
if (m_fillmode == Normal)
{
CBrush br;
if (m_hBackBrush != NULL)
br.Attach(m_hBackBrush);
else
br.Attach(m_hwndBrush);
pDCMem->FillRect(rc,&br);
br.Detach();
}
else // Gradient Fill
{
DrawGradientFill(pDCMem, &rc, m_crLoColor, m_crHiColor, 100);
}
}
// If the text is flashing turn the text color on
// then to the color of the window background.
LOGBRUSH lb;
ZeroMemory(&lb,sizeof(lb));
// Stop Checking complaining
if (m_hBackBrush)
::GetObject(m_hBackBrush,sizeof(lb),&lb);
// Something to do with flashing
if (!m_bState && m_Type == Text)
pDCMem->SetTextColor(lb.lbColor);
DWORD style = GetStyle();
switch (style & SS_TYPEMASK)
{
case SS_RIGHT:
dwFlags = DT_RIGHT | DT_WORDBREAK;
break;
case SS_CENTER:
dwFlags = SS_CENTER | DT_WORDBREAK;
break;
case SS_LEFTNOWORDWRAP:
dwFlags = DT_LEFT;
break;
default: // treat other types as left
case SS_LEFT:
dwFlags = DT_LEFT | DT_WORDBREAK;
break;
}
//.........这里部分代码省略.........
示例4: OnPaint
void FeatureDistribution::OnPaint()
{
// TODO: Add your message handler code here
// Do not call CStatic::OnPaint() for painting messages
CPaintDC dc(this); // device context-ul pentru afisare
RECT rectf;
GetClientRect(&rectf);
CBrush brush;
brush.Attach(GetStockObject(LTGRAY_BRUSH));
dc.FillRect(&rectf, &brush);
brush.Detach();
CPen pen(PS_SOLID, 1, RGB(255,0,0)); // definirea pen-ului de desenare cu culoare rosie
CPen *pTempPen=dc.SelectObject(&pen); // selectarea pen-ului de afisare
CRect rect;
GetClientRect(rect); // obtine zona de afisare dreptunghiulara disponibila
int height=rect.Height(); // inaltimea zonei de afisare
int width=rect.Width(); // latimea zonei de afisare
int upperOffset = 10;
// se determina maximul sirului values[256]
int i;
int maxV=0;
for (i=0;i<nbValues;i++)
if (pdf[i]>maxV)
maxV=pdf[i];
// se verifica daca este nevoie de scalare
double scaleFactor=1.0;
int heightOffset = 20;
// facem intotdeauna scalarea; astfel incat la maxValue sa corespunda height;
scaleFactor=(double)(height-heightOffset)/maxV;
int intervalDim = width/(this->nbValues)-1;
//find the dimension of an interval, and draw rectangles not lines;
// se afiseaza pdf (eventual scalata) ca niste bare verticale
for (i=0;i<nbValues;i++)
{
// determinarea lungimii liniei
int lengthLine=(int)(scaleFactor*pdf[i]);
for (int j = i*intervalDim+2; j < i*intervalDim+intervalDim-1; j++)
{
//afisarea dreptunghiului
dc.MoveTo(j,height-heightOffset);
dc.LineTo(j,height-heightOffset-lengthLine);
}
}
dc.SelectObject(pTempPen); // restaurarea pen-ului de afisare
#if 0
CPen pen2(PS_SOLID, 1, RGB(5,0,0)); // definirea pen-ului de desenare cu culoare rosie
CPen *pTempPen2=dc.SelectObject(&pen2); // selectarea pen-ului de afisare
dc.MoveTo(0, height-heightOffset);
dc.LineTo(nbValues*intervalDim, height-heightOffset);
dc.MoveTo(0, height-heightOffset);
dc.LineTo(0, 0);
CPoint pos ;
int intervalDimReal = (maxValue - minValue)/nbValues;
CString msg;
for (i = 0; i < nbValues; i++)
{
pos.x = (i+1)*intervalDim - 3*intervalDim/4;
pos.y = height - heightOffset;
msg.Format("%d",(i+1)*intervalDimReal/2);
dc.TextOut(pos.x, pos.y, msg);
dc.MoveTo(0, height-heightOffset);
dc.LineTo(nbValues*intervalDim, height-heightOffset);
}
dc.SelectObject(pTempPen2); // restaurarea pen-ului de afisare
#endif
}