Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi [DELPHI 2010] EnumWindows mit Handle (https://www.delphipraxis.net/147240-%5Bdelphi-2010%5D-enumwindows-mit-handle.html)

DarkItachi 4. Feb 2010 15:18

Re: [DELPHI 2010] EnumWindows mit Handle
 
Ok, nun habe ich selbstständig versucht, das in einer ListView umzusetzen!

function EnumWinProc(Wnd: THandle; LParam: LongInt): Boolean; stdcall;
var
WinCaption : string;
Len: integer;
i : TListItem;
begin
Result := True;
Len := GetWindowTextLength(Wnd);
SetLength(WinCaption, Len);
GetWindowText(Wnd, PChar(WinCaption), Len+1);
if Trim(WinCaption) <> '' then begin
i:= Form1.ListView1.Items.Add;
i.Caption:= WinCaption;
i.SubItems.add(inttostr(Wnd));
end;
end;

Funktioniert natürlich nicht, ist ja klar :?

1. Spalte: Fenstername
2. Spalte: Handle

Wie muss ich mein Code umsetzen?

Oder muss ich das ganz anders machen mit irgendwas wie
Delphi-Quellcode:
for I:= 0 to WindowCount do begin
oder sowas?

himitsu 4. Feb 2010 15:33

Re: [DELPHI 2010] EnumWindows mit Handle
 
Hast du den Code eigentlich verstanden?

Zitat:

Delphi-Quellcode:
function EnumWindowsProc(wHandle: HWND; lb: TListBox): Bool; stdcall;

heißt eigentlich

Delphi-Quellcode:
function EnumWindowsProc(wHandle: HWND; LParam: LongInt): Bool; stdcall;
Wobei LParam das LParam aus dem Aufruf von EnumWindows enthält


Code:
EnumWindows(@EnumWindowsProc, [color=#ff0000]LongInt(ListBox1)[/color]);


function EnumWindowsProc(wHandle: HWND; [color=#ff0000]LParam: LongInt[/color]): LongBool; stdcall;
begin
  [color=#ff0000]TListView(LParam)[/color].Item.Add
Also, alles was du per LParam übergibst, hast du somit auch in der Prozedur
und mußt es einfach nur zurückcasten.
(Wobei man hierbei auch mal den Prozedurrumpf anpassen könnte, so wie es in der Demo gemacht wurde

Sowas wie Form1.ListView1 verursacht nur mehr Verwirrung und erzeugt fehleranfälligeren Code.



PS: Boolean (1 Byte) <> BOOL (4 Byte)


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:38 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz