Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Иконки...


maxistent ©   (2006-08-24 11:47:00) 

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


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

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


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

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


Ketmar   (2006-08-24 23:52:00) [3]

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


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

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


Ketmar   (2006-08-24 23:22:00) [5]

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


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

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


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

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


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

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


maxistent   (2006-08-24 14:25:00) [9]


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

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


DVM   (2006-08-24 13:34:00) [10]

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

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


DprYg   (2006-08-24 12:49:00) [11]

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


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

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


clickmaker   (2006-08-24 11:54:00) [13]

ExtractIcon


Наверх

Титульная страница Поиск, карта сайта Написать письмо