Procedure wmQUERYENDSESSION(var msg:tWMQUERYENDSESSION);message WM_QUERYENDSESSION;var myMsg:Tmessage;procedure Tform1.wmQUERYENDSESSION(var msg:tWMQUERYENDSESSION);
begin
nmudp1.free;
myMsg.Result :=1;
Msg.Result := 1;
inherited;
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
If myMsg.Result=1 then
CanClose:=True
Else
begin
CanClose:=False;
Hide();
end;
end;我在程序中用以上代码,关闭窗体时隐藏到托盘,不能正常关机,激活窗口时却可以响应.哪位高手指点一下?
begin
nmudp1.free;
myMsg.Result :=1;
Msg.Result := 1;
inherited;
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
If myMsg.Result=1 then
CanClose:=True
Else
begin
CanClose:=False;
Hide();
end;
end;我在程序中用以上代码,关闭窗体时隐藏到托盘,不能正常关机,激活窗口时却可以响应.哪位高手指点一下?
procedure WMQUERYENDSESSION(var Msg: TWMQUERYENDSESSION); message WM_QUERYENDSESSION;
----------------
procedure TForm1.WMQUERYENDSESSION(var Msg: TWMQUERYENDSESSION);
begin
DoSomething; //你的处理
Inherited; //加上这句
end;
nmudp1.free;
myMsg.Result :=1;
Msg.Result := 1; inherited;
可以用Shell_NotifyIcon
卸载图标
procedure Tmain.SpeedButton_sys_closeClick(Sender: TObject);
var
icondata:tnotifyicondata;
begin
myIcon:=TIcon.Create;
myIcon.LoadFromFile('my.ico');
icondata.cbSize:=SIZEOF(icondata);
icondata.Wnd:=Handle;
icondata.uID:=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@icondata);
Application.Terminate;
end;
procedure Tmain.FormCreate(Sender: TObject);
var
icondata:tnotifyicondata;
begin
myIcon:=TIcon.Create;
myIcon.LoadFromFile('my.ico');
icondata.cbSize:=SIZEOF(icondata);
icondata.Wnd:=Handle;
icondata.uID:=ICON_ID;
icondata.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
icondata.szTip:='进销存管理系统';
icondata.uCallbackMessage:=MI_ICONEVENT;
icondata.hIcon:=myIcon.Handle;
Shell_NotifyIcon(NIM_ADD,@icondata);
end;
当系统关机时,会接受系统发送的消息,如果在托盘时,就接受不到,不知为什么