使用对话框窗口 C++ 上的图标Win32 API
我正在尝试创建一个顶部带有图标的对话框,如下所示。
我正在使用资源文件来加载图标,如下所示。
IDI_ICON1 ICON ".\\usb.ico"
我尝试使用以下代码设置窗口图标。
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++ 编译器。谢谢!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 LoadIcon 并将图标句柄传递给 WM_SETICON。
Use LoadIcon and pass an icon handle to WM_SETICON.
我必须将
LoadImageW()
的返回值转换为HICON
,以避免错误:这对我有用:
这是结果
仅供参考:使用的图标是从以下位置下载的:
http://www.iconsdb.com/orange-icons/stackoverflow-6-icon .html
希望有帮助!
I had to cast the return value of
LoadImageW()
toHICON
, to avoid the error :this worked for me :
and here is the result
FYI: the used icon was downloaded from :
http://www.iconsdb.com/orange-icons/stackoverflow-6-icon.html
Hope that helps !
虽然已经三年了。我想为此添加另一个解决方案。我已经在 Visual Studio 2017 上尝试过此操作。
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
SendMessage(WM_SETICON, ICON_BIG, (LPARAM)m_hIcon);
Even though it's three years. I would like to add another solution to this. I have tried this on Visual Studio 2017.
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
SendMessage(WM_SETICON, ICON_BIG, (LPARAM)m_hIcon);