使用对话框窗口上的图标C ++ Win32 API [英] Using an icon on a dialog box window 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屋!