delphi中怎样对alt+Ctrl+Del,win,Tab等热键的屏闭功能?请给出实例

谢谢!如果编译成功并实现功能,将给分!用两个按钮btn1枷锁,btn2解锁!... 谢谢!如果编译成功并实现功能,将给分!用两个按钮btn1 枷锁,btn2解锁! 展开
 我来答
匿名用户
2013-08-07
展开全部
unit Unit1;
interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls,Wintypes, WinProcs,TLHelp32, ExtCtrls;type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
edt1: TEdit;
tmr1: TTimer;
//键盘上锁
Function DisableKeyboard: Boolean;
//键盘解锁
Procedure EnableKeyboard;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
hHk :HHOOK;
type
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;implementation
var
oldHook: Hhook;
{$R *.dfm}function ycxsks( yc:Boolean): Boolean;stdcall; //隐藏-显示任务条
var
h:THandle;
begin
if yc = True then
begin
h:=FindWindow('Shell_TrayWnd',nil);
ShowWindow(h,SW_hide); //隐藏任务条
end
else
begin
h:=FindWindow('Shell_TrayWnd',nil);
ShowWindow(h,SW_SHOW); //显示任务条
end;
Result:=true;
end;function keyHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
//调用键盘钩子,屏蔽左右win功能键
var
p: PKBDLLHOOKSTRUCT;
y: integer;
begin
if nCode<0 then
Result:= CallNextHookEx(hHk,nCode,WParam,LParam)
else
begin
y := 0;
case WParam of
WM_KEYDOWN,WM_SYSKEYDOWN: //按键后判断所按键
begin
p:=PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = VK_LWIN then
y := 1;
if p^.vkCode = VK_RWIN then
y := 1;
end;
WM_KEYUP,WM_SYSKEYUP: //松开按键后判断所按键
begin
p:=PKBDLLHOOKSTRUCT(Lparam);
if p^.vkCode = VK_LWIN then
y := 1;
if p^.vkCode = VK_RWIN then
y := 1;
end;
end;
if y=1 then
Result:=1 //如果为WIN功能键则屏蔽
else
Result:= CallNextHookEx(hHk,nCode,WParam,LParam); //其他键放下一个钩子
end
end;function Enablehide:Boolean;stdcall;export; //外部调用
begin
if hHk = 0 then
begin
hHk := SetWindowsHookEx(13,@keyHookProc,HInstance,0);
Result := True;
end
else
Result := False;
ycxsks(true);
end;function Disablehide:Boolean; stdcall; export; //外部调用
begin
if hHk <> 0 then
begin
UnHookWindowsHookEx(hHk);
hHk := 0;
Result := True;
end
else
Result := False;
ycxsks(False);
end;Function KbHook( code: Integer; wparam: Word; lparam: LongInt ): LongInt;
Begin
If code < 0 Then
KbHook := CallNextHookEx( oldHook, code, wparam, lparam )
Else
KbHook := 1;
End; // KbHookFunction TForm1.DisableKeyboard: Boolean;
//上锁
Begin
oldHook := SetWindowsHookEx( WH_KEYBOARD, @KbHook, Hinstance, 0 );
DisableKeyboard := oldHook <> 0;
End;Procedure TForm1.EnableKeyboard;
//解锁
Begin
If oldHook <> 0 Then
Begin
UnhookWindowshookEx( oldHook );
oldHook := 0;
End; // If
End;
procedure TForm1.btn1Click(Sender: TObject);
begin
Enablehide;
DisableKeyboard;
tmr1.Enabled:=true;
end;procedure TForm1.btn2Click(Sender: TObject);
begin
Disablehide;
EnableKeyboard;
tmr1.Enabled:=false;
end;
procedure TForm1.tmr1Timer(Sender: TObject);
var
hwnd:THandle;
begin
hwnd:=FindWindow(nil,PChar('Windows 任务管理器'));
if hwnd<>0 then
SendMessage(hwnd,WM_CLOSE,0,0);
end;
end.
编译通过的~
匿名用户
2013-08-07
展开全部
代码太长,发你QQ邮箱好了.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式