unit mUptime;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, Menus, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
IconData: TNotifyIconData;
public
{ Public declarations }
procedure WndProc(var Msg: TMessage); override;
procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function UpTime: string; // Uptime
const
ticksperday: Integer = 1000 * 60 * 60 * 24;
ticksperhour: Integer = 1000 * 60 * 60;
ticksperminute: Integer = 1000 * 60;
tickspersecond: Integer = 1000;
var
t: Longword;
d, h, m, s: Integer;
begin
t := GetTickCount;
d := t div ticksperday;
Dec(t, d * ticksperday);
h := t div ticksperhour;
Dec(t, h * ticksperhour);
m := t div ticksperminute;
Dec(t, m * ticksperminute);
s := t div tickspersecond;
Result := 'Läuft seit: ' + IntToStr(d) + ' Tag(e) ' + IntToStr(h) + ' Stunden ' + IntToStr(m) +
' Minuten ' + IntToStr(s) + ' Sekunden';
end;
procedure TForm1.WndProc(var Msg: TMessage);
var
Point: TPoint;
begin
if Msg.Msg = WM_USER + 20 then
begin
case Msg.lParam of
WM_RBUTTONDOWN:
begin
SetForegroundWindow(
Handle);
GetCursorPos(Point);
PopUpMenu1.PopUp(Point.X, Point.Y);
end;
WM_LBUTTONDOWN:
begin
//ShowMessage('links runter');
end;
WM_LBUTTONDBLCLK:
begin
Form1.Show;
// Icon nur anzeigen wenn Fenster minimiert
Shell_NotifyIcon(NIM_DELETE, @IconData);
end;
end;
end;
inherited;
end;
procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
if Message.CmdType and $FFF0 = SC_MINIMIZE then
begin
Hide;
// Icon nur anzeigen wenn Fenster minimiert
Shell_NotifyIcon(NIM_ADD, @IconData);
end
else
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.ShowMainForm := False; //Programm gar nicht erst anzeigen
IconData.cbSize := SizeOf(IconData);
IconData.Wnd :=
Handle;
IconData.uID := 100;
IconData.uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
IconData.uCallBackMessage := WM_USER + 20;
IconData.hIcon := Application.Icon.Handle;
IconData.szTip := PChar(UpTime); //Geht nicht
label1.caption := PChar(UpTime); //Funktioniert Wunderbar
Shell_NotifyIcon(NIM_ADD, @IconData); // fügt das Icon ein end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @IconData);
end;
end.