怎样在WinME中禁止用Alt+F4关闭程序?

解决方案 »

  1.   

    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
    begin
    if (ssAlt in shift)and(key=115) then key:=0;
    end;
    ------------------------------------------------------------------------------------------------------------
    type
      TForm1 = class(TForm)后,Private前面写:
    procedure SysCommand(var msg:TWMSysCommand);message WM_SysCommand;实现;
    procedure TForm1.SysCommand(var msg: TWMSysCommand);
    begin
      if msg.CmdType = SC_CLOSE then
      begin
        msg.cmdtype:= SC_DEFAULT;
        Hide;
      end;
      inherited;
    end;
    -------------------------------------------------------------------------------------------------------------
    TForm1 = class
    ...
    private
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
    ...end;procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
    begin
      if Msg.CmdType <> SC_CLOSE then
        inherited
    end;
      

  2.   

    another:屏蔽ctrl+alt+delunit start;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;Const RSP_SIMPLE_SERVICE = 1;
    Const RSP_UNREGISTER_SERVICE = 0;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
        Function GetCurrentProcessId():Longint;stdcall;far;external 'kernel32';
        Function GetCurrentProcess():Longint;stdcall;far;external 'kernel32';
        Function RegisterServiceProcess(dwProcessID:Longint;dwType:Longint):Longint;stdcall;far;external 'kernel32';
    implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    var
       pid:longint;
    begin
       pid:=GetCurrentProcessId(); //得到当前进程ID
       RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE);//把本程序注册为service
    end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    var
       pid:Longint;
    begin
       pid:=GetCurrentProcessId();
       RegisterServiceProcess(pid,RSP_UNREGISTER_SERVICE);
    end;
    end.//调试过了,在win98+Delphi5通过!
      

  3.   

    http://expert.csdn.net/Expert/topic/1418/1418963.xml?temp=.2790338
      

  4.   

    我记得可以在Form的OnCloseQuery中直接修改事件参数就可以禁止关闭。
      

  5.   

    知道Alt+F4为什么能关闭程序吗?看看系统菜单中的"关闭"项(X 关闭(C) Alt+F4),那把系统菜单中的关闭项删除不就可以了?
      

  6.   

    几个API:GetSystemMenu
    GetMenuItemCoun
    DeleteMenu
      

  7.   

    执行4次,删除关闭项后还有中间的横线两次用Form.Handle,另两次用Application.Handle~~~
      

  8.   

    registerhotkey的方法public
    procedure WMHotKey(var Message: TWMHOTKEY);  message WM_HOTKEY;
    ....
    procedure TForm1.FormCreate(Sender: TObject);
    begin
     RegisterHotKey(Handle, GlobalAddAtom('hotkey'), mod_alt, vk_F4);
    end;
    ...
    procedure TForm1.WMHotKey(var Message: TWMHOTKEY);
    begin
    //定义热键事件
    end;
    ...
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    UnregisterHotKey(Handle, GlobalAddAtom('hotkey'));
    end;
      

  9.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ComCtrls, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        ComboBox1: TComboBox;
        RadioGroup1: TRadioGroup;
        GroupBox1: TGroupBox;
        Label2: TLabel;
        Edit1: TEdit;
        CheckBox1: TCheckBox;
        CheckBox2: TCheckBox;
        CheckBox3: TCheckBox;
        Button1: TButton;
        Button2: TButton;
        ProgressBar1: TProgressBar;
        procedure FormCreate(Sender: TObject);
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
        HotKeyId: Integer;
        procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;  public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}
    //处理消息过程
    procedure TForm1.HotKeyDown(var Msg: Tmessage);
    begin
      if (Msg.LparamLo = Mod_Alt) And (Msg.LParamHi = VK_F4) then
      begin
        showmessage('OK');
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      total:real;
      temp_title:string;
      title:array [0..127] of char;
      found: HWND;
      reghotkey:boolean;
    begin
    //注册alt+f4热键
      HotKeyId := GlobalAddAtom('HotKey') - $C000;
      if RegisterHotKey(Handle, hotkeyid, Mod_Alt, VK_F4) then
        showmessage('reg suc');  
    //防止多次运行
      StrPCopy(title,Application.Title);
      temp_title:=Application.Title;
      Application.Title:='temp';
      found:=findwindow(nil,title);
      Application.Title:=temp_title;
      if found<>0 then begin
        ShowWindow(Found, SW_RESTORE);
        Application.Terminate
      end;
    //屏蔽其它系统热键和开始菜单
      SystemParametersInfo(Spi_screensaverrunning,1,nil,0);
      SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
      EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil),
                   0,'Button',nil),false);
      RadioGroup1.ItemIndex:=0;
    //取C盘容量,并在combobox里显示出来
      total:=DiskSize(3)/1024/1024;
      ComboBox1.Text:=format('%.1f',[total])+' Mb';
      ComboBox1.Items.Add(ComboBox1.Text);
    end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
    {  if RadioGroup1.ItemIndex<>1 then
      CanClose:=false;  }
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    //恢复被屏蔽的热键
      SystemParametersInfo(Spi_screensaverrunning,0,nil,0);
      EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil),
                   0,'Button',nil),true);
      unregisterhotkey(handle,hotkeyid);
      DeleteAtom(HotKeyid);
    end;end.
      

  10.   

    不明白为什么一定要是WINME,是禁止关闭所有的程序还是只是你写的程序?
      

  11.   

    unit MainFrm;interfaceuses
      SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs;type
      TMainForm = class(TForm)
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      MainForm: TMainForm;implementation{$R *.DFM}procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if MessageDlg('是否关闭窗体', mtConfirmation, mbYesNoCancel, 0) = mrYes then
        CanClose := True
      else
        CanClose := false;
    end;end.
      

  12.   

    禁止关闭你写的程序就用 linzer(阿色)的方法
      

  13.   

    你截获wm_syscommand过后,你什么都不做就可以了