本文整理汇总了C++中CBrush::GetSafeHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ CBrush::GetSafeHandle方法的具体用法?C++ CBrush::GetSafeHandle怎么用?C++ CBrush::GetSafeHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBrush
的用法示例。
在下文中一共展示了CBrush::GetSafeHandle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnCtlColor
HBRUSH CExtResizableDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if( nCtlColor == CTLCOLOR_DLG
|| nCtlColor == CTLCOLOR_STATIC
|| nCtlColor == CTLCOLOR_MSGBOX
)
{
if( nCtlColor == CTLCOLOR_STATIC )
pDC->SetBkMode( TRANSPARENT );
static CBrush brBackground;
if( brBackground.GetSafeHandle() == NULL )
{
VERIFY(
brBackground.CreateSolidBrush(
g_PaintManager->GetColor(
CExtPaintManager::CLR_3DFACE_OUT
)
)
);
} // if( brBackground.GetSafeHandle() == NULL )
return (HBRUSH)brBackground.GetSafeHandle();
}
HBRUSH hBrush = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
return hBrush;
}
示例2: GetBitmapFromImageList
BOOL COptionTreeItemImage::GetBitmapFromImageList(CDC *pDC, HICON hIcon, CBitmap &bmp)
{
// Declare varaibles
CDC dc;
CBrush brush;
dc.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, m_sImageSizes.cx, m_sImageSizes.cy);
CBitmap* pOldBmp = dc.SelectObject(&bmp);
brush.CreateSolidBrush(GetSysColor(COLOR_MENU));
::DrawIconEx(dc.GetSafeHdc(), 0, 0, hIcon, m_sImageSizes.cx, m_sImageSizes.cy, 0, (HBRUSH)brush,DI_NORMAL);
// Restore
dc.SelectObject(pOldBmp);
// Delete
if (brush.GetSafeHandle() != NULL)
{
brush.DeleteObject();
}
if (dc.GetSafeHdc() != NULL)
{
dc.DeleteDC();
}
// The icon is not longer needed
DestroyIcon(hIcon);
return TRUE;
}
示例3: CtlColor
HBRUSH CBaseView::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
if( pDC )
{
pDC->SetBkColor( AfxGetProfile().GetColor(CColorClass::clrBaseBK) );
pDC->SetTextColor( AfxGetProfile().GetColor(CColorClass::clrBaseText) );
}
static CBrush brushBK;
static COLORREF clrBKLast = RGB(255,255,255);
COLORREF clrBKNow = AfxGetProfile().GetColor( CColorClass::clrBaseBK );
if( NULL == brushBK.GetSafeHandle() || clrBKLast != clrBKNow )
{
brushBK.DeleteObject( );
VERIFY( brushBK.CreateSolidBrush( clrBKNow ) );
}
clrBKLast = clrBKNow;
return (HBRUSH)brushBK.GetSafeHandle();
}
示例4: OnCtlColor
HBRUSH CWizardView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if( nCtlColor == CTLCOLOR_DLG
|| nCtlColor == CTLCOLOR_STATIC
|| nCtlColor == CTLCOLOR_MSGBOX )
{
if( nCtlColor == CTLCOLOR_STATIC )
pDC->SetBkMode( TRANSPARENT );
static CBrush brushBK;
static COLORREF clrBKLast = RGB(255,255,255);
COLORREF clrBKNow = RGB(255,255,255);
if( NULL == brushBK.GetSafeHandle() || clrBKLast != clrBKNow )
{
brushBK.DeleteObject( );
VERIFY( brushBK.CreateSolidBrush( clrBKNow ) );
}
clrBKLast = clrBKNow;
return (HBRUSH)brushBK.GetSafeHandle();
}
return CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
}
示例5: OnDrawItem
void CDiaColorD::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CBrush brush;
if(lpDrawItemStruct->CtlID==IDC_COLORON){
brush.CreateSolidBrush(m_ColorOn);
}else{
brush.CreateSolidBrush(m_ColorOff);
}
CPen pen;
pen.CreateStockObject(NULL_PEN);
HPEN hOldPen=(HPEN)SelectObject(lpDrawItemStruct->hDC,pen.GetSafeHandle());
HBRUSH hOldBrush=(HBRUSH)SelectObject(lpDrawItemStruct->hDC,brush.GetSafeHandle());
Rectangle(lpDrawItemStruct->hDC,0,0,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
SelectObject(lpDrawItemStruct->hDC,hOldBrush);
SelectObject(lpDrawItemStruct->hDC,hOldPen);
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
示例6: DrawControl
void COptionTreeItemColor::DrawControl(CDC *pDC, const RECT &rcRect)
{
// Declare variables
HGDIOBJ hOld;
HGDIOBJ hOldBrush;
COLORREF crOld;
int nOldBack;
CRect rcText, rcColor, rcClient;
CString strText;
CBrush bBrush;
COLORREF crOldBack;
// Get window rect
GetClientRect(rcClient);
// Select font
hOld = pDC->SelectObject(m_otOption->GetNormalFont());
// Create bush
bBrush.CreateSolidBrush(m_crColor);
// Set text color
if (IsReadOnly() == TRUE || m_otOption->IsWindowEnabled() == FALSE)
{
crOld = pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
}
else
{
crOld = pDC->SetTextColor(GetTextColor());
}
// Set background color
crOldBack = pDC->SetBkColor(GetBackgroundColor());
// Set background mode
nOldBack = pDC->SetBkMode(TRANSPARENT);
// Select brush
hOldBrush = pDC->SelectObject(GetSysColorBrush(COLOR_BTNSHADOW));
// Get color rectangle
rcColor.left = rcRect.left + 1;
rcColor.right = rcColor.left + (long) OT_COLOR_SIZE;
rcColor.top = rcRect.top + OT_SPACE - 2;
rcColor.bottom = rcColor.top + (long) OT_COLOR_SIZE;
// Draw color border
rcColor.InflateRect(1, 1, 1, 1);
pDC->PatBlt(rcColor.left, rcColor.top, rcColor.Width(), rcColor.Height(), PATCOPY);
// Draw color
rcColor.DeflateRect(1, 1, 1, 1);
pDC->FillRect(rcColor, &bBrush);
// Get text rectangle
rcText.left = rcColor.right + OT_SPACE;
rcText.right = rcRect.right;
rcText.top = rcRect.top;
rcText.bottom = rcRect.bottom;
// Get text
if (GetOption(OT_COLOR_SHOWHEX) == TRUE)
{
strText.Format(_T("#%.6X"), m_crColor);
}
else
{
strText.Format(_T("RGB (%d, %d, %d)"), GetRValue(m_crColor), GetGValue(m_crColor), GetBValue(m_crColor));
}
// Draw text
pDC->DrawText(strText, rcText, DT_SINGLELINE | DT_VCENTER);
pDC->DrawText(strText, rcText, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT);
// Delete brush
if (bBrush.GetSafeHandle() != NULL)
{
bBrush.DeleteObject();
}
// Restore GDI ojects
pDC->SelectObject(hOldBrush);
pDC->SelectObject(hOld);
pDC->SetTextColor(crOld);
pDC->SetBkMode(nOldBack);
pDC->SetBkColor(crOldBack);
}