[Win32SDK基本]Static Control(2)Image Static Control
来源:互联网 发布:新开淘宝店铺没生意 编辑:程序博客网 时间:2024/05/17 09:13
上一篇博文([Win32SDK基本]Static Control(1)Text Static Control 和 WM_CTLCOLORSTATIC,地址:http://blog.csdn.net/zuishikonghuan/article/details/46604945)中,介绍了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基本] 窗口详解(超详细)”(地址:http://blog.csdn.net/zuishikonghuan/article/details/46378475)为模板,进一步编写。
下面创建一个 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.
于是才知道用完必须释放,汗啊,以前从来没发现过,于是又百度了一下,发现有前辈也遇到过这个问题,于是我就“拿来主义”了,借鉴了那位前辈:http://blog.csdn.net/whitehack/article/details/6443369
效果图:
注意MSDN说最低支持的系统是Vista,下回有时间装个虚拟机看看XP的情况。
- [Win32SDK基本]Static Control(2)Image Static Control
- [Win32SDK基本]Static Control(1)Text Static Control 和 WM_CTLCOLORSTATIC
- [Win32SDK基本]Button Control(2)Check Boxes
- [Win32SDK基本]Edit Control详解
- [Win32SDK基本]Button Control(1)Push Button 和 BM_SETIMAGE
- [Win32SDK基本]Button Control(3)Group Boxes
- [Win32SDK基本]Button Control(4)Radio Buttons
- Static LED control - CDigiStatic 1.3
- set bitmap to static control
- 访问控制(access control)及final、static关键字
- MFC控件之Text Control(Static Text)
- Static control 透明,重影,长度问题
- Polymorphism, class member access control, static method/field
- MFC学习笔记——static text 和 picture control
- MFC中设置Edit Control 和 Static Text控件学习
- how to implement the version control of static files
- "",IDC_FRAME,"Static",SS_BLACKFRAME,226,8,20,20 CONTROL IDB_BACK,IDC_BACK,"Static",SS_
- Control
- cocoapods安装与使用
- [NOIP2008] 笨小猴
- Direct UI 思想阐述
- [一起学Hive]之四-Hive的安装配置
- Java线程面试题 Top 50 (转载)
- [Win32SDK基本]Static Control(2)Image Static Control
- 嵌入式系统学习开发指导
- iOS开发之打包上传到App Store——(二)开发/发布流程
- wince 背光驱动u
- dhroid学习(二)dhroid的fragment的注入问题
- oracle sql日期比较
- [一起学Hive]之五-Hive的视图和分区
- NPAPI插件与JS交互开发详细记录
- 无中生有