this slowpoke moves

List all Windows

Beispiel 1:
function EnumWinProc(Wnd: THandle; LParam: LongInt): Boolean; stdcall;
var
  WinCaption : string;
  Len: integer;
begin
  Result := True;
  Len := GetWindowTextLength(Wnd);
  SetLength(WinCaption, Len);
  GetWindowText(Wnd, PChar(WinCaption), Len+1);
  if Trim(WinCaption) <> '' then
    Form1.Listbox1.Items.Add(Format('%.6x : %s', [Wnd, WinCaption]));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
	EnumWindows(@EnumWinProc, 0);
end;
Beispiel 2:
type
  PMyEnumParam = ^TMyEnumParam;
  TMyEnumParam = record
    lb: TListbox;
  end;
  
//

function GetWindows(const hWnd: Longword; Param: PMyEnumParam): LongBool;
  stdcall;
var
  Len: Longint;
  S: string;
begin
  Result := True;
  if not (IsWindow(hWnd) and IsWindowVisible(hWnd)) then
    Exit;
  Len := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0);
  if Len > 0 then
  begin
    SetLength(S, Len);
    SendMessage(hWnd, WM_GETTEXT, Len + 1, Longint(Pchar(S)));
    Param.lb.Items.Add(s);
  end;
  // mit Result = False kann die Callbackfunktion vorzeitig verlassen werden
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Param: TMyEnumParam;
begin
  Param.lb := Listbox1;
  EnumWindows(@GetWindows, LPARAM(@Param));
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate