const
Icon_ID=1;// 图标在本应用程序中的编号
MyIcoMes=WM_USER+1; // 图标上的鼠标事件
ver = '1.0';
private
{ Private declarations }
normalIcon,disabledIcon:TIcon;//需放在状态指示区的图标
status: Boolean;
procedure MyIcoMesDo(var Msg : TMessage);Message MyIcoMes; //托盘图标的返回消息
procedure installIcon;
procedure UninstallIcon;
procedure ChangeIcon(status:Boolean); //根据参数,显示不同的图标
var
Form1: TForm1;
PNotify:PNotifyIconDataA; //托盘图标结构
Mouse_Point : TPoint; //当前鼠标位置
procedure TForm1.installIcon;
var icondata:TNotifyIconData;
begin
normalIcon:=TIcon.Create;
disabledIcon:=TIcon.Create;
// normalicon.LoadFromFile ('log.ico');
// disabledIcon.LoadFromFile ('log.ico');
normalicon.assign(Form1.Icon);
disabledIcon.assign(Form1.Icon);
IconData.cbSize:=Sizeof(IconData);
IconData.Wnd :=Handle;
IConData.uID :=Icon_ID;
IconData.uFlags :=NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallbackMessage :=MyIcoMes;
IConData.hIcon :=normalIcon.Handle ;
IconData.szTip :='中国龙';
Shell_NotifyIcon(NIM_ADD,@IconData);
end;
procedure Tform1.UninstallIcon ;
var
IconData:TNotifyIconData;
begin
//
IconData.cbSize :=Sizeof(IconData);
IconData.Wnd :=handle;
IconData.uID :=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
end;
procedure tForm1.ChangeIcon(status:boolean);
var
IconData:TNotifyIconData;
begin
IconData.cbSize :=Sizeof(IconData);
IconData.Wnd :=Handle;
IconData.uID :=ICON_ID;
if not status then IconData.hIcon := normalicon.Handle
else IconData.hIcon :=disabledIcon.Handle;
IconData.uFlags :=NIF_ICON;
Shell_NotifyIcon(NIM_MODIFY,@IconData);
end;
procedure Tform1.MyIcoMesDo(var Msg:TMessage);
Var Mouse_Point : TPoint; //当前鼠标位置
begin
if (Msg.LParam=WM_LBUTTONDBLCLK) and form1.Enabled then
if Auser.runthis=1 then
begin
form1.Visible:=not form1.Visible; //双击图标,显示(隐藏)窗口
if not form1.Visible then
begin
SetForegroundWindow(form1.Handle); //窗口运行到前台
end;
end;
if (Msg.LParam=WM_RBUTTONUP) and form1.Enabled then
begin //右键单击,显示菜单
GetCursorPos(Mouse_Point);
PopupMenu1.Popup(Mouse_Point.x,Mouse_Point.y);
ChangeIcon( status );
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle,SW_HIDE);
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
18: //弹出pop菜单 "Alt"
begin
GetCursorPos(Mouse_Point);
PopupMenu1.Popup(Mouse_Point.x,Mouse_Point.y);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
installIcon; //建立“托盘”图标
ChangeIcon(False);
ShowWindow(Application.handle,SW_HIDE); //隐藏应用程序主窗口机
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ANimateWindow(Handle,200,AW_SLIDE+AW_VER_NEGATIVE);
SetForegroundWindow(form1.Handle);
// TreeView1.Visible := false;
TreeView1.Items.Clear;
AddClass(0,nil);
// TreeView1.Visible := false;
TreeView1.FullExpand;
// 收起 TreeView1.FullCollapse;
DM.aq_company.open;
if (dm.AQ_Company.RecordCount<>0) then
StatusBar1.Panels[0].TEXT := DM.aq_company.FieldByName('company').AsString
else StatusBar1.Panels[0].TEXT := '微笑电脑公司';
StatusBar1.Panels[1].TEXT := '用户:' + Auser.UserName;
StatusBar1.Panels[2].TEXT := '权限:' + Auser.UserGroup;
StatusBar1.Panels[3].TEXT := '中国人的中国龙';
tjpg_sta;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Application.messagebox('确认是要退出吗?', '人事系统', mb_iconinformation + mb_YesNo) = idNo then
Abort;
// DM.AQ_login.Locate('username', Auser.UserName, []);
DM.AQ_login.Edit;
DM.AQ_login.FieldByName('exit_date').AsString := DateTimetostr((now()));
DM.AQ_login.Post;
unInstallIcon; //删除任务栏图标
normalicon.Free ;
disabledIcon.Free;
Application.Terminate;
ANimateWindow(Handle,200,AW_SLIDE+AW_HOR_POSITIVE+AW_HIDE);
// ANimateWindow(Handle,200,AW_SLIDE+AW_HOR_POSITIVE+AW_HIDE);
// ANimateWindow(Handle,200,AW_SLIDE+AW_VER_NEGATIVE+AW_HIDE);
end;