AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

problem mit handle

Ein Thema von delphi_newbie_123 · begonnen am 7. Dez 2004 · letzter Beitrag vom 7. Dez 2004
Antwort Antwort
delphi_newbie_123

Registriert seit: 14. Jan 2004
181 Beiträge
 
Delphi 5 Enterprise
 
#1

problem mit handle

  Alt 7. Dez 2004, 12:35
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
  Mit Zitat antworten Zitat
Benutzerbild von Pr0g
Pr0g

Registriert seit: 21. Mai 2004
809 Beiträge
 
Delphi 7 Personal
 
#2

Re: problem mit handle

  Alt 7. Dez 2004, 12:41
Der Parameter erwartet einen "PAnsiChar", daher musst du es so machen:
Wnd := FindWindow(PChar(anwendung), NIL); MfG Pr0g
  Mit Zitat antworten Zitat
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, 12: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
delphi_newbie_123

Registriert seit: 14. Jan 2004
181 Beiträge
 
Delphi 5 Enterprise
 
#4

Re: problem mit handle

  Alt 7. Dez 2004, 13:15
danke,euch
das wär vielleicht besser aber mit meinem code solte es doch auch gehen?
ich versuchs mal ich danke euch vielmals
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz