Autor Beitrag
masteroffinalfantasy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 11:48 
Moin :)

Ich bin gerade dabei mich ein bisschen mit Handles etc ausseinander zu setzten. Nur leider fällt mir partout nicht ein wie ich aus einer Listbox, wo der Handle Name gespeichert ist, den wieder in eine hwnd variable bekomme...

Also ich hab folgende Funktion:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function EnumWinProc(Wnd: THandle; LParam: LongInt): Boolean; stdcall;
var
 WinCaption : string;
 Len: integer;

begin
 Result := True;
 Len := GetWindowTextLength(Wnd);
 SetLength(WinCaption, Len);
 GetWindowText(Wnd, PChar(WinCaption), Len+1);
 if Trim(WinCaption) <> ''
 then begin
      Form2.Listbox1.Items.Add(Format('%.6x : %s', [Wnd, WinCaption]));
      end;
end;


Die Items in Listbox1 werden dann so in die Listbox 2 übertragen...

ausblenden Delphi-Quelltext
1:
Listbox2.Items.Add(Format('%.6x : %s', [Listbox1.Items.Strings[Listbox1.ItemIndex]]))					


Dann soll folgende Procedur aufgerufen werden
ausblenden Delphi-Quelltext
1:
2:
3:
4:
 procedure SetWindowPosToFront(process:HWND);
begin
  SetWindowPos(process,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;


da wollte ich über einen Timer dynamisch die Items aus der Listbox auslesen und dann die Procedur aufrufen

So weit :D
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 12:24 
Moin!

Pack doch in die .Objects[] das Handle binär rein. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 12:28 
user profile iconNarses hat folgendes geschrieben:
Moin!

Pack doch in die .Objects[] das Handle binär rein. :idea: ;)

cu
Narses


There are 10 types of people - those who understand binary and those who don´t.

Ich gehör zur zweiten Gruppe T_T
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 12:37 
Moin!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function EnumWinProc(Wnd: THandle; LParam: LongInt): Boolean; stdcall;
  var
    WinCaption : string;
    Len: integer;
begin
  Result := True;
  Len := GetWindowTextLength(Wnd);
  SetLength(WinCaption, Len);
  GetWindowText(Wnd, PChar(WinCaption), Len+1);
  if (Trim(WinCaption) <> '') then
    Form2.Listbox1.Items.AddObject(Format('%.6x : %s', [Wnd, WinCaption]),TObject(Wnd));
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 12:44 
Ach so meinst das.

Dann geht aber der Aufruf nicht...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
process:=Listbox2.Items.Objects[counter];
SetWindowPosToFront(process);
[..]
 procedure SetWindowPosToFront(process:HWND);
begin
  SetWindowPos(process,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 12:55 
Moin!

user profile iconmasteroffinalfantasy hat folgendes geschrieben:
Die Items in Listbox1 werden dann so in die Listbox 2 übertragen...
ausblenden Delphi-Quelltext
1:
Listbox2.Items.Add(Format('%.6x : %s', [Listbox1.Items.Strings[Listbox1.ItemIndex]]));					

Du kopierst die Objects so auch nicht mit; probier mal:
ausblenden Delphi-Quelltext
1:
Listbox2.Items.Assign(Listbox1.Items);					

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 13:04 
hmm das problem ist, das die aufgerufenen Prozedur ein HWND will, aus der Listbox aber ein TObject rauskommt...

(btw danke das du dich dem problem überhaupt annimmst)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 13:07 
Moin!

Dann machst du halt einen Cast auf HWND... :roll: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 13:13 
omg ich bin zu doof :D

also ich will die zwei prozeduren aufrufen lassen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 procedure SetWindowPosToFront(process:HWND);
begin
  SetWindowPos(process,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;

procedure SetWindowPosToBack(process:HWND);
begin
  SetWindowPos(process,HWND_NOTOPMOST,0,0,0,0,SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWinProc, 0);
end;


und zwar damit :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm2.Timer1Timer(Sender: TObject);
var counter:integer;
begin

if counter>0 then SetWindowPosToBack(process);
counter:=counter+1;
process:=Listbox2.Items.Objects[counter];
SetWindowPosToFront(process);

end;


und wo soll ich was "casten"?^^
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 13:22 
Moin!

ausblenden Delphi-Quelltext
1:
process := HWND(Listbox2.Items.Objects[counter]);					

Hast du doch beim Einfügen per .AddObject auch gemacht, nur eben "andersrum". :P

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 13:34 
user profile iconNarses hat folgendes geschrieben:
Moin!

ausblenden Delphi-Quelltext
1:
process := HWND(Listbox2.Items.Objects[counter]);					

Hast du doch beim Einfügen per .AddObject auch gemacht, nur eben "andersrum". :P

cu
Narses


^^ ja ich werd noch ganz kirre mit den ganzen HWND und OBJECTS und haste nicht gesehen XD

so mal testen^^

EDIT:

Scheint zu funktionieren n1^^

Wenn du mir jetzt noch erklärst wie ich die Einträge von Listbox1 zu Listbox2 einzeln rüberbekomme bist du mein Held^^ (naja bist ja eh jetzt schon :P )
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 13:49 
Moin!

user profile iconNarses hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
Form2.Listbox1.Items.AddObject(Format('%.6x : %s', [Wnd, WinCaption]),TObject(Wnd));					

user profile iconmasteroffinalfantasy hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
Listbox2.Items.Add(Format('%.6x : %s', [Listbox1.Items.Strings[Listbox1.ItemIndex]]));					

Was fällt dir auf... :les: :roll: :P

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 13:55 
Ich nehm mal an du meinst ich soll das analog machen^^

also dann

ausblenden Delphi-Quelltext
1:
Listbox2.Items.AddObject(Listbox1.Items.Objects[Listbox1.ItemIndex]));					


aber der will da strings ^^
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 14:20 
Moin!

Aaaalso... :roll:
DOH hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
function AddObject(const S: string; AObject: TObject): Integer;					

Das hier ist das aktuell markierte Object aus Listbox1:
ausblenden Delphi-Quelltext
1:
Listbox1.Items.Objects[Listbox1.ItemIndex]);					

Und das hier der Text dazu:
ausblenden Delphi-Quelltext
1:
Listbox1.Items.Strings[Listbox1.ItemIndex]);					

Was schätzt du denn, wie dann der .AddObject-Aufruf für Listbox2 aussehen muss, hm? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 14:28 
^^
so?
ausblenden Delphi-Quelltext
1:
Form2.Listbox2.Items.AddObject(Listbox1.Items.Strings[Listbox1.ItemIndex],Listbox1.Items.Objects[Listbox1.ItemIndex]);					
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 31.05.07 14:29 
Moin!

Hast du´s denn nicht probiert? :mahn: :?:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
masteroffinalfantasy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Win XP
Delphi 2005 Architect
BeitragVerfasst: Do 31.05.07 14:32 
doch gerade eben :)

Danke dir vielmals!