unit Unit1;
interface
uses ShellApi;
const WM_TASKBAREVENT = WM_USER + 1;
type
TForm1 =
class(TForm)
TNATimer2: TTimer;
TNAPopup1: TPopupMenu;
TNAImage2: TImage;
Runterfahren1: TMenuItem;
Beenden1: TMenuItem;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TNATimer2Timer(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure oeffnen1Click(Sender: TObject);
procedure Beenden1Click(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
private
procedure TaskBarRemoveIcon;
procedure TaskBarAddIcon;
protected
procedure WMTaskbarEvent(
var Message: TMessage);
message WM_TASKBAREVENT;
end;
var
Form1: TForm1;
implementation
uses
var count :Integer;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
TaskBarAddIcon;
// Icon setzen
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ShowWindow(GetWindow(
handle,GW_OWNER),SW_HIDE);
// Taskbareintrag löschen
end;
//=========Bei Formstart Iconsetzen=============================================
procedure TForm1.TNATimer2Timer(Sender: TObject);
begin
Inc(count);
if count = 3
then
begin
Self.Hide;
TNATimer2.Enabled:= False;
end;
end;
//==================Icon setzen=================================================
procedure TForm1.TaskBarAddIcon;
var tnid: TNotifyIconData;
begin
tnid.cbSize := SizeOf(TNotifyIconData);
tnid.Wnd := Form1.Handle;
tnid.uID := 1;
tnid.UFlags:= NIF_MESSAGE
or NIF_ICON
or NIF_TIP;
tnid.uCallbackMessage:= WM_TASKBAREVENT;
tnid.hIcon:= Form1.TNAImage2.Picture.Icon.Handle;
strcopy(tnid.szTip,'
Rechner Runterfahren');
Shell_NotifyIcon(NIM_Add, @tnid)
end;
//===============Beim öffnen des Icon( Popup)===================================
procedure TForm1.oeffnen1Click(Sender: TObject);
begin
Form1.Show;
Timer3.Enabled:= True;
end;
//===========Nach erneuten öfnnen des Programms wieder schließen================
procedure TForm1.Timer3Timer(Sender: TObject);
begin
Self.Hide;
Timer3.Enabled:= False;
end;
//===============Beim schließen des Icon( Popup)================================
procedure TForm1.Beenden1Click(Sender: TObject);
begin
close;
end;
//=====Beim Form schließen Icon wieder aufräumen================================
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
TaskBarRemoveIcon;
end;
//==================Icon weg====================================================
procedure TForm1.TaskBarRemoveIcon;
var tnid: TNotifyIconData;
begin
tnid.cbSize := SizeOf(TNotifyIconData);
tnid.Wnd := Form1.Handle;
tnid.uID := 1;
Shell_NotifyIcon(NIM_DELETE, @tnid)
end;
//=================Icon Rechts/Links klick =====================================
procedure TForm1.WMTaskbarEvent(
var Message: TMessage);
var Point: TPoint;
begin
case Message.LParamLo
of
WM_LBUTTONDOWN:
// bei Linksklick
begin
Form1.Show;
Timer3.Enabled:= True;
end;
WM_RBUTTONDOWN:
// bei Rechtsklick
begin
GetCursorPos(point);
TNAPopup1.Popup(point.X,point.Y);
end;
end;
end;
end.