Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2006.12.31;
Скачать: [xml.tar.bz2];

Вниз

Иконки...   Найти похожие ветки 

 
maxistent ©   (2006-08-24 11:47) [0]

Всем привет! Подскажите, как получать иконки окон?
Окна типа Дельфи, Тотал Коммоньдер, Диспетчер задач и т.д.
Я пробовал получать иконки с помощью
Icon.Handle:=GetClassLong(wnd, GCL_HICONSM),
но это не всегда срабатывало, т.е. иногда функция возвращала абсолютный ноль по Цельсию :-(
Что могёте посоветовать?


 
clickmaker ©   (2006-08-24 11:54) [1]

ExtractIcon


 
maxistent ©   (2006-08-24 12:41) [2]

Ну? А дальше-то что?


 
DprYg ©   (2006-08-24 12:49) [3]

Дальше хэлп юзать надо:
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.


 
DVM ©   (2006-08-24 13:34) [4]

Вот комплект моих трех функций, которые помогут вытащить иконку любого окна.

uses   Tlhelp32, PSAPI;
........
//------------------------------------------------------------------------------

function _GetFileAssociatedIcon(FileName: string; bSmall: boolean): HICON;
var
 FileInfo: SHFILEINFO;
 BIG_OR_SMALL_ICON: integer;
begin
 if bSmall then
   BIG_OR_SMALL_ICON := SHGFI_SMALLICON
 else
   BIG_OR_SMALL_ICON := SHGFI_LARGEICON;
 SHGetFileInfo(PChar(FileName),
               FILE_ATTRIBUTE_NORMAL,
               FileInfo,
               SizeOf(FileInfo),
               SHGFI_ICON or BIG_OR_SMALL_ICON or SHGFI_SYSICONINDEX);
 Result := FileInfo.hIcon;
end;

//------------------------------------------------------------------------------

function _GetProcessFileNameByWindowHandle(Wnd: HWND): string;
var
 hProcess: THandle;
 PID: Cardinal;
 FileName: array [1..MAX_PATH] of char;
 PE: TProcessEntry32;
 Snap: Cardinal;
 OsVerInfo: TOSVersionInfo;
begin
 Result := "";
 GetWindowThreadProcessId(Wnd, @PID);
 hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
 OsVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
 if GetVersionEx(osVerInfo) then
   begin
     if OsVerInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
       begin
         ZeroMemory(@Filename[1], SizeOf(Filename));
         GetModuleFileNameEx(hProcess, 0, @Filename[1], SizeOf(Filename));
         Result := FileName;
       end
     else
       begin
         Snap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
         if Snap <> -1 then
           begin
             PE.dwSize:=SizeOf(PE);
             if Process32First(Snap, PE) then
               repeat
                 if PE.th32ProcessID = PID then Result := PE.szExeFile;
               until not Process32Next(Snap, PE);
           end;
       end;
   end;
 CloseHandle(hProcess);
end;

//------------------------------------------------------------------------------

function GetIconFromWindow(hWnd: HWND): HICON; stdcall;
const
 ICON_SMALL2 = 2;
begin
 Result := 0;
 // Get Small Icon From Window ...
 SendMessageTimeout(hWnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then SendMessageTimeout(hWnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then Result := GetClassLong(hWnd, GCL_HICONSM);
 if Result = 0 then SendMessageTimeout(hWnd, WM_GETICON, ICON_SMALL, 1,
                        SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then SendMessageTimeout(hWnd, WM_GETICON, ICON_SMALL2, 1,
                        SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then SendMessageTimeout(hWnd, WM_QUERYDRAGICON, ICON_SMALL,
                        0, SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then SendMessageTimeout(hWnd, WM_QUERYDRAGICON, ICON_SMALL2,
                       0, SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 // Get Big Icon From Window ...
 if Result = 0 then SendMessageTimeout(hWnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then Result := GetClassLong(hWnd, GCL_HICON);
 if Result = 0 then SendMessageTimeout(hWnd, WM_GETICON, ICON_BIG, 1,
                      SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 if Result = 0 then SendMessageTimeout(hWnd, WM_QUERYDRAGICON, ICON_BIG,
                      0, SMTO_ABORTIFHUNG, 1000, Cardinal(Result));
 // Get Icon From File ...
 if Result = 0 then Result := _GetFileAssociatedIcon(_GetProcessFileNameByWindowHandle(hWnd), true);
 if Result = 0 then Result := _GetFileAssociatedIcon(_GetProcessFileNameByWindowHandle(hWnd), false);
 // Load Default Icon ...  }
 if Result = 0 then Result := LoadIcon(0, IDI_APPLICATION);
end; // End of function GetIconFromWindow



 
maxistent ©   (2006-08-24 14:25) [5]


> DVM ©   (24.08.06 13:34) [4]

Спасибо! Вроде бы работает...


 
LBVF   (2006-08-24 23:11) [6]

Сегодня случайно возился с иконками, написал прогу, так она вытягивает
иконки с *.exe и *.dll. Могу дать исходник.


 
Ketmar ©   (2006-08-24 23:12) [7]

> [6] LBVF   (24.08.06 23:11)
чисто случайно нашёл в справке ExtractIcon()?


 
LBVF   (2006-08-24 23:18) [8]

Совершенно верно! Но и не только.


 
Ketmar ©   (2006-08-24 23:22) [9]

> [8] LBVF   (24.08.06 23:18)
впрочем, тоже полезное упражнение. всяко лучше медиаплееров. %-)


 
LBVF   (2006-08-24 23:46) [10]

Тогда  выложи свой код на эту тему. Пускай другие учатся.


 
Ketmar ©   (2006-08-24 23:52) [11]

> [10] LBVF   (24.08.06 23:46)
я почти никогда не выкладываю готовый код.


 
LBVF   (2006-08-25 00:31) [12]

Что за причина этому?


 
Ketmar ©   (2006-08-25 00:38) [13]

> [12] LBVF   (25.08.06 00:31)
лучше один раз написать свой код, чем сто раз увидеть чужой. я могу лишь подсказать направление, в котором надо копать. не более.



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2006.12.31;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.042 c
6-1154973628
ZeroXider
2006-08-07 22:00
2006.12.31
Пример port mapping


2-1166106304
webpauk
2006-12-14 17:25
2006.12.31
Записи


5-1145509871
Lanc
2006-04-20 09:11
2006.12.31
Как определить предка?


2-1165829964
Baisak
2006-12-11 12:39
2006.12.31
Работа с БД


2-1165954437
sat
2006-12-12 23:13
2006.12.31
Abstract Error





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский