LoadIcon
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?
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?
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?
DWORD Error = GetLastError();
Error is 2. what's that mean?
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);
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement