Einzelnen Beitrag anzeigen

axellang

Registriert seit: 3. Mai 2003
Ort: München
138 Beiträge
 
Delphi XE2 Enterprise
 
#11

Re: SystemTray - TNA erweitert!

  Alt 16. Aug 2005, 18:22
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
Alexander Lang
  Mit Zitat antworten Zitat