![]() |
Re: Vom Form Handle zum Icon
menno, ich verstehs nicht :(
habs wie folgt versucht:
Delphi-Quellcode:
aber es geht nicht, bekomm immer ne AC. ...
var
bitmap : TBitmap; begin bitmap.Handle:= SendMessage(AHandle, WM_GETICON, ICON_BIG, 0); ImageList1.Add(bitmap,bitmap); bitmap.Free; end; AHandle muss schon das handle eines fensters sein, oder? MfG - Ghost007 //Edit: oder wie kann ich mit dem code von luke, die erstellte bitmap in ein image laden bzw. in einer imagelist speichern? MfG - Ghost007 |
Re: Vom Form Handle zum Icon
Ein Icon-Handle an ein TBitmap zuweisen?
Ich würd erstmal TIcon nehmen ;) |
Re: Vom Form Handle zum Icon
also,
ich verwende folgenden code um alle geöffneten programme und deren titel auszulesen. Der code funktioniert auch gut, aber das mit dem icon auslesen bekomm ich nicht hin ... bekomm ständig ne access violation ... :(
Delphi-Quellcode:
MfG - Ghost007
function EnumWin(hWnd: THandle; FirstWnd: PCardinal): Boolean; stdcall;
var WinText: AnsiString; ProcId : cardinal; icon : Ticon; begin Result := True; if IsWindowVisible(hwnd) then begin if (GetWindowLong(hwnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) <> 0 then hwnd:= GetWindowLong(hWnd, GWL_HWNDPARENT); ProcId := GetWindowThreadProcessID(hWnd, nil); SetLength(WinText, SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0)); SendMessage(hWnd, WM_GETTEXT, Length(WinText) + 1, integer(WinText)); if (length(WinText) > 0) and (FirstWnd^ <> ProcId) then begin Form1.ListBox1.Items.Add(WinText); icon.Handle:=SendMessage(hWnd, WM_GETICON, ICON_BIG, 0); Form1.ImageList1.AddIcon(icon); icon.Free; end; FirstWnd^ := ProcId; end; end; procedure TForm1.Button1Click(Sender: TObject); var FirstWnd : cardinal; begin ListBox1.Clear; EnumWindows(@EnumWin, cardinal(@FirstWnd)); end; P.S.Help me :wall: |
Re: Vom Form Handle zum Icon
Hast du nicht ein
Delphi-Quellcode:
vergessen?
Icon := TIcon.Create
[edit]Ich kriegs nämlich auch nicht hin. Als Bitmap ist es 0x0 Pixel groß und als Icon kommt danach immer ein Fehler ("ungültiges Symbol") Ich benötige das nämlich auch gerade :-D [edit] |
Re: Vom Form Handle zum Icon
omg ich n*** ^^ stimmt, mit icon := TIcon.Create; gehts ...
jetzt sind also die icons in der imagelist. hab grad schonmal in der onlinehilfe guggt, aber wie komm ich jetzt an die icons? und wie wandel ich se in bitmaps um? MfG - Ghost007 |
Re: Vom Form Handle zum Icon
Icon in Bitmap umwandeln:
Delphi-Quellcode:
--> ungetestet
bmp.Assign(NIL); //löschen
bmp.height := ico.height; bmp.width := ico.width; bmp.Draw(0,0,ico);
Delphi-Quellcode:
geht ja leider nicht.
bmp.Assign(ico)
|
Re: Vom Form Handle zum Icon
Liste der Anhänge anzeigen (Anzahl: 1)
hm,
wie mir grade auffällt, schlägt die abfrage manchmal fehlt, dann liefert die funktion, welche das handle der icons liefern soll, den wert 0, und die bitmap wird weiß ... kann des an dem ICON_BIG bzw. ICON_SMALL liegen? MfG - Ghost007 [EDIT] hier der erweiterte code um das letzte ermittelte icon als bitmap darzustellen
Delphi-Quellcode:
Wie kann es nun aber sein, das manche Applicationen als iconhandle 0 zurück liefern?
function EnumWin(hWnd: THandle; FirstWnd: PCardinal): Boolean; stdcall;
var WinText: AnsiString; ProcId : cardinal; icon : Ticon; bmp : Tbitmap; begin Icon := TIcon.Create; bmp := TBitmap.Create; Result := True; if IsWindowVisible(hwnd) then begin if (GetWindowLong(hwnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) <> 0 then hwnd:= GetWindowLong(hWnd, GWL_HWNDPARENT); ProcId := GetWindowThreadProcessID(hWnd, nil); SetLength(WinText, SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0)); SendMessage(hWnd, WM_GETTEXT, Length(WinText) + 1, integer(WinText)); if (length(WinText) > 0) and (FirstWnd^ <> ProcId) then begin Form1.ListBox1.Items.Add(WinText); Form1.handle.Items.Add(IntToStr(hWnd)); Form1.ListBox2.Items.Add(IntToStr(SendMessage(hWnd, WM_GETICON, ICON_BIG, 0))); icon.Handle:=SendMessage(hWnd, WM_GETICON, ICON_BIG, 0); if icon.Handle <> 0 then begin Form1.ImageList1.AddIcon(icon); bmp.Assign(NIL); //löschen bmp.height := icon.height; bmp.width := icon.width; bmp.Canvas.Draw(0,0,icon); Form1.Image2.Picture.Bitmap:=bmp; end; icon.Free; end; FirstWnd^ := ProcId; end; end; procedure TForm1.Button1Click(Sender: TObject); var FirstWnd : cardinal; begin ListBox1.Clear; EnumWindows(@EnumWin, cardinal(@FirstWnd)); end; Ich hab schon getestet, bei den applicationen (z.B. Winamp) ist es egal ob man ICON_BIG oder ICON_SMALL aufruft ... [/EDIT] [EDIT] im anhang sieht man die ausgabe des obigen codes ... wie kann es sein, das ich als icon handle 0 bekomme ... bzw. wie komm ich dann an die icons? [/EDIT] |
Re: Vom Form Handle zum Icon
Hi,
kannst ja mal versuchen ob es so
Delphi-Quellcode:
anders ist.
icon.Handle := SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
if icon.Handle = 0 then icon.Handle := GetClassLong(hWnd, GCL_HICON); |
Re: Vom Form Handle zum Icon
sehr schön, danke :)
funktioniert perfekt :) MfG - Ghost007 |
Re: Vom Form Handle zum Icon
Brauchst du dazu nicht
![]() ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:57 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz