Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.12.31;
Скачать: CL | DM;

Вниз

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

 
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 вся ветка

Текущий архив: 2006.12.31;
Скачать: CL | DM;

Наверх




Память: 0.5 MB
Время: 0.047 c
2-1165735440
intel
2006-12-10 10:24
2006.12.31
Здравствуйте


3-1161246824
X_ksandr_X
2006-10-19 12:33
2006.12.31
помогите плиз с DBGrid


2-1165681703
atas-sheriff
2006-12-09 19:28
2006.12.31
ClientSocket


15-1164872146
pkm
2006-11-30 10:35
2006.12.31
Сцена на новый год


2-1165786800
Евгений Р.
2006-12-11 00:40
2006.12.31
Присвоить значение свойству Set