Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > Вытащить иконку из exe


Автор: ip127001 22.9.2007, 18:32
как? Помогите советом...
если можно то пример кода если есть..если нет то функцию...

Автор: zkv 22.9.2007, 19:02
Цитата(MSDN)

Extracting Icons from Executable Files
An application can use the ExtractIcon function to retrieve the handle to an icon from a specified executable file, dynamic-link library (DLL), or icon file. The following example uses the DragQueryPoint function to retrieve the coordinates of the point where a file was dropped, the DragQueryFile function to retrieve the file name of a dropped file, and the ExtractIcon function to retrieve the handle to the first icon in the file, if any. 

Hide Example

POINT pt; 
WORD cFiles; 
HDC hdc; 
char lpszFile[80]; 
HANDLE hCurrentInst, hicon; 

DragQueryPoint((HANDLE) wParam, &pt); 

cFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, NULL, NULL); 

if(cFiles > 1) 

    TextOut(hdc, pt.x, pt.y, "Please drop only one icon file.", 31); 
    return FALSE; 

else 

    DragQueryFile((HANDLE) wParam, 0, lpszFile, 
                  sizeof(lpszFile)/sizeof(TCHAR)); 
    hCurrentInst = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE); 
    hicon = ExtractIcon(hCurrentInst, lpszFile, 0); 
    if (hicon == NULL) 
        TextOut(hdc, pt.x, pt.y, "No icons found.", 15); 
    else if (hicon == (HICON) 1) 
        TextOut(hdc, pt.x, pt.y, "File must be .EXE, .ICO, or .DLL.", 33); 
    else 
        DrawIcon(hdc, pt.x, pt.y, hicon); 


DragFinish((HANDLE) wParam);



Добавлено через 52 секунды
пойдет?

Автор: ip127001 22.9.2007, 19:40
а можно пояснить плз..что и как работает..а то что не очень понятно...

Автор: zkv 22.9.2007, 19:48
все действие в этой строке происходит:
Код

   hicon = ExtractIcon(hCurrentInst, lpszFile, 0); 

передаешь инстанс, имя файла, индекс иконки (она там не одна может быть) и получаешь иконку на выходе. 
Вот и весь секрет smile
http://msdn2.microsoft.com/en-us/library/ms648068.aspx
не забудь удалить только потом, когда не нужна иконка будет.

Автор: ip127001 22.9.2007, 20:01
как я понял мы получаем указатель на эту иконку...а как ее преобразовать в изображение ..на пр. в bmp

Автор: zkv 22.9.2007, 21:23
ip127001, посмотри http://forum.vingrad.ru/articles/topic-157904.html  не уверен, что точно по теме, посмотришь. 
И пользуйся МСДНом и поиском, удачи!  smile 

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