简体   繁体   中英

Adding ICO file to Win32 program

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.

我建议使用ResEdit ,它是用于编辑资源的非常强大的工具。

Assuming your file name is right, probable cause has it that you need to #include <windows.h> before including resources.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 the include 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM