取画刷(HBrush)的6种方法
2008-09-02 23:58
155 查看
HBRUSH hbr;
第一种: hbr= CreateSolidBrush(RGB(255,0,0)); //单色的画刷
第二种: hbr= (HBRUSH)GetStockObject(BLACK_BRUSH); //只能取特定颜色的画刷,如BLACK_BRUSH,GRAY_BRUSH等刷
第三种: hbr= CreatePatternBrush(HBITMAP hbmp); //得到位图画刷
第四种: hbr = CreateHatchBrush(int fnStyle, COLORREF clrref) //创建一种带阴影的画刷
第五种: hbr= CreateBrushIndirect(LOGBRUSH); //通过LOGBRUSH结构体来取画刷
typedef struct tagLOGBRUSH {
UINT lbStyle; //画刷类型
COLORREF lbColor; //颜色
LONG lbHatch; //阴影
} LOGBRUSH, *PLOGBRUSH;
第六种: hbr= HBRUSH CreateDIBPatternBrush( //通过与设备无关位图创建一个画刷
HGLOBAL hglbDIBPacked, // handle to DIB
UINT fuColorSpec // color table data
);
例如:
HBRUSH CAfdView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID()==IDC_STATIC1)
{
pDC->SetTextColor(RGB(200,0,0));
pDC->SetBkColor(RGB(0,0,255));
static HBRUSH hBrush = CreateSolidBrush(RGB(222,0,255));
return hBrush;
}
// TODO: Return a different brush if the default is not desired
else
return hbr;
}
改变对话框背景色
HBRUSH CDqfDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if(nCtlColor == CTLCOLOR_DLG)
{
CBrush *brush;
brush = new CBrush(RGB(221,221,221));
return (HBRUSH)(brush->m_hObject);
}
return hbr;
}
第一种: hbr= CreateSolidBrush(RGB(255,0,0)); //单色的画刷
第二种: hbr= (HBRUSH)GetStockObject(BLACK_BRUSH); //只能取特定颜色的画刷,如BLACK_BRUSH,GRAY_BRUSH等刷
第三种: hbr= CreatePatternBrush(HBITMAP hbmp); //得到位图画刷
第四种: hbr = CreateHatchBrush(int fnStyle, COLORREF clrref) //创建一种带阴影的画刷
第五种: hbr= CreateBrushIndirect(LOGBRUSH); //通过LOGBRUSH结构体来取画刷
typedef struct tagLOGBRUSH {
UINT lbStyle; //画刷类型
COLORREF lbColor; //颜色
LONG lbHatch; //阴影
} LOGBRUSH, *PLOGBRUSH;
第六种: hbr= HBRUSH CreateDIBPatternBrush( //通过与设备无关位图创建一个画刷
HGLOBAL hglbDIBPacked, // handle to DIB
UINT fuColorSpec // color table data
);
例如:
HBRUSH CAfdView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID()==IDC_STATIC1)
{
pDC->SetTextColor(RGB(200,0,0));
pDC->SetBkColor(RGB(0,0,255));
static HBRUSH hBrush = CreateSolidBrush(RGB(222,0,255));
return hBrush;
}
// TODO: Return a different brush if the default is not desired
else
return hbr;
}
改变对话框背景色
HBRUSH CDqfDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if(nCtlColor == CTLCOLOR_DLG)
{
CBrush *brush;
brush = new CBrush(RGB(221,221,221));
return (HBRUSH)(brush->m_hObject);
}
return hbr;
}
相关文章推荐
- 【转】取画刷(HBrush)的6种方法
- 取画刷(HBrush)的6种方法
- Java读取文件夹大小的6种方法及代码
- ASP.NET 6种常用数据库的连接方法
- ASP.NET 6种常用数据库的连接方法
- 6种方法实现asp.net返回上一页
- 在Spring3中,配置DataSource的方法有6种。
- 爬虫突破封禁的6种常见方法
- [转]-CSS 元素垂直居中的6种方法
- Delphi中让窗口关闭按钮无效的6种方法
- js弹出窗口总结6种弹窗方法
- 在Spring3中,配置DataSource的方法有6种。
- CSS 元素垂直居中的 6种方法
- Shell中判断字符串是否为数字的6种方法分享
- js弹出窗口总结6种弹窗方法
- 在Spring3中,配置DataSource的方法有6种。
- 最大连续子序列和(6种解决方法)
- MySQL分页技术、6种分页方法总结
- JQuery中根据属性或属性值获得元素(6种情况获取方法)
- 教你6种过滤RSS种子信息的方法