Jump to content
  • Advertisement
Sign in to follow this  
BloodLust666

LoadIcon

This topic is 4888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Load the icon with a call to LoadImage.
WNDCLASS WndClass;
//...
WndClass.hIcon = reinterpret_cast<HICON>(LoadImage(
NULL, "filename.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE));
The icon should be destroyed when there are no windows or window classes that uses it anymore. This can be done with a call to DestroyIcon. It is automatically destroyed when the application terminates.

Share this post


Link to post
Share on other sites
ok, i changed it so it's now:
wc.hIcon = reinterpret_cast<HICON>(LoadImage(0, (LPCTSTR)m_Icon, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE));

but when i compile, the icon is still the default and there's no icon on the window... is there something else wrong?

Share this post


Link to post
Share on other sites
Check the return value of LoadImage. If it fails, it will return NULL. In that case, call GetLastError() to find out what went wrong.

Share this post


Link to post
Share on other sites
Icon = LoadImage(0, (LPCTSTR)m_Icon, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
DWORD Error = GetLastError();

Error is 2. what's that mean?

Share this post


Link to post
Share on other sites
Use this to translate it:

char buffer[256];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),buffer,256,0);
MessageBox(hwnd,buffer,"Error",MB_OK|MB_ICONERROR);

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilKnuckles666
it says "The handle is invalid"... why??


Your handle of the instance is '0', thus it will load an OEM image. Your application contains the image that you want to load.

hinst

Identifies an instance of the module that contains the image to be loaded. To load an OEM image, set this parameter to zero.

lpszName

Identifies the image to load.

If the hinst parameter is non-NULL and the fuLoad parameter does not include LR_LOADFROMFILE,
lpszName is a pointer to a null-terminated string that contains the name of the image resource in the hinst module.

If hinst is NULL and LR_LOADFROMFILE is not specified, the low-order word of this parameter must be the identifier of the OEM image to load.
The OEM image identifiers are defined in WINUSER.H and have the following prefixes:




Try changing the '0' to GetModuleHandle(NULL) and see if that works.

Share this post


Link to post
Share on other sites
ok, it worked now. but how do i get it so the display icon is the icon i want. like when i would run an actual game and it has it's own icon. know what i mean?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!