Windows API一日一练(25)CreateSolidBrush函数
来源:互联网 发布:武装突袭3优化 编辑:程序博客网 时间:2024/06/05 01:52
当你看到Windows显示的按钮时,背景颜色是灰色的。当你看到缺省的窗口背景时,它是白色的。当你的老板需要你创建一个黑色背景的按钮时,你会怎么样做呢?其实在Windows里先用API函数CreateSolidBrush创建画刷,然后调用FillRect函数来填充背景。这样来,不管你需要什么样的背景,都随心所欲了吧。现在先来搞懂CreateSolidBrush函数,下次再来练习FillRect。
函数CreateSolidBrush声明如下:
WINGDIAPI HBRUSH WINAPI CreateSolidBrush( __in COLORREF color);
color是画刷颜色。
调用这个函数的例子如下:
#001 //
#002 //界面显示输出.
#003 //
#004 //蔡军生 2007/08/29 QQ:9073204 深圳
#005 //
#006 void CCaiWinMsg::OnDraw(HDC hDC)
#007 {
#008 //
#009 std::wstring strShow(_T("C++窗口类的实现,2007-08-27"));
#010
#011 //设置输出字符串的颜色.
#012 COLORREF crOld = SetTextColor(hDC,RGB(255,0,0));
#013
#014 RECT rcText;
#015 rcText.left = 10;
#016 rcText.top = 30;
#017 rcText.right = 300;
#018 rcText.bottom = 80;
#019
#020 //创建黑色的画刷,
#021 HBRUSH hbrush = CreateSolidBrush(RGB(0, 0, 0));
#022
#023 //用黑色的画刷填充四边形的颜色.
#024 FillRect(hDC,&rcText,hbrush);
#025
#026 //删除画刷.
#027 DeleteObject(hbrush);
#028
#029 //显示字符串在四边形的中间位置.
#030 DrawText(hDC,strShow.c_str(),(int)strShow.length(),&rcText,
#031 DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
#032
#033 //恢复原来的颜色.
#034 SetTextColor(hDC,crOld);
#035 }
第21行是创建黑色的画刷。它的效果图如下:
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- Windows API一日一练(25)CreateSolidBrush函数
- LCC编译器的源程序分析(69)全局变量的初始化
- 微软宣布将发布.NET Framework Library源代码
- 从Decorator,Adapter模式看Java/IO库(三)
- 正态分布的随机数发生器 in C#
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- Windows API一日一练(25)CreateSolidBrush函数
- 走近Silverlight - 微软Silverlight上海开发团队Blog第二篇
- SystemC 初始化步骤
- Windows API一日一练(24)DrawText函数
- 从Decorator,Adapter模式看Java/IO库(二)
- SystemC——一套将C++扩展为硬件描述语言的Class Library (初学SystemC有感)
- .NET中的幕后英雄:MSCOREE.DLL
- Windows API一日一练(23)SetTextColor函数
- Asp.net 2.0 自定义控件开发[实现GridView多行表头固定表体滚动效果][示例代码下载]