大家好,我写实现一功能:就是屏蔽键盘上的复制快捷键CTRL+C我是这样实现的,先把函数写进DLLlibrary ViewCode;uses
Windows, Messages; {$R *.res}function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
var
Key: WORD;
FMHook: HHOOK;
begin
if Msg.Message = WM_KEYDOWN then
begin
Key := Msg.wParam;
//ShiftState := Msg.lParam;
if (GetKeyState(vk_Control) < 0) and (key = ord ('C')) then
Msg.wParam := 0;
end ;
Result := CallNextHookEx(FMHook, Code, WParam, Longint(@Msg));
end;exports
FMHookProc;begin
end.然后在程序中调用:function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall; external 'ViewCode.dll' Name 'FMHookProc';procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowsHookEx(WH_GETMESSAGE, @FMHookProc, 0, GetCurrentThreadID);
end;结果却是这样的:
使用CTRL+C是复制不了程序文本框里的内容,但接着用CTRL+V,却粘贴了“FMHook: HHOOK”
请问这是什么原因呢 ?
Windows, Messages; {$R *.res}function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
var
Key: WORD;
FMHook: HHOOK;
begin
if Msg.Message = WM_KEYDOWN then
begin
Key := Msg.wParam;
//ShiftState := Msg.lParam;
if (GetKeyState(vk_Control) < 0) and (key = ord ('C')) then
Msg.wParam := 0;
end ;
Result := CallNextHookEx(FMHook, Code, WParam, Longint(@Msg));
end;exports
FMHookProc;begin
end.然后在程序中调用:function FMHookProc(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall; external 'ViewCode.dll' Name 'FMHookProc';procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowsHookEx(WH_GETMESSAGE, @FMHookProc, 0, GetCurrentThreadID);
end;结果却是这样的:
使用CTRL+C是复制不了程序文本框里的内容,但接着用CTRL+V,却粘贴了“FMHook: HHOOK”
请问这是什么原因呢 ?
你试试在别处复制一下,然后再Ctrl + v,你看看值是不是变成你最后一次复制的内容了