最近我把电脑搬到学校,因为不想让所有的人都胡乱摆弄我的电脑,所以自己编程做了个程序,开机时自动运行,没有密码就不让进入系统,我编程将鼠标限制在一个区域里,屏蔽了所有的系统热键,但是后来有个同学发现了我这个软件的BUG,就是一按CTRL+F4,就能将它关掉,郁闷啊,为什么屏蔽的系统热键里没有CTRL+F4呢?请问各位大虾怎么编程才能实现?请不要对我说要用键盘钩子,一说到钩子我就头疼!
先送上100分热热身!

解决方案 »

  1.   

    向系统注册Alt+F4热键,然后在代码里什么也不做,这样可以屏蔽全局的 Alt+F4:
      private
        { Private declarations }
        HotKeyId: Integer;
        procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;  //热键消息响应procedure TForm1.HotKeyDown(var Msg: Tmessage);
    begin
      if (Msg.LparamLo = Mod_Alt) And (Msg.LParamHi = VK_F4) then 
      begin
        ; // 什么也不做,呵呵, 不写也行
      end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      HotKeyId := GlobalAddAtom('HotKey') - $C000;
      RegisterHotKey(Handle, hotkeyid, Mod_Alt, VK_F4);
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      UnRegisterHotKey(handle, HotKeyId);
    end;
      

  2.   

    在Form的OnCloseQuery事件中:
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if 密码不对 then CanClose := False;
    end;
      

  3.   


    用主form的onkeydown事件,
    不过最好设置其keypreview为true如此这般就行了:
    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      {屏蔽 ALT+F4}
      if (shift = [ssAlt]) and (key = vk_F4) then
          begin
            shift := [];
            key := 0;
          end;
    end;