请问
使用DELPHI60,如何在WINDOWS2000下屏蔽WINDOWS键

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        CheckBox1: TCheckBox;
        CheckBox2: TCheckBox;
        CheckBox3: TCheckBox;
        CheckBox4: TCheckBox;
        CheckBox5: TCheckBox;
        CheckBox6: TCheckBox;
        CheckBox7: TCheckBox;
        CheckBox8: TCheckBox;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;const
      WH_KEYBOARD_LL = 13;
      LLKHF_ALTDOWN  = $00000020;type
      tagKBDLLHOOKSTRUCT = record
        vkCode: DWORD;
        scanCode: DWORD;
        flags: DWORD;
        time: DWORD;
        dwExtraInfo: DWORD;
      end;
      KBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
      LPKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
      PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;var
      hhkLowLevelKybd: HHOOK;function LowLevelKeyBoardProc(nCode: Integer; awParam: WPARAM; alParam: LPARAM): LRESULT; stdcall;
    implementationfunction LowLevelKeyBoardProc(nCode: Integer; awParam: WPARAM; alParam: LPARAM): LRESULT; stdcall; 
    var
      fEatKeyStroke: Boolean;
      p: PKBDLLHOOKSTRUCT;
    begin
      fEatKeystroke := False;
      if nCode = HC_ACTION then
      begin
        case awParam of
          WM_KEYDOWN,
          WM_SYSKEYDOWN,
          WM_KEYUP,
          WM_SYSKEYUP:
            begin
      p := PKBDLLHOOKSTRUCT(alParam);
              if ((p^.flags and LLKHF_ALTDOWN) <> 0) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then
                fEatKeystroke := True;
              if ((p^.flags and LLKHF_ALTDOWN) <> 0) and (p^.vkCode = VK_ESCAPE) then
                fEatKeystroke := True;
              if ((p^.flags and LLKHF_ALTDOWN) <> 0) and (p^.vkCode = VK_TAB) then
                fEatKeystroke := True;
              if ((p^.Flags and LLKHF_ALTDOWN) <> 0) and (p^.vkCode = VK_SPACE) then
                fEatKeyStroke := True;
              if ((GetKeyState(VK_CONTROL) and $8000) <> 0) and (p^.vkCode = VK_ESCAPE) then
                fEatKeystroke := True;
              if p^.vkCode = VK_LWIN then
                fEatKeystroke := True;
            end;
        end;
      end;
      if fEatKeyStroke then
        Result := 1
      else
        Result := CallNextHookEx(hhkLowLevelKybd, nCode, awParam, alParam);
    end;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowWindow(FindWindow('Shell_TrayWnd', nil), SW_HIDE);
      hhkLowLevelKybd := SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardProc, hInstance, 0);
      Button1.Enabled := False;
      Button2.Enabled := True;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      UnhookWindowsHookEx(hhkLowLevelKybd);
      ShowWindow(FindWindow('Shell_TrayWnd', nil), SW_SHOW);
      Button1.Enabled := True;
      Button2.Enabled := False;
    end;end.