Systray - substituindo o clock do windows |
Top Previous Next |
// Este exemplo mostra como colocar qualquer coisa sobre o RELOGIO do Windows!!
unit Unit1;
interface
uses Forms, ExtCtrls, StdCtrls, Classes, Controls, Windows;
type TForm1 = class(TForm) Button1: TButton; StaticText1: TStaticText; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private procedure ReplaceSystemClock; end;
var Form1: TForm1;
implementation
{$R *.dfm}
uses ARotinasUnit;
procedure TForm1.Button1Click(Sender: TObject); begin ReplaceSystemClock; end;
procedure TForm1.ReplaceSystemClock; var Rect : TRect; // We need this for calc'ing the size of the System Tray Window 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 := taCenter; // Change the borderstyle to single so we can see if its positioned properly StaticText1.BorderStyle := sbsNone; // Single; // 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); end;
procedure TForm1.Timer1Timer(Sender: TObject); var A,B : string; begin A := StrZero( Trunc( Random(99) + 1 ), 2 ); B := StrZero( Trunc( Random(99) + 1 ), 2 ); StaticText1.Caption := A + ':' + B; ReplaceSystemClock; end;
end. |