[Win32SDK基本]Static Control(2)Image Static Control
2015-06-24 13:40
381 查看
本文由CSDN用户zuishikonghuan所作,转载请注明出处:/article/9672502.html
上一篇博文([Win32SDK基本]Static Control(1)Text Static Control 和 WM_CTLCOLORSTATIC,地址:/article/9672501.html)中,介绍了Text
Static Control的使用以及利用 WM_CTLCOLORSTATIC 消息修改其前景色和背景色,这篇将介绍 Image Static Control,他可以显示位图或图标
创建子窗口和 Static Control 相关的风格已经在上一篇中详细说了,因此这一篇中不再重复了。但把用到的几个样式再拿出来说一下:
SS_BITMAP:显示一个位图
SS_ICON:显示一个图标(MSDN: If the control is created via CreateWindow or a related function, the text is the name of an icon (not a filename) defined in the resource file associated with the module specified by the hInstance parameter to CreateWindow. 翻译:如果控件通过
CreateWindow 或有相关的函数创建的文本是图标 (而不是文件名) 在与 CreateWindow 的 hInstance 参数所指定的模块关联的资源文件中定义的名称)
SS_REALSIZECONTROL:调整位图以适应静态控件的大小
SS_CENTERIMAGE:位图或图标居中
还是以我的博客“[Win32SDK基本] 窗口详解(超详细)”(地址:/article/9672496.html)为模板,进一步编写。
下面创建一个 Image Static Control
Image Static Control 使用以下消息来控制
STM_GETICON
STM_GETIMAGE
STM_SETICON
STM_SETIMAGE
具体用法很简单而且相似,可以参见MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ff486029(v=vs.85).aspx
下面以 STM_SETIMAGE 为例给 Image Static Control 设置一个图标
在窗口回调函数中添加
以前从来没有注意过,因为写文章又翻了一次MSDN,惊奇地发现已下一段话:
Important
In version 6 of the Microsoft Win32 controls, a bitmap passed to a static control using the STM_SETIMAGE message was the same bitmap returned by a subsequent STM_SETIMAGE message. The client is responsible to delete any bitmap sent to a static control.
于是才知道用完必须释放,汗啊,以前从来没发现过,于是又百度了一下,发现有前辈也遇到过这个问题,于是我就“拿来主义”了,借鉴了那位前辈:/article/1912615.html
效果图:
注意MSDN说最低支持的系统是Vista,下回有时间装个虚拟机看看XP的情况。
上一篇博文([Win32SDK基本]Static Control(1)Text Static Control 和 WM_CTLCOLORSTATIC,地址:/article/9672501.html)中,介绍了Text
Static Control的使用以及利用 WM_CTLCOLORSTATIC 消息修改其前景色和背景色,这篇将介绍 Image Static Control,他可以显示位图或图标
创建子窗口和 Static Control 相关的风格已经在上一篇中详细说了,因此这一篇中不再重复了。但把用到的几个样式再拿出来说一下:
SS_BITMAP:显示一个位图
SS_ICON:显示一个图标(MSDN: If the control is created via CreateWindow or a related function, the text is the name of an icon (not a filename) defined in the resource file associated with the module specified by the hInstance parameter to CreateWindow. 翻译:如果控件通过
CreateWindow 或有相关的函数创建的文本是图标 (而不是文件名) 在与 CreateWindow 的 hInstance 参数所指定的模块关联的资源文件中定义的名称)
SS_REALSIZECONTROL:调整位图以适应静态控件的大小
SS_CENTERIMAGE:位图或图标居中
还是以我的博客“[Win32SDK基本] 窗口详解(超详细)”(地址:/article/9672496.html)为模板,进一步编写。
下面创建一个 Image Static Control
Image Static Control 使用以下消息来控制
STM_GETICON
STM_GETIMAGE
STM_SETICON
STM_SETIMAGE
具体用法很简单而且相似,可以参见MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ff486029(v=vs.85).aspx
下面以 STM_SETIMAGE 为例给 Image Static Control 设置一个图标
在窗口回调函数中添加
HBITMAP oldimage; HICON hicon;在case WM_CREATE:里添加
static3 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | SS_ICON, 250, 220, 50, 50, hwnd, (HMENU)3, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); hicon = LoadIcon((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), TEXT("ICON_1")); oldimage = (HBITMAP)SendMessage(static3, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hicon); if (oldimage != NULL) { DeleteObject(oldimage); } DeleteObject(hicon);
以前从来没有注意过,因为写文章又翻了一次MSDN,惊奇地发现已下一段话:
Important
In version 6 of the Microsoft Win32 controls, a bitmap passed to a static control using the STM_SETIMAGE message was the same bitmap returned by a subsequent STM_SETIMAGE message. The client is responsible to delete any bitmap sent to a static control.
于是才知道用完必须释放,汗啊,以前从来没发现过,于是又百度了一下,发现有前辈也遇到过这个问题,于是我就“拿来主义”了,借鉴了那位前辈:/article/1912615.html
效果图:
注意MSDN说最低支持的系统是Vista,下回有时间装个虚拟机看看XP的情况。
相关文章推荐
- [一起学Hive]之四-Hive的安装配置
- Java线程面试题 Top 50 (转载)
- int与long long之间的转换
- [转]Linux中设置服务自启动的三种方式
- Makefile
- 织梦5.7下载远程图片和资源无效全套最新解决方案
- MySQL删除存储过程和函数
- iOS开发之打包上传到App Store——(一)各种证书的理解
- 加密技术在信息安全领域的重要作用
- [NOIP2008] 笨小猴
- cocoapods安装与使用
- 启动Tomcat时报Caused by: java.lang.ClassNotFoundException: FilterConfig异常
- the assignment of reading paper
- 我要阻止做java开发的男朋友去创业型公司工作吗?
- 功率W与dBm的对照表及关系(转)
- MIT python 第二课最后一个例子 求整数的平方数
- 基于html5 canvas 的客户端异步上传图片的插件,支持客户端压缩图片尺寸
- android back键实现home键效果
- 数据窗口打印详解
- HTML5梦幻星空,可用作网页背景