Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi problem mit handle (https://www.delphipraxis.net/35446-problem-mit-handle.html)

delphi_newbie_123 7. Dez 2004 12:35


problem mit handle
 
hi ich lade alle aktiven tasks in eine kombobox.
beim auswählen wird der name des tasks in die variable anwendung geschrieben
Delphi-Quellcode:
var
  i: Integer;
  hWindowHandle: HWND;
  Buffer: array[0..255] of char;
  sTitle: string;
begin
  WindowList := TList.Create;
  EnumWindows(@GetWindow, 0);
  for i := 0 to WindowList.Count - 1 do
  begin
    hWindowHandle := HWND(WindowList[i]);
    if IsWindowVisible(hWindowHandle) then
    begin
      GetWindowText(hWindowHandle, Buffer, SizeOf(Buffer) - 1);
      if Buffer[0] <> #0 then
      begin
        sTitle := Copy(StrPas(Buffer), 1, 500);
      end;
      if length(stitle)>0 then
      Form1.combobox1.Items.Add(stitle);
    end;
  end;
end;
nun will ich den handle dieses einen fensters rausbekommen, das man ausgewählt hat.

Delphi-Quellcode:
Var Wnd:HWnd;
begin


  Wnd:=FindWindow(anwendung, NIL);
  If Wnd>0 Then Begin
    SetForegroundWindow(Wnd);
    SetForegroundWindow(Handle);
  End;

end;
doch der code will nicht geparsed werden. anwendung ist ein string, ist das richtig?
mach ich irgendetwas falsch?
danke euch schonmal :dp:

Pr0g 7. Dez 2004 12:41

Re: problem mit handle
 
Der Parameter erwartet einen "PAnsiChar", daher musst du es so machen:
Delphi-Quellcode:
Wnd := FindWindow(PChar(anwendung), NIL);
MfG Pr0g

Sprint 7. Dez 2004 12:55

Re: problem mit handle
 
Zitat:

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;

delphi_newbie_123 7. Dez 2004 13:15

Re: problem mit handle
 
danke,euch
das wär vielleicht besser aber mit meinem code solte es doch auch gehen?
ich versuchs mal ich danke euch vielmals


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:58 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