Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
Delphi 5 Professional
|
Re: problem mit handle
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!"
|