Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#27

Re: Fenster-Icon aus hWnd ermitteln

  Alt 22. Jun 2005, 20:13
Und hier die Delphi Umsetzung:

Delphi-Quellcode:
const
  ICON_SMALL2 = 2;

function get_window_icon_small(hwnd: HWND): HICON;
var
  Icon: HICON;
begin
  Icon := 0;
  SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, DWORD(Icon));

  if Icon = 0 then
    SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, DWORD(Icon));

  if Icon = 0 then
    SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, DWORD(Icon));

  if Icon = 0 then
    Icon := HICON(GetClassLong(hwnd, GCL_HICONSM));

  if Icon = 0 then
    Icon := HICON(GetClassLong(hwnd, GCL_HICON));

  if Icon = 0 then
    SendMessageTimeout(hwnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, DWORD(Icon));

  Result := Icon;
end;


function get_window_icon_big(hwnd: HWND; allow_from_class: Boolean): HICON;
var
  Icon: HICON;
begin
  Icon := 0;
  SendMessageTimeout(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, DWORD(Icon));

  if Icon = 0 then
    SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, DWORD(Icon));

  if Icon = 0 then
    SendMessageTimeout(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, DWORD(Icon));

  if allow_from_class then
  begin
    if Icon = 0 then
      Icon := HICON(GetClassLong(hwnd, GCL_HICON));

    if Icon = 0 then
      Icon := HICON(GetClassLong(hwnd, GCL_HICONSM));
  end;

  if Icon = 0 then
    SendMessageTimeout(hwnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, DWORD(Icon));

  Result := Icon;
end;
Angehängte Dateien
Dateityp: zip getwindowicon_993.zip (265,5 KB, 15x aufgerufen)
Thomas
  Mit Zitat antworten Zitat