AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

SystemTray - TNA erweitert!

Ein Thema von axellang · begonnen am 16. Aug 2005 · letzter Beitrag vom 11. Feb 2006
 
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
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:16 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz