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;我在程序中用以上代码,关闭窗体时隐藏到托盘,不能正常关机,激活窗口时却可以响应.哪位高手指点一下?

解决方案 »

  1.   

    截获关机的消息,注意在你的处理后加上inherited一句
    procedure WMQUERYENDSESSION(var Msg: TWMQUERYENDSESSION); message WM_QUERYENDSESSION;
    ----------------
    procedure TForm1.WMQUERYENDSESSION(var Msg: TWMQUERYENDSESSION);
    begin
      DoSomething; //你的处理
      Inherited;  //加上这句
    end;
      

  2.   

    有啊
     nmudp1.free;
      myMsg.Result :=1;
      Msg.Result := 1;  inherited;
      

  3.   

    是否  inherited要放前边.
      

  4.   

    为什么搞这么复杂
    可以用Shell_NotifyIcon
      

  5.   

    是呀 托盘怎么和关机撤上了呀
    卸载图标
    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;
      

  6.   

    装载图标:
    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;
      

  7.   

    因为有 If myMsg.Result=1 then
    当系统关机时,会接受系统发送的消息,如果在托盘时,就接受不到,不知为什么