新建一工程,加入CnTrayIcon控件, AutoHide=True; UseAppIcon=True,其余默认,为双击添加如下事件:
procedure TForm1.CnTrayIconDblClick(Sender: TObject);
begin
if Application.MainForm.WindowState = wsMinimized then
CnTrayIcon.ShowApplication
else
CnTrayIcon.HideApplication;
end;
在Windows XP/7/2008下面都无法正常还原窗口,表现为最小化的任务栏图标,需要鼠标再次点击才能恢复.
CnPack是否可以考虑在CnTrayIcon.pas添加多一行Application.BringToFront?
procedure TCnTrayIcon.ShowApplication;
begin
ShowWindow(Application.Handle, SW_SHOW);
Application.Restore;
if Application.MainForm <> nil then
begin
if FSaveWindowState <> wsMinimized then
Application.MainForm.WindowState := FSaveWindowState
else
Application.MainForm.WindowState := wsNormal;
Application.MainForm.Show;
Application.BringToFront;
end;
end;