![]() |
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:
nun will ich den handle dieses einen fensters rausbekommen, das man ausgewählt hat.
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;
Delphi-Quellcode:
doch der code will nicht geparsed werden. anwendung ist ein string, ist das richtig?
Var Wnd:HWnd;
begin Wnd:=FindWindow(anwendung, NIL); If Wnd>0 Then Begin SetForegroundWindow(Wnd); SetForegroundWindow(Handle); End; end; mach ich irgendetwas falsch? danke euch schonmal :dp: |
Re: problem mit handle
Der Parameter erwartet einen "PAnsiChar", daher musst du es so machen:
Delphi-Quellcode:
MfG Pr0g
Wnd := FindWindow(PChar(anwendung), NIL);
|
Re: problem mit handle
Zitat:
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; |
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