将ICO文件添加到Win32程序中
因此在我的项目中添加了一个resource.rc和一个resource.h文件。
resource.rc 具有 #include "resource.h" IDI_MYICON ICON "my_icon.ico"
且 resource.h 具有 #define IDI_MYICON 201
wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wincl.hIconSm = (HICON) LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16 ,0);
我收到编译器错误,读取“[resource错误] my_icon.ico 读取 2440 返回 2439”
我也在自学这个 API。网上有什么好的资源吗? forgers win32 API 教程很好,但解释不多。
So added a resource.rc and a resource.h file to my project.
resource.rc has #include "resource.h" IDI_MYICON ICON "my_icon.ico"
and resource.h has #define IDI_MYICON 201
wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wincl.hIconSm = (HICON) LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16 ,0);
im getting an compiler error reading "[resource error] my_icon.ico read 2440 returned 2439"
also im teaching myself this API. is there any good resources online? the forgers win32 API tutorial is good but doesnt explain much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的文件名正确,可能的原因是您需要在包含
resources.h
之前先#include
。我昨天遇到了这个问题,并得到了相同的错误代码。我还注意到,如果您更改 .rc 并重新编译,似乎每次都会删除#include
行。我猜测我的机器上的include
路径是错误的,并且由于它找不到该文件,因此将其删除。另一个原因是你的图标文件路径错误。如果您将 my_icon.ico 添加为资源,并将其添加到您的项目的
Resources
文件夹下,则您的文件位置应为#include "resource.h" IDI_MYICON ICON "Resources\\my_icon.h" ico"
如果您的 .ico 已损坏(也可能是这样),请尝试使用您知道未损坏的 .ico 并查看其是否有效。
希望你现在已经明白了这一点!祝你好运!
Assuming your file name is right, probable cause has it that you need to
#include <windows.h>
before includingresources.h
. I ran into this problem yesterday and was getting the same error codes. I also noticed that if you change the .rc and recompiled, it seemed like it was deleting the#include <windows.h>
line every time. I'm guessing theinclude
path is wrong on my machine, and since it can't find the file, it removes it.The other reason is your icon file path is wrong. If you added my_icon.ico as a resource and it added to your project under the
Resources
folder, your file location should be#include "resource.h" IDI_MYICON ICON "Resources\\my_icon.ico"
If your .ico is corrupt, which it could be, try using an .ico you know isn't corrupt and see if it works.
Hope you figured this out by now! Good luck!
我建议使用ResEdit,这是一个非常编辑资源的强大工具。
I suggest using ResEdit, It is a very powerful tool for editing resources.