Autor Beitrag
Insignificant
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 12:56 
Hi....ich bin dabei ne Taskleiste zu machen aber stoße auf ein großes Problem: Wie bekomme ich den richtigen Sender heraus.

Ich habe erstelle
ausblenden Delphi-Quelltext
1:
 Blabel[i] := TLabel.Create(nil);					

und möchte nun, beim das sich beim OnClick auch das passende Fenster dazu öffnet.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.TaskClick(Sender: TObject);
var
  hdl: HWND;
begin
  hdl := FensterInfo[TLabel(Sender).Tag].Handle;
  if IsIconic(hdl) then
    ShowWindow(hdl, SW_RESTORE) else
    BringWindowToTop(hdl);
end;


aber irgendwie funktioniert das nicht. Da nicht der richtige Sender übertragen wird.....

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 13:02 
Du übergibst ja auch weder Parent noch Owner. Sonst könntest du ja mit (Sender as TComponent).Owner auf das Formualr schlie0en können.

ausblenden Delphi-Quelltext
1:
Blabel[i] := TLabel.Create( self);					

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 13:11 
Nene, das ist so nicht ganz richtig. Ich setze den Parent, aber erst was später.

ausblenden Delphi-Quelltext
1:
2:
3:
Blabel[i] := TLabel.Create(nil);
      with  Blabel[i] do begin
        Parent := Form1;


ich wollte nur nicht alles hier kopieren, ansonsten wirds irgendwann zu unübersichtlich hier ^^

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 13:15 
Den Owner ab nicht, und der ist im Normalfall die Form.

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 13:36 
Aber auch nachdem ich diese gesetzt habe, funktioniert es nicht.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 13:39 
Was funktiniert nicht. Wenn du beim Erzeugen den Owner setzt, kannst du ihn einfach abfragen und mußt nicht den Tag misbrauchen.

BTW. schon gesehen das es hier im Forum möglich ist Tabs (z.B.
 das ist delphi Code;)
zu verwenden?

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 13:49 
Ja das mit dem Delphi-Code weiss ich, nur ich finds immer so umständlich *g*

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.TaskClick(Sender: TObject); 
var 
hdl: HWND; 
begin 
hdl := FensterInfo[TLabel(Sender).Tag].Handle; 
if IsIconic(hdl) then 
ShowWindow(hdl, SW_RESTORE) else 
BringWindowToTop(hdl); 
end;


In wiefern muss ich denn dann
hdl := FensterInfo[TLabel(Sender).Tag].Handle; das nun ändern?! weil du meinst ja ich muss den Tag nicht mehr misbrauchen?!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 13:54 
TComponent aht eine Eigenschaft .Owner. Diese kann beim Erzeugen gesetzt werden z.B.
ausblenden Delphi-Quelltext
1:
Blabel[i] := TLabel.Create( self);					

Wobei self eine Referenz auf die aktuelle Form ist und auch durch Form1 ersetzt werden kann.
Dann kannst du in einem Event mit
ausblenden Delphi-Quelltext
1:
((Sender as TComponent).Owner as TForm)					

direkt auf die Form zugreifen.

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 14:01 
Und wie kann ich dem Sender nun das passende Handle zu weisen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.TaskClick(Sender: TObject); 
var 
hdl: HWND; 
begin 
hdl := FensterInfo[TLabel(Sender).Tag].Handle; 
if IsIconic(hdl) then 
ShowWindow(hdl, SW_RESTORE) else 
BringWindowToTop(hdl); 
end;


Ich möchte ja, das wenn man das Label anklickt, das passende Fenster geöffnet wird, was ja nicht geht da ja nicht der richtige Sender übertragen wird.
Ich versteh jetzt nur nicht, wie mir((Sender as TComponent).Owner as TForm) in Bezug auf das Handle weiterhilft. Ich meine man kann dem da so ja kein Handle mehr zuweisen oô?!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 14:07 
ausblenden Delphi-Quelltext
1:
((Sender as TComponent).Owner as TForm).Handle					

oder
ausblenden Delphi-Quelltext
1:
((Sender as TComponent).Owner as TForm).BringToFront					

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 14:16 
Achso. Jetzt hab ichs kapiert.

Aber das Problem ist ja, dass das Blabel, also der Sender, ja gar nicht das Handle besitzt. Es 'leiht' sich das Handle ja von FensterInfo.

FensterInfo[TLabel(Sender).Tag].Handle; (FensterInfo[High(FensterInfo)].Handle:=Wnd;)

((Sender as TComponent).Owner as TForm).Handle das würd ja nur funktionieren wenn Bable das Handle hätte?!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 14:19 
Zitat:
das würd ja nur funktionieren wenn Bable das Handle hätte?!
Nein das handle stammt vom Owner nicht vom Label.

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 14:26 
Huh? Wie jetzt? :gruebel:

Das bringt mir ja überhaupt nichts wenn ich das handle vom Owner nehme, da der Owner, in dem Fall die Form, ja gar nicht das Handle besitzt, sondern das array, FensterInfo, ja das handle von allen Fenstern hat.
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Sa 27.05.06 14:35 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var handles : array of hwnd;
    labels : array of TLabel;
oncreate:
  for i := 1 to 10 do begin
   setlength(labels, i);
   setlength(handles, i);
   labels[i-1] := tlabel.create(nil);
   labels[i-1].parent := form1;
   labels[i-1].tag := i-1;
   labels[i-1].OnClick := form1.OnClick;
   handles[i-1] := HWND_BROADCAST;
  end;
onClick:
  if (sender.tag >= 0) and (sender.tag < length(handles)) then
    showwindow(handles[ sender.tag], SW_SHOW );


so sollte das gehen (ungetestet)
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 15:44 
Wirklich verstehen tu ich das nicht. Kompilieren kann ich es auch nicht.
"Undefinierter Bezeichner für tag"

Kann man nicht einfach nen Mix aus

hdl := FensterInfo[TLabel(Sender).Tag].Handle;

und

((Sender as TComponent).Owner as TForm).Handle

machen?

Es ist ja so. Jeden Blabel der erstellt wird, entspricht ja auch aus den FensterInfo array.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
    for i := 0 to Length(FensterInfo) - 1 do begin
      Blabel[i] := TLabel.Create(self);
      with  Blabel[i] do begin
        Parent := Form1;
             Enabled := true;
             AutoSize := false;
             Caption := FensterInfo[i].Caption;

etc.

Ich dachte eigentlich einfach nur so. Beispielsweise Blabel[1] bekommt dann auch von Fensterinfo den handle [1] irgendwie?
So wird es ja bei den Caption die ich ja auslese und die ja auch funktionieren auch gemacht. Blabel[i] bekommt von FensterInfo den passenden Caption.
Caption := FensterInfo[i].Caption;
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 27.05.06 16:16 
Was steht den alles in Fensterinfo drin?

_________________
Markus Kinzler.
Insignificant Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Sa 27.05.06 16:27 
Das hier ist mal die komplette funktion

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function EnumWinProc(Wnd: THandle; LParam: LongInt): Boolean; stdcall;
var
 WinCaption : string;
 Len: integer;
begin
 Result := True;
  If IsWindowVisible(Wnd) and
     ((GetWindowLong(Wnd, GWL_HWNDPARENT)=0) or
      (HWND(GetWindowLong(Wnd, GWL_HWNDPARENT))=GetDesktopWindow)) and
     ((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW)=0)
  then
begin
 Len := GetWindowTextLength(Wnd);
 SetLength(WinCaption, Len);
 GetWindowText(Wnd, PChar(WinCaption), Len+1);

 SetLength(WinCaption, Len);
 SetLength(FensterInfo, length(FensterInfo)+1);
    inc(lengthvar);
    FensterInfo[High(FensterInfo)].Caption:=WinCaption;
    FensterInfo[High(FensterInfo)].Handle:=Wnd;

 if Trim(WinCaption) <> '' then
   Form1.Listbox1.Items.Add(Format('%.6x : %s', [Wnd, WinCaption]));

end;
end;


Moderiert von user profile iconjasocul: Delphi-Tags hinzugefügt
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 27.05.06 17:07 
user profile iconInsignificant hat folgendes geschrieben:
Ja das mit dem Delphi-Code weiss ich, nur ich finds immer so umständlich *g*

Hallo Insignificant,
du magst das ja umständlich finden, aber weißt du, was wirklich umständlich ist?
1. Deinen unformatierten Delphi-Source zu lesen.
2. Dass die Moderatoren jedesmal die Delphi-Tags für dich nacharbeiten.
Ich bitte dich daher, die zwei Maus-Cicks fortan selbstständig durchzuführen.
Beste Grüße,
Peter