Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C++ Builder > Как получить иконку из EXE


Автор: azesmcar 11.5.2005, 08:06
Здравствуйте...понадобилось тут пробежаться по EXE файлам, загрузить их иконки в TImageList...

Кто нибудь знает как это делаеться???

Заранее спасибо

Автор: Guest 11.5.2005, 09:17
Нашёл в Windows SDK пару функций:
1) Извлечение иконки
Цитата

The ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.

HICON ExtractIcon(

    HINSTANCE hInst, // instance handle
    LPCTSTR lpszExeFileName, // filename of file with icon
    UINT nIconIndex  // index of icon to extract
  );


Parameters

hInst

Identifies the instance of the application calling the function.

lpszExeFileName

Points to a null-terminated string specifying the name of an executable file, DLL, or icon file.

nIconIndex

Specifies the index of the icon to retrieve. If this value is 0, the function returns the handle of the first icon in the specified file. If this value is -1, the function returns the total number of icons in the specified file.



Return Values

If the function succeeds, the return value is the handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If no icons were found in the file, the return value is NULL.

2) "Расширенная" версия функции smile
Цитата

The ExtractIconEx function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.

HICON ExtractIconEx(

    LPCSTR lpszFile,
    int nIconIndex,
    HICON FAR * phiconLarge,
    HICON FAR * phiconSmall,
    UINT nIcons 
  );


Parameters

lpszFile

Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file.

nIconIndex

Specifies the index of the icon to retrieve. If this value is 0, the function returns the handle of the first icon in the specified file. If this value is -1 and phIconLargeand phiconSmall are both NULL, the function returns the total number of icons in the specified file.

phiconLarge

Pointer to an array of handles of large icons returned. This parameter can be NULL.

phiconSmall

Pointer to an array of handles of small icons returned. This parameter can be NULL.

nIcons

Specifies the count of the number of icons to extract.



Return Values

If the function succeeds, the return value is the handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return value is 1. If no icons were found in the file, the return value is NULL.


Вот только, вероятно, придётся какой-нибудь header подключить (а какой - не знаю smile ). Насколько я помню, в Delphi функция ExtractIcon была импортирована в модуле ShellAPI, так что вероятно и в C++ Builder'е будет какой-нибудь заголовок с похожим названием.

Обе эти функции находятся в shell32.dll и имеют имена ExtractIconA и ExtractIconExA соответственно, поэтому, если что - то ты можешь импортировать их самостоятельно. smile

Автор: drinkOut 11.5.2005, 09:20
Упс, забыл подписаться и запостил ответ - sorry! smile

Автор: azesmcar 11.5.2005, 09:28
Спасибо...я тут тоже кое что накопал...функция SHGetFileInfo...работает вполне нормально, как для файлов, так и для ярлыков и директорий...вот работающий код если кому понадобится
Код

   TSHFileInfo sfInfo;
   SHGetFileInfo( Path.c_str(), 0, &sfInfo, sizeof(sfInfo), SHGFI_ICON );
   TIcon *pIcon = new TIcon();
   pIcon->Handle = sfInfo.hIcon;
   ImageList1->AddIcon(pIcon);
   delete pIcon;

Автор: drinkOut 11.5.2005, 15:31
Хороший способ. smile

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)