我想做成这样的效果:在操作系统任务栏的程序图标上右键弹出菜单里选择“关闭”后,先弹出确认对话框,选择“是”:退出程序;选择“否”返回程序窗口。
请写出相关代码并说明!

解决方案 »

  1.   


    if Application.MessageBox('是否退出?', '系统提示', MB_OKCANCEL +
      MB_ICONQUESTION) = IDCANCEL then
    begin
      Exit;
    end
    else
    begin
      Application.Terminate;
    end;
      

  2.   

    //会触发FormCloseQuery事件procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
        if  application.MessageBox('是否保存?','询问',mb_okcancel+mb_iconquestion)=idok  then
          CanClose   := true
        else
          CanClose   := false;
    end;
      

  3.   

    在主窗口的OnCloseQuery事件中procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if Application.MessageBox('确实要退出系统吗?','询问',MB_YESNO + MB_ICONQUESTION)<>IDYES then
      begin
        CanClose := False;
      end
      else
      begin
        CanClose := True;
      end;
    end;
      

  4.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if Application.MessageBox('确实要退出系统吗?','询问',MB_YESNO + MB_ICONQUESTION)<>IDYES then
      begin
      CanClose := False;
      end
      else
      begin
      CanClose := True;
      end;
    end;