LoadIcon

Started by
17 comments, last by EliasAE 18 years, 8 months ago
How do i load an icon from an .ICO file when using the WNDCLASS to define my window?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Advertisement
?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
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.
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?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Check the return value of LoadImage. If it fails, it will return NULL. In that case, call GetLastError() to find out what went wrong.
Icon = LoadImage(0, (LPCTSTR)m_Icon, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
DWORD Error = GetLastError();

Error is 2. what's that mean?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
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);
it says "The handle is invalid"... why??
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
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.
hinstIdentifies an instance of the module that contains the image to be loaded. To load an OEM image, set this parameter to zero. lpszNameIdentifies 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.
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?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML

This topic is closed to new replies.

Advertisement