概述
链接:https://pan.baidu.com/s/1j41jWSawLn-xZK07i0GC2w
提取码:cax2
说明:
- 点击【禁用Win键】最小化并禁止Win键
- 在【禁用Win键】点击后,屏蔽WinE WinD才生效
- 退出在面板或托盘右键退出即可
Delphi7源码
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI, Menus, ComObj, ExtCtrls, Contnrs;
const
WH_KEYBOARD_LL = 13;
WM_TRAYMSG = WM_USER + 101; //自定义托盘消息
VK_D = $44;
VK_E = $45;
VK_L = $4C;
type
PKBDLLHOOKSTRUCT=^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT=record
vkCode:DWORD;
scanCode:DWORD;
flags:DWORD;
time:DWORD;
dwExtraInfo:DWORD;
end;
type
TfrmDispatcherMain = class(TForm)
Button1: TButton;
pm1: TPopupMenu;
N1: TMenuItem;
Button2: TButton;
Timer1: TTimer;
cbE: TCheckBox;
cbD: TCheckBox;
cbL: TCheckBox;
Win1: TMenuItem;
Win2: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure Win1Click(Sender: TObject);
procedure Win2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
procedure WMTrayMsg(var Msg: TMessage);message WM_TRAYMSG; //声明托盘消息
procedure WMSysCommand(var Msg: TMessage);message WM_SYSCOMMAND;
public
{ Public declarations }
procedure ShowDesktop;
end;
var
frmDispatcherMain: TfrmDispatcherMain;
hhkLowLevelKybd: HHook = 0;
NotifyIcon: TNotifyIconData; //定义托盘图标结构体
Q:TObjectQueue;
HookFlag:Boolean = true;
GHandle:HWND = 0;
implementation
{$R *.dfm}
procedure SwitchToThisWindow(hWnd:Thandle;fAltTab:boolean);stdcall;external 'User32.dll';
function LowLevelKeyboardProc(nCode:integer;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;
var
fEatKeystroke:BOOL;
p,p0:pKBDLLHOOKSTRUCT;
procedure ShowDesktop;
begin
frmDispatcherMain.ShowDesktop;
//Form1.Memo1.Lines.Append('ShowDesktop');
end;
procedure OpenComputer;
begin
ShellExecute(GHandle, 'open', 'Explorer.exe','::{20D04FE0-3AEA-1069-A2D8-08002B30309D}', nil, SW_SHOWNORMAL);
//Form1.Memo1.Lines.Append('OpenComputer');
end;
procedure LockComputer;
begin
LockWorkStation();
//Form1.Memo1.Lines.Append('LockComputer');
end;
procedure Enqueue;
begin
//Form1.Memo1.Lines.Append('Q.Push->'+inttostr(p.vkCode));
New(p0);
p0.vkCode:=p.vkCode;
p0.scanCode:=p.scanCode;
p0.flags:=p.flags;
p0.time:=p.time;
p0.dwExtraInfo:=p.dwExtraInfo;
Q.Push(TObject(p0));
end;
begin
result:=0;
fEatKeystroke := false;
p:=PKBDLLHOOKSTRUCT(lparam);
p0:=nil;
if (ncode=HC_ACTION) then begin
case wparam of
WM_KEYDOWN,
WM_SYSKEYDOWN,
WM_KEYUP,
WM_SYSKEYUP:
begin
if HookFlag then begin
case p.vkCode of
VK_D:
if not frmDispatcherMain.cbD.Checked then Enqueue;
VK_E:
if not frmDispatcherMain.cbE.Checked then Enqueue;
VK_L:
if not frmDispatcherMain.cbL.Checked then Enqueue;
VK_RWin,
VK_LWin:
begin
while Q.Count>0 do begin
p0 := PKBDLLHOOKSTRUCT(Q.Pop());
//if p0 <> nil then frmDispatcherMain.Memo1.Lines.Append('Q.Pop->'+inttostr(p0.vkCode));
if (p.time - p0.time)<500 then break;
Dispose(p0);
end;
if (p0 <> nil) and ((p.time - p0.time)<500) then begin
HookFlag := false;
case p0.vkCode of
VK_D: ShowDesktop();
VK_E: OpenComputer();
VK_L: LockComputer();
end;
Dispose(p0);
while Q.Count>0 do Dispose(PKBDLLHOOKSTRUCT(Q.Pop()));
frmDispatcherMain.Timer1.Enabled:=true;
end;
end;
end;
end;
featkeystroke :=(p.vkcode = VK_LWin) or (p.vkcode = VK_RWin) or (p.vkCode = VK_APPS);
end;
end;
end;
if featkeystroke then result:=1;
if ncode <> 0 then result := callnexthookex(0,ncode,wparam,lparam);
end;
procedure TfrmDispatcherMain.Button1Click(Sender: TObject);
begin
hhklowlevelkybd := setwindowshookexw(wh_keyboard_ll,LowlevelKeyboardproc,hinstance,0);
if hhklowlevelkybd<>0 then begin
Button1.Enabled:=true;
Button2.Enabled:=false;
NotifyIcon.szTip := 'Win键屏蔽已启用';
Shell_NotifyIcon(NIM_MODIFY,@NotifyIcon);
self.Visible:=false;
pm1.Items.Items[1].Enabled:= (hhklowlevelkybd=0);
pm1.Items.Items[0].Enabled:= (hhklowlevelkybd<>0);
end;
end;
procedure TfrmDispatcherMain.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
Q.Free();
end;
procedure TfrmDispatcherMain.FormCreate(Sender: TObject);
begin
with NotifyIcon do begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Self.Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; //图标、消息、提示信息
uCallbackMessage := WM_TRAYMSG;
hIcon := Application.Icon.Handle;
szTip := 'Win屏蔽';
end;
Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
Q := TObjectQueue.Create();
GHandle:=Handle;
end;
procedure TfrmDispatcherMain.WMSysCommand(var Msg: TMessage);
begin
if (Msg.WParam = SC_ICON) or (Msg.WParam = SC_CLOSE) then begin
Self.Visible := False;
SetWindowPos(Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE OR SWP_NOSIZE OR SWP_SHOWWINDOW);
end
else
DefWindowProc(Self.Handle,Msg.Msg,Msg.WParam,Msg.LParam);
end;
procedure TfrmDispatcherMain.WMTrayMsg(var Msg: TMessage);
var
p: TPoint;
begin
case Msg.LParam of
WM_LBUTTONDOWN:
begin
Self.Visible := True; //显示窗体
SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;
WM_RBUTTONDOWN:
begin
if self.visible then SetForegroundWindow(Self.Handle); //把窗口提前
GetCursorPos(p);
pm1.Popup(p.X,p.Y);
end;
end;
end;
procedure TfrmDispatcherMain.N1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TfrmDispatcherMain.Button2Click(Sender: TObject);
begin
UnhookWindowsHookEx(hhklowlevelkybd);
hhklowlevelkybd:=0;
Button1.Enabled:=true;
Button2.Enabled:=false;
pm1.Items.Items[1].Enabled:= (hhklowlevelkybd=0);
pm1.Items.Items[0].Enabled:= (hhklowlevelkybd<>0);
NotifyIcon.szTip := 'Win键屏蔽已禁用';
Shell_NotifyIcon(NIM_MODIFY,@NotifyIcon);
end;
procedure TfrmDispatcherMain.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
begin
Button1.Enabled:=(hhklowlevelkybd=0);
Button2.Enabled:=(hhklowlevelkybd<>0);
pm1.Items.Items[1].Enabled:= (hhklowlevelkybd=0);
pm1.Items.Items[0].Enabled:= (hhklowlevelkybd<>0);
end;
procedure TfrmDispatcherMain.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:=false;
HookFlag:=true;
end;
procedure TfrmDispatcherMain.Win1Click(Sender: TObject);
begin
Button2Click(Sender);
end;
procedure TfrmDispatcherMain.Win2Click(Sender: TObject);
begin
Button1Click(Sender);
end;
procedure TfrmDispatcherMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
self.Visible:=false;
CanClose:=False;
end;
procedure TfrmDispatcherMain.ShowDesktop;
var
vShellApplication: OleVariant;
begin
self.Visible:=true;
SetForegroundWindow(Self.Handle);
SwitchToThisWindow(Self.Handle,true);
SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
vShellApplication := CreateOleObject('Shell.Application');
vShellApplication.ToggleDesktop;
vShellApplication := unassigned;
self.Visible:=false;
end;
end.
最后
以上就是敏感皮卡丘为你收集整理的Win屏蔽工具的全部内容,希望文章能够帮你解决Win屏蔽工具所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复