本文整理汇总了C++中CBrush::FromHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ CBrush::FromHandle方法的具体用法?C++ CBrush::FromHandle怎么用?C++ CBrush::FromHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBrush
的用法示例。
在下文中一共展示了CBrush::FromHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnDraw
void CMFCView::OnDraw(CDC* pDC)
{
CMFCDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect r;
GetClientRect(&r);
// array of font name
CString font[4]={"Arial","Tahoma","Times New Roman", "Consolas"};
CBrush brush; // init
brush.CreateSolidBrush(RGB(255,0,0)); // red brush
CBrush *pTempBrush = NULL;
CBrush origBrush;
pTempBrush = (CBrush*) pDC->SelectObject(&brush);
// save original brush
origBrush.FromHandle((HBRUSH)pTempBrush);
// paint upper left corner with red brush
pDC->Rectangle(0,0,r.Width()/2, r.Height()/2);
try
{
CBrush brush2(RGB(rand()%255,rand()%255,rand()%255));
CBrush brush3(RGB(rand()%255,rand()%255,rand()%255));
CBrush brush4(RGB(rand()%255,rand()%255,rand()%255));
pTempBrush = (CBrush*)pDC->SelectObject(&brush2);
// Paint upper right corner with red brush.
pDC->Rectangle(r.Width() / 2, 0, r.Width(), r.Height() / 2);
pTempBrush = (CBrush*)pDC->SelectObject(&brush3);
// Paint lower left corner with green hatched brush.
pDC->Rectangle(0, r.Height() / 2, r.Width() / 2, r.Height());
pTempBrush = (CBrush*)pDC->SelectObject(&brush4);
// Paint lower right corner with resource brush.
pDC->Rectangle(r.Width() / 2, r.Height() / 2, r.Width(), r.Height());
}
catch(CResourceException* e)
{
e->ReportError();
e->Delete();
}
pDC->SelectObject(&origBrush);
// set font for every times we create new single view
CFont *oldf, f;
// select a random font in font array.
f.CreateFont(rand()%80, rand()%30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, font[rand()%4]);
oldf= pDC->SelectObject(&f);
pDC->SetTextAlign(TA_CENTER); // align text to the center of the screen
pDC->SetTextColor(RGB(rand()%255,rand()%255,rand()%255));
pDC->TextOut(r.CenterPoint().x, r.CenterPoint().y, "hello world");
// draw new rectangle
CPen pen(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255));
CPen *pOldPen = pDC->SelectObject(&pen);
pDC->Rectangle(50, 50, 250, 250);
pDC->SelectObject(pOldPen);
// draw new ellipse
CPen pen2(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255));
CPen *pOldPen2 = pDC->SelectObject(&pen2);
pDC->Ellipse(50, 50, 250, 250);
pDC->SelectObject(pOldPen2);
// duong cheo chinh
CPen pen3(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255));
CPen *pOldPen3 = pDC->SelectObject(&pen3);
pDC->MoveTo(50, 50);
pDC->LineTo(250, 250);
pDC->SelectObject(pOldPen3);
// duong cheo phu
CPen pen4(PS_SOLID, 10, RGB(rand()%255,rand()%255,rand()%255));
CPen *pOldPen4 = pDC->SelectObject(&pen4);
pDC->MoveTo(250, 50);
pDC->LineTo(50, 250);
pDC->SelectObject(pOldPen4);
// release object when it is no longer in use
f.DeleteObject();
pen.DeleteObject();
pen2.DeleteObject();
pen3.DeleteObject();
pen4.DeleteObject();
}