Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Vom Form Handle zum Icon (https://www.delphipraxis.net/76019-vom-form-handle-zum-icon.html)

ghost007 15. Mai 2007 18:15

Re: Vom Form Handle zum Icon
 
menno, ich verstehs nicht :(
habs wie folgt versucht:

Delphi-Quellcode:
var
  bitmap : TBitmap;
begin
 bitmap.Handle:= SendMessage(AHandle, WM_GETICON, ICON_BIG, 0);
 ImageList1.Add(bitmap,bitmap);
 bitmap.Free;
end;
aber es geht nicht, bekomm immer ne AC. ...
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

CCRDude 15. Mai 2007 18:48

Re: Vom Form Handle zum Icon
 
Ein Icon-Handle an ein TBitmap zuweisen?
Ich würd erstmal TIcon nehmen ;)

ghost007 15. Mai 2007 19:01

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:
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;
MfG - Ghost007

P.S.Help me :wall:

halinchen 15. Mai 2007 19:02

Re: Vom Form Handle zum Icon
 
Hast du nicht ein
Delphi-Quellcode:
Icon := TIcon.Create
vergessen?

[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]

ghost007 15. Mai 2007 19:12

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

halinchen 15. Mai 2007 19:15

Re: Vom Form Handle zum Icon
 
Icon in Bitmap umwandeln:
Delphi-Quellcode:
bmp.Assign(NIL); //löschen
bmp.height := ico.height;
bmp.width := ico.width;
bmp.Draw(0,0,ico);
--> ungetestet

Delphi-Quellcode:
bmp.Assign(ico)
geht ja leider nicht.

ghost007 15. Mai 2007 19:42

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:
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;
Wie kann es nun aber sein, das manche Applicationen als iconhandle 0 zurück liefern?
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]

bitsetter 15. Mai 2007 20:22

Re: Vom Form Handle zum Icon
 
Hi,

kannst ja mal versuchen ob es so
Delphi-Quellcode:
icon.Handle := SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
if icon.Handle = 0 then
  icon.Handle := GetClassLong(hWnd, GCL_HICON);
anders ist.

ghost007 15. Mai 2007 20:45

Re: Vom Form Handle zum Icon
 
sehr schön, danke :)
funktioniert perfekt :)

MfG - Ghost007

Mackhack 15. Mai 2007 21:37

Re: Vom Form Handle zum Icon
 
Brauchst du dazu nicht MSDN-Library durchsuchenExtractIcon oder MSDN-Library durchsuchenExtractIconEx??? Du uebergibst der Funktion den Index der Icons die du haben willst und schwupps hast du alle da!


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:57 Uhr.
Seite 2 von 3     12 3      

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