Delphi应用程序 - 在Windows 8上阻止windows-key(Start)

Mar*_*iak 0 windows delphi screen windows-8

我正在编写Delphi应用程序.我的目标是用我的应用程序覆盖所有屏幕以强制用户填写我的表单.应用程序将按计划任务运行.

我的问题是,通常,Windows不允许应用程序阻止其他用户操作.

在Windows 7中,我可以将我的应用程序作为scr文件(屏幕保护程序)运行,没有标题栏和设置StayOnTop.在这种情况下,即使在"窗口键"(开始)上可见,其他应用程序也会留在我的应用程序之后,因此达到了我的目标.不幸的是,在Windows 8中,这个解决方案不起作用,因为"窗口键"显示了开始屏幕,当我可以运行任何东西并且这个"任何东西"保持在最顶层.

我尝试了下面的代码,但没有成功.

  h := FindWindowEx(FindWindow('Shell_TrayWnd', nil),0,'Button',nil);
  ShowWindow(h,0); 
  Windows.SetParent(h,0);
Run Code Online (Sandbox Code Playgroud)

如何阻止整个Windows 8系统中的"窗口键"(开始按钮)操作?

Cod*_*aos 9

我没有在Windows 8上测试它,但原则上可以使用键盘钩来丢弃按键.

类似于以下内容:

const   
    WH_KEYBOARD_LL   =   13;
    LLKHF_ALTDOWN    =   $00000020;
    LLKHF_INJECTED   =   $00000010;

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;
var
    fEatKeyStroke:   Boolean;
    p:   PKBDLLHOOKSTRUCT;
begin
    fEatKeystroke   :=   False;
    if active and(  nCode   =   HC_ACTION)   then
    begin
        case   awParam   of
            WM_KEYDOWN,
            WM_SYSKEYDOWN,
            WM_KEYUP,
            WM_SYSKEYUP:
                begin
                    p   :=   PKBDLLHOOKSTRUCT(alParam);
                    if DisableWinKeys then
                     begin
                      if p^.vkCode   =   VK_LWIN
                        then fEatKeystroke   :=   True;
                      if p^.vkCode   =   VK_RWIN
                        then fEatKeystroke   :=   True;
                     end;
                end;
        end;
    end;
    if   fEatKeyStroke   then
        Result := 1
    else
        Result := CallNextHookEx(hhkLowLevelKybd, nCode, awParam, alParam);
end;

procedure InstallHook;
begin
  if hhkLowLevelKybd <> 0 then exit;
  hhkLowLevelKybd := SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardProc,   hInstance,   0);
end;

procedure UninstallHook;
begin
  if hhkLowLevelKybd = 0 then exit;
  UnhookWindowsHookEx(hhkLowLevelKybd);
  hhkLowLevelKybd := 0;
end;
Run Code Online (Sandbox Code Playgroud)

  • @CodeInChaos ......你是男人!您的代码即使在Windows 8中也无需更改.我会投票给您的解决方案,但我没有足够的声誉:( (3认同)