digitalmars.D.learn - How load icon from resource using LoadImage?
- Marcone (4/4) Jan 05 2020 I am using this code to load icon from local directory, but I
- JN (8/12) Jan 05 2020 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-lo...
- ShadoLight (7/11) Jan 06 2020 Sort of correct... but not strictly correct. Typically the
- Rumbu (7/11) Jan 05 2020 You cannot load icons from res files.
- Marcone (4/16) Jan 05 2020 Very good! working using: LoadIcon(hInstance,
I am using this code to load icon from local directory, but I want to load icon from resource.res file: wndclass.hIcon = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);
Jan 05 2020
On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:I am using this code to load icon from local directory, but I want to load icon from resource.res file: wndclass.hIcon = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagea According to the docs, the first argument is NULL only for standalone images, otherwise you have to provide a valid HINSTANCE. By the way, have you managed to add the res file into the binary? My understanding is that the res file should be added into the exe file by the rc command before it can be used.
Jan 05 2020
On Sunday, 5 January 2020 at 13:52:27 UTC, JN wrote:On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:[snip]By the way, have you managed to add the res file into the binary? My understanding is that the res file should be added into the exe file by the rc command before it can be used.Sort of correct... but not strictly correct. Typically the resource compiler (such as Microsoft's rc.exe) compiles xyzfile.rc into xyzfile.res. xyzfile.res is then added into the exe by the linker during linking.
Jan 06 2020
On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:I am using this code to load icon from local directory, but I want to load icon from resource.res file: wndclass.hIcon = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);You cannot load icons from res files. If you link your res file to the executable, you can load the icon using: LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(youriconid)); The function LoadImage from above loads an icon from the file named icon.ico, not from a res file.
Jan 05 2020
On Sunday, 5 January 2020 at 15:13:17 UTC, Rumbu wrote:On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:Very good! working using: LoadIcon(hInstance, MAKEINTRESOURCE(youriconid)); becouse GetModuleHandle(NULL) is undefined here.I am using this code to load icon from local directory, but I want to load icon from resource.res file: wndclass.hIcon = LoadImage( NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE| LR_SHARED | LR_LOADTRANSPARENT);You cannot load icons from res files. If you link your res file to the executable, you can load the icon using: LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(youriconid)); The function LoadImage from above loads an icon from the file named icon.ico, not from a res file.
Jan 05 2020