Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi SystemTray - TNA erweitert! (https://www.delphipraxis.net/51646-systemtray-tna-erweitert.html)

axellang 16. Aug 2005 18:22

Re: SystemTray - TNA erweitert!
 
Hallo Leute,

das ließ mir einfach keine Ruhe, nun bin ich schlauer.
Ein Anfang:

Code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StaticText1: TStaticText;
    procedure Button1Click(Sender: TObject);
    procedure StaticText1Click(Sender: TObject);
    procedure ReplaceSystemClock;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
ReplaceSystemClock;
end;

procedure TForm1.ReplaceSystemClock;
var
// We need this for calc'ing the size of the System Tray Window
Rect: TRect;
TaskbarHwnd, TrayHwnd: HWND;
begin
// First we'll find the taskbar
TaskbarHwnd := FindWindow('Shell_TrayWnd',nil);

// Next the Tray Window
TrayHwnd := FindWindowEx(TaskbarHwnd,0,'TrayNotifyWnd',nil);

// Now we need the Rect. of the Tray window so we can
// position the TStatictext somewhat accurately
GetWindowRect(TrayHwnd,Rect);

// Right Justify is recommended because the text will
//otherwise extend beyond the TrayWindow bounds

StaticText1.Alignment := taRightJustify;

// Change the borderstyle to single so we can see if its positioned properly
StaticText1.BorderStyle := sbsSingle;

// Reposition it so it covers the System Clock
StaticText1.Left := (Rect.Right - Rect.Left) - StaticText1.Width - 3;
StaticText1.Top := 2;
StaticText1.Font.Name := 'Tahoma';

// Disable this, or StaticText1 will move around when you change the text
StaticText1.AutoSize := FALSE;

// Now comes the interesting part: we shift the Statictext1's parent to the Traywindow

Windows.SetParent(StaticText1.Handle,TrayHwnd);

// Even though Statictext1 changed owner, we can still manipulate
// it like it were in our own form! Which is a great advantage. }
StaticText1.Caption := 'Test';
end;

procedure TForm1.StaticText1Click(Sender: TObject);
const
ClickTest: array[0..3] of string = ('this','is','a','test');
begin
{ Your events will work just as if they were on your form }
StaticText1.Caption := ClickTest[StaticText1.Tag];
if StaticText1.Tag < 3 then
  StaticText1.Tag := StaticText1.Tag + 1
else StaticText1.Tag := 0;
end;

end.
Gefunden auf www.delphi3000.com

Autor + Zitat:

Mickey Petersen (Jun 7 2001 9:51AM)

The example I provided isn't the smartest way to "hide" the system clock.. a better way would be to use GetWindowRect and then SetWindowPos to make sure the Statictext covers the clock completely. It would also ensure that, when you resized the taskbar, that the statictext changed it size to accomodate this.



Alexander

omata 16. Aug 2005 18:34

Re: SystemTray - TNA erweitert!
 
Wirklich nett.

Wenn ich allerdings die ausgeblendeten Symbole einblende verschiebt sich bei mir das Ausgabefeld in den mittleren Bereich.

Also doch noch nicht ganz das Optimum.

MfG
Thorsten

turboPASCAL 16. Aug 2005 19:07

Re: SystemTray - TNA erweitert!
 
Ich mach hier mal ein Link, aber Vorsicht, Ausländisch. (und etwas langsam)

http://homepage1.nifty.com/kazubon/p...arhistory.html

...dort sind die Fensterklasses schön dargestellt.

Daniel G 16. Aug 2005 20:39

Re: SystemTray - TNA erweitert!
 
Vielleicht dürften diese Links interessant sein:

DelphiPages

ExpertExchanges - Zum Lesen der Lösung müsst ihr dort registriert sein

//Edit:
Und dann noch von den Jungs aus'm DF:

FreewareComp ähnlich wie WinTray

Am interessantesten finde ich diese Aussage von Motzi im o.g. Thread:

Zitat:

der Hook wird wahrscheinlich verwendet um die Dll in den Parent-Prozess des Tray (explorer.exe) zu injezieren. Dafür wird dann wahrscheinlich die WndProc des TrayNotifyWnd-Fensters gesubclasst.
Klingt nicht gerade einfach....

//Edit2:

Delphi-Quellcode:
TrayClockWClass
Zu dieser Klasse gibt es bei Microsoft ja überhaupt keine Infos?

turboPASCAL 16. Aug 2005 21:55

Re: SystemTray - TNA erweitert!
 
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:

Zitat von Daniel G
//Edit2:

Delphi-Quellcode:
TrayClockWClass
Zu dieser Klasse gibt es bei Microsoft ja überhaupt keine Infos?

Naja, alles wollen die bestimmt auch nicht veröffentlichen, oder ?

Habe mal den Code den axellang gepostet hat umgebaut, so dass er exakt ins TrayClock - Fenster passt. Nachtei ist das jeden mal beim WM_Paint Ereignis der Uhr das neue Fenster wieder Übermalt wird.

Delphi-Quellcode:
procedure TForm1.ReplaceSystemClock;

var
  Rect: TRect;
begin
  TaskbarHwnd := FindWindow('Shell_TrayWnd', nil);
  TrayHwnd   := FindWindowEx( TaskbarHwnd, 0, 'TrayNotifyWnd', nil);
  ClockHwnd  := FindWindowEx(TrayHwnd, 0, 'TrayClockWClass', nil);

  GetWindowRect(ClockHwnd, Rect);

  Panel1.AutoSize := False;
  Panel1.Left := 0;
  Panel1.Top := 0;
  Panel1.Width := Rect.Right - Rect.Left;
  Panel1.Height := Rect.Bottom - Rect.Top;

  Windows.SetParent(Panel1.Handle, ClockHwnd);

  Panel1.Caption := 'Test';
end;

Um das zu umgehen muss man halt "nur" dieses Ereignis auf seine Paint-Routine umlenken.

Ein Link zu selben Thema dazu in russisch: http://tusovka.co.il/article371.html


Leider habe ich bei diesem Code ein Problem mit :
Code:
[b]procedure[/b] GetAndSet(h: integer);
[b]var[/b]
  p, p2: Trect;
  hand, h2: integer;
[b]begin[/b]
  [b]if[/b] [color=red]pointer(getwindowlong(h, GWL_WNDPROC))@WinProc[/color] [b]then[/b]
  [b]begin[/b]
    SavedProc := pointer(SetWindowLong(h, GWL_WNDPROC, cardinal(@Winproc)));
  [b][...][/b]
[Fehler] ...: Ausdruckstyp muß BOOLEAN sein ?

DGL-luke 16. Aug 2005 21:59

Re: SystemTray - TNA erweitert!
 
sieht nach tippfehler aus:

Delphi-Quellcode:
pointer(getwindowlong(h, GWL_WNDPROC))=@WinProc //man beachte das '='
Sollte tun.

turboPASCAL 16. Aug 2005 22:02

Re: SystemTray - TNA erweitert!
 
Zitat:

Zitat von DGL-luke
sieht nach tippfehler aus:

Delphi-Quellcode:
pointer(getwindowlong(h, GWL_WNDPROC))=@WinProc //man beachte das '='
Sollte tun.

:gruebel: ... :coder2: ... :wall:

axellang 17. Aug 2005 09:35

Re: SystemTray - TNA erweitert!
 
Hallo Leute,

ersmal möchte ich mich bei euch allen für die angeregte Dikussion und vor allem
für das Über-Den-Tellerrand-Denken bedanken. Gestern Nacht habe ich den kompetten Source einer
Anwendung die alle Funktionen beinhaltet erhalten. Leider ist der Source (mit exe)
in C/C++ (BCB) geschreiben.

Da ich aber nicht grade eine Leuchte in Sachen C/C++ bin, obwohl das Lesen von C/C++ Source
auch bei mir Aha-Effekte auslöst werde ich aus dem Ganzen nicht ganz schlau. Leider habe ich
nicht die Möglichkeit den Source in eine IDE zu laden um vielleicht das ganze besser zu verstehen
(durchzusteppen).

Die App. hier zum Download:TNA_CLOCK.


Grüsse an die Runde

Alexander

digleu 11. Feb 2006 18:40

Re: SystemTray - TNA erweitert!
 
sorry, dass ich diesen Thread aus der Versenkung zurück hole, allerdings versuche ich seit gestern vergeblich die TNA zu vergrößern. Ich habe (mithilfe des Codes aus diesem Thread schon einen Panel an die Stelle der Uhr gesetzt und kann dessen Text halt auch beliebig verändern). Mein Ziel ist allerdings eigentlich _neben_ der Uhr einen weiteren Textbereich zu erstellen indem ich dann eine Zahl (ca. 6 stellig, beliebig wär' mir natürlich auch lieber, weiß aber echt nicht wie es gehensoll) anzeigen möchte.

Ich habe bisher mit

SetWindowPos(ClockHwnd, HWND_TOP, ClockRect.Left, ClockRect.Top, ClockRect.Right - ClockRect.Left, ClockRect.Bottom - ClockRect,Topm 0);

(dabei ist ClockRect die Größe des zu ClockHwnd gehörenden Dingsbums (Fenster ists ja nich wirklich) und ClockHwnd halt der Handle vom Dingsbums)
versucht die Größe der Uhr zu verändern (habe mir halt überlegt, dass ich ja ne eigene anzeigen könnte und daneben den Text (elegantere Wege sind willkommen), allerdings wenn ich diesen Bereich nun größer mache dann scheint sich mein Panel über die anderen Icons drüberzulegen und verdeckt sie ...

Wäre für die ein oder andere Zeile Quellcode oder nen klugen Kommentar dankbar :)

Lg Lars


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:04 Uhr.
Seite 2 von 2     12   

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