I can't load my own icon for my window

Dec 29, 2015 at 7:56am
Ok so i was able to successfuly make my own window and so now im trying to load my own icon to the window so that it will appear in upper left corner but I can't figure out how to do it I have tried this

winClass.hIcon = LoadIcon(hInstance, "C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");

and

winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"));

but it won't work help me out plz?
Dec 29, 2015 at 9:56am
LoadIcon load an icon from the executable file so you have to use a resource file.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648072%28v=vs.85%29.aspx
http://www.winprog.org/tutorial/resources.html
Dec 29, 2015 at 6:40pm
That didnt help any when i did what that tutorial said it just kept underlining my IDI_MyIcon in red no matter what i did, I added #include "resource.h" and everything nothing i did worked
Dec 29, 2015 at 6:44pm
btw i am using Visual Studio 2013
Dec 29, 2015 at 7:51pm
closed account (E0p9LyTq)
JPeg files don't work as icons, you will have to convert the jpeg into an icon file.

http://smallbusiness.chron.com/create-icon-file-jpg-54591.html

The LoadIcon() function has been superseded, you should use LoadImage().

LoadImage() will allow you to load a cursor, icon or bitmap from a file, it won't work with jpegs.
Dec 30, 2015 at 2:38am
Ok so i was able to convert an image i wanted to use to a .ico file and i got it put in Resource Files and this is what i put in

winClass.hIcon = (HICON)LoadImage(NULL, L"DominiStudios_Icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);

and the window icon stays the same EVERY TIME it wont change
Dec 30, 2015 at 3:27am
closed account (E0p9LyTq)
If you are loading an icon as a resource you do NOT use LR_LOADFROMFILE.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045%28v=vs.85%29.aspx

If I use an icon as a resource I first define the resource:

resource.rc
TheIcon ICON icon.ico

And then load it from the resource:
wc.hIcon = (HICON) LoadImage(hInstance, L"TheIcon", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);

--------------

Or I create an ordinal to define the icon resource:

resource.h
#define IDI_ICON 1001

resource.rc
IDI_ICON ICON "icon.ico"

and then load the icon
wc.hIcon = (HICON) LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
Dec 30, 2015 at 3:32am
closed account (E0p9LyTq)
If you want to load your icon from a file:
wc.hIcon = (HICON) LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);

Personally I prefer to just create a resource and load from the resource so you don't have to worry where the icon file is located when the program runs.
Dec 30, 2015 at 5:36am
OMG how r u doing this!!?? whenever i do the "TheIcon ICON icon.ico" stuff it gets underlined in red and the program wont run
Dec 30, 2015 at 5:41am
:O sry i found the problem lol i typed something in wrong #troubleshooting skillz xD
Topic archived. No new replies allowed.