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

查看:215
本文介绍了在对话框窗口中使用图标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天全站免登陆