在对话框窗口上使用图标 C++ Win32 API [英] Using an icon on a dialog box window C++ Win32 API

查看:29
本文介绍了在对话框窗口上使用图标 C++ Win32 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个像这样顶部带有图标的对话框.

I am trying to create a dialog box with an icon at the top like so.

我正在使用资源文件来加载图标.

I am using a resource file to load the icon like so.

IDI_ICON1          ICON           ".\\usb.ico"

我尝试使用以下代码设置窗口图标.

I have tried setting the window icon using the following code.

SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)IDI_ICON1);
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)IDI_ICON1);

hwnd 是窗口.结果,我得到一个蓝色圆圈,看起来就像 Windows 7 和 Vista 的加载图标.我几乎肯定图标被正确加载,因为当我查看任务栏时,我的程序有代表我的程序的图标.如果您需要我用于对话框窗口本身的代码,请告诉我我会发布它.我在 Windows 7 上使用 mingw32 C++ 编译器.谢谢!

hwnd is the window. As a result, I get a blue circle that looks just like the loading icon for Windows 7 and Vista. I am almost positive the icon is being loaded correctly as when I look at the task bar, my program has that icon representing my program. If you need the code I am using for the dialog window itself, let me know I will post it. I am using mingw32 C++ compiler on Windows 7. Thanks!

推荐答案

使用 LoadIcon 并将图标句柄传递给 WM_SETICON.

Use LoadIcon and pass an icon handle to WM_SETICON.

HICON hicon = LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDI_ICONMAIN), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
SendMessageW(hwnd, WM_SETICON, ICON_BIG, hicon);

这篇关于在对话框窗口上使用图标 C++ Win32 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆