/************************************************************************* * ExtractAssociatedIconW (SHELL32.@) * * Return icon for given file (either from file itself or from associated * executable) and patch parameters if needed. */ HICON WINAPI ExtractAssociatedIconW(HINSTANCE hInst, LPWSTR lpIconPath, LPWORD lpiIcon) { HICON hIcon = NULL; WORD wDummyIcon = 0; TRACE("%p %s %p\n", hInst, debugstr_w(lpIconPath), lpiIcon); if(lpiIcon == NULL) lpiIcon = &wDummyIcon; hIcon = ExtractIconW(hInst, lpIconPath, *lpiIcon); if( hIcon < (HICON)2 ) { if( hIcon == (HICON)1 ) /* no icons found in given file */ { WCHAR tempPath[MAX_PATH]; HINSTANCE uRet = FindExecutableW(lpIconPath,NULL,tempPath); if( uRet > (HINSTANCE)32 && tempPath[0] ) { lstrcpyW(lpIconPath,tempPath); hIcon = ExtractIconW(hInst, lpIconPath, *lpiIcon); if( hIcon > (HICON)2 ) return hIcon; } } if( hIcon == (HICON)1 ) *lpiIcon = 2; /* MSDOS icon - we found .exe but no icons in it */ else *lpiIcon = 6; /* generic icon - found nothing */ if (GetModuleFileNameW(hInst, lpIconPath, MAX_PATH)) hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(*lpiIcon)); } return hIcon; }
/************************************************************************* * ExtractIconA [SHELL32.@] */ HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex) { HICON ret; INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0); LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex); MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len); ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex); HeapFree(GetProcessHeap(), 0, lpwstrFile); return ret; }