更改标题栏图标时如何正确使用loadicon和makeintresource? [英] How do i use loadicon and makeintresource correctly when changing the title bar icon?
问题描述
我正在使用Code:Blocks c ++ win32中的一个项目。我已经在互联网上阅读了LoadIcon和MAKEINTRESOURCE的使用。但是,似乎我没有正确使用它们。我用油漆创建了一个图像并命名为'ico1'。它的格式为'.png'。
当我执行程序时,我在第1行收到错误代码错误:在'1002'中请求成员'png',这是非类型的'int'。
以下是代码。
I am working on a project in Code:Blocks c++ win32. I have read on the internet the use of LoadIcon and MAKEINTRESOURCE. However, it seems I am not using them correctly. I have created an image with paint and named it 'ico1'. It is in the format '.png'.
When I execute the program I get an error code at line 1 "error: request for member 'png' in '1002', which is of non-class type 'int'."
Below is the code.
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (ico1.png, MAKEINTRESOURCE(IDI_ico1));
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_HIGHLIGHTTEXT;
接下来我该怎么办?任何帮助深表感谢。谢谢。
我尝试过:
#define IDI_ico1 1001
#define ico1 1002
/ *使用默认图标和鼠标指针* /
wincl.hIcon = LoadIcon(ico1.png,MAKEINTRESOURCE(IDI_ico1));
wincl.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL,IDC_ARROW) ;
wincl.lpszMenuName = NULL; / *没有菜单* /
wincl.cbClsExtra = 0; / *窗口类后没有额外的字节* /
wincl.cbWndExtra = 0; / *结构或窗口实例* /
/ *使用Windows的默认颜色作为窗口的背景* /
wincl.hbrBackground =(HBRUSH)COLOR_HIGHLIGHTTEXT;
What should I do next? Any help is much appreciated. Thanks.
What I have tried:
#define IDI_ico1 1001
#define ico1 1002
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (ico1.png, MAKEINTRESOURCE(IDI_ico1));
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_HIGHLIGHTTEXT;
推荐答案
LoadIcon功能(Windows) [ ^ ]要求使用Windows图标格式将图像作为资源存储在可执行文件或加载的DLL中。
如果要从文件加载图标,可以使用 LoadImage函数(Windows) [ ^ ],带LR_LOADFROMFILE
。但即使是这个函数也要求文件是Windows图标或位图文件。因此,您必须将PNG文件转换为支持的格式之一。
LoadIcon function (Windows)[^] requires the image to be stored as resource in the executable or a loaded DLL using the Windows icon format.
If you want to load an icon from a file you can use the LoadImage function (Windows)[^] withLR_LOADFROMFILE
. But even this function requires the file to be a Windows icon or bitmap file. So you must convert your PNG file to one of the supported formats.
这篇关于更改标题栏图标时如何正确使用loadicon和makeintresource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!