Thema: Delphi problem mit handle

Einzelnen Beitrag anzeigen

Benutzerbild von Sprint
Sprint

Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
 
Delphi 5 Professional
 
#3

Re: problem mit handle

  Alt 7. Dez 2004, 13:55
Zitat von delphi_newbie_123:
nun will ich den handle dieses einen fensters rausbekommen, das man ausgewählt hat.
Warum speicherst du das Handle nicht gleich mit?

Ein Beispiel: Zwei Buttons und eine ComboBox

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);

  function EnumWindowsProc(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
  begin
    TList(lParam).Add(Pointer(hWnd));
    Result := True;
  end;

var
  List: TList;
  S: String;
  I: Integer;
begin
  ComboBox1.Clear;
  List := TList.Create;
  try
    if EnumWindows(@EnumWindowsProc, Longint(List)) then
    begin
      for I := 0 to List.Count - 1 do
      begin
        if IsWindowVisible(Longint(List.Items[I])) then
        begin
          SetLength(S, GetWindowTextLength(Longint(List.Items[I])) + 1);
          SetLength(S, GetWindowText(Longint(List.Items[I]), PChar(S), Length(S)));
          ComboBox1.Items.AddObject(S, List.Items[I]);
        end;
      end;
    end;
  finally
    List.Free;
  end;
end;
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
begin
  SetForegroundWindow(Longint(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
end;
Ciao, Sprint.

"I don't know what I am doing, but I am sure I am having fun!"
  Mit Zitat antworten Zitat