/**************************************************************************** * * FUNCTION: GetIconFromInstance * * PURPOSE: Callback for enumerating resources in a DLL/EXE * * PARAMS: HINSTANCE hInstance - Instance handle for this module * LPTSTR nIndex - Resource index * * RETURNS: HICON - Handle to the icon, NULL for failure * * History: * July '95 - Created * \****************************************************************************/ HICON GetIconFromInstance( HINSTANCE hInstance, LPTSTR nIndex ) { HICON hIcon = NULL; HRSRC hRsrc = NULL; HGLOBAL hGlobal = NULL; LPVOID lpRes = NULL; int nID; // Find the group icon if( (hRsrc = FindResource( hInstance, nIndex, RT_GROUP_ICON )) == NULL ) return NULL; if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL ) return NULL; if( (lpRes = LockResource(hGlobal)) == NULL ) return NULL; // Find this particular image nID = LookupIconIdFromDirectory( lpRes, TRUE ); if( (hRsrc = FindResource( hInstance, MAKEINTRESOURCE(nID), RT_ICON )) == NULL ) return NULL; if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL ) return NULL; if( (lpRes = LockResource(hGlobal)) == NULL ) return NULL; // Let the OS make us an icon hIcon = CreateIconFromResource( lpRes, SizeofResource(hInstance,hRsrc), TRUE, 0x00030000 ); return hIcon; }
HICON LoadLocalizedIcon(const UINT iconId) { LANGID langId = GetGUILanguage(); /* find group icon resource */ HRSRC res = FindResourceLang(RT_GROUP_ICON, MAKEINTRESOURCE(iconId), langId); if (res == NULL) return NULL; HGLOBAL resInfo = LoadResource(o.hInstance, res); if (resInfo == NULL) return NULL; int id = LookupIconIdFromDirectory(resInfo, TRUE); if (id == 0) return NULL; /* find the actual icon */ res = FindResourceLang(RT_ICON, MAKEINTRESOURCE(id), langId); if (res == NULL) return NULL; resInfo = LoadResource(o.hInstance, res); if (resInfo == NULL) return NULL; DWORD resSize = SizeofResource(o.hInstance, res); if (resSize == 0) return NULL; return CreateIconFromResource(resInfo, resSize, TRUE, 0x30000); }
static HICON LoadLocalizedIconEx(const UINT iconId, int cxDesired, int cyDesired) { LANGID langId = GetGUILanguage(); HICON hIcon = (HICON) LoadImage (o.hInstance, MAKEINTRESOURCE(iconId), IMAGE_ICON, cxDesired, cyDesired, LR_DEFAULTSIZE|LR_SHARED); if (hIcon) return hIcon; else PrintDebug (L"Loading icon using LoadImage failed."); /* Fallback to CreateIconFromResource which always scales * from the first image in the resource */ /* find group icon resource */ HRSRC res = FindResourceLang(RT_GROUP_ICON, MAKEINTRESOURCE(iconId), langId); if (res == NULL) return NULL; HGLOBAL resInfo = LoadResource(o.hInstance, res); if (resInfo == NULL) return NULL; int id = LookupIconIdFromDirectory(resInfo, TRUE); if (id == 0) return NULL; /* find the actual icon */ res = FindResourceLang(RT_ICON, MAKEINTRESOURCE(id), langId); if (res == NULL) return NULL; resInfo = LoadResource(o.hInstance, res); if (resInfo == NULL) return NULL; DWORD resSize = SizeofResource(o.hInstance, res); if (resSize == 0) return NULL; /* Note: this uses the first icon in the resource and scales it */ hIcon = CreateIconFromResourceEx(resInfo, resSize, TRUE, 0x30000, cxDesired, cyDesired, LR_DEFAULTSIZE|LR_SHARED); return hIcon; }