自己写的关于程序在状态栏相关操作,只列出了主要部分,大家自己琢磨吧!
const
mymsg= wm_user + 1; //定义消息键值
type
TMainForm = class(TForm)
......
private
{ Private declarations }
procedure mymessage(var message:tmessage); message mymsg; //定义接收自定义消息后的功能
var
MainForm: TMainForm;
ntid: TnotifyIconDataA;
procedure TMainForm.FormCreate(Sender: TObject);
begin//让程序不在任务栏中显示
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
ntid.cbsize := sizeof(TnotifyIconDataA);
ntid.Wnd := Handle;
ntid.uID := 100;
ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
ntid.uCallbackMessage := mymsg;
ntid.hIcon := image1.Picture.Icon.Handle; //Application.Icon.handle 系统图标
ntid.szTip := 'SMS系统服务平台';
shell_notifyicona(NIM_ADD,@ntid);
self.Visible := false;
end;
状态图表操作:
ntid.hIcon := image2.Picture.Icon.Handle; //显示工作图标
shell_notifyicona(NIM_MODIFY,@ntid);
ntid.hIcon := image1.Picture.Icon.Handle; //显示工作停止图标
shell_notifyicona(NIM_MODIFY,@ntid);
shell_notifyicona(NIM_DELETE,@ntid); //删除图标,退出程序时用
窗口操作:
ShowWindow(MainForm.Handle,SW_HIDE); //隐藏主窗口
ShowWindow(MainForm.Handle,SW_SHOW); //显示主窗口
//自定义消息操作功能:
procedure TMainForm.mymessage(var message: tmessage); //接收自定义消息,右键显示PopupMenu
var
mypt:Tpoint;
begin
Inherited;
if message.LParam = WM_RBUTTONUP then begin
getCursorPos(mypt);
PM1.Popup(mypt.X, mypt.Y);
end;
message.Result := 0;
end;