DLL中的主代码如下:
function KeyboardHookHandler(iCode: Integer;wParam:
WPARAM; lParam: LPARAM): LRESULT;stdcall;export;
const _KeyPressMask=$80000000;
//var
//f:textfile;
//temp:string;
begin
result:=0;
if iCode<0 then
Result:=CallNextHookEx(hHook,iCode,wParam,lParam);
//侦测Ctrl+Alt+F12组合键
if ((lParam and _KeyPressMask)=0)
and (GetKeyState(vk_Control)<0)
and (getKeyState(vk_menu)<0) and (wParam=vk_F12) then
begin
if HideHook then
begin
showmessage('HideHook:true;显示');
showWindow(hbefore,SW_SHOW);
hideHook:=false;
end
else
begin
showmessage('HideHook:false;隐藏');
showWindow(hbefore,SW_HIDE);
hideHook:=true;
end
end;
end;
//-这里hbefore是由调用程序传过来的,程序窗口句柄。
function EnableHideHook(hFrmHandle:longint):BOOL; export;
begin
Result:=false;
if hHook<>0 then
exit;//已经有一个HOOK存在
hHook:=SetWindowsHookEx(WH_KEYBOARD,KeyboardHookHandler,HInstance,0);
hbefore:=hFrmHandle;
Result:=hHook<>0;
end;
=====================
//调用程序代码
procedure THideForm.Button1Click(Sender: TObject);
begin
if EnableHideHook(HideForm.Handle) then
showMessage('HotKy Testing...');
end;
=====================
现在问题是,只有调用程序为当前窗口,才能正常显示/隐藏该窗口,否则发送的showMessage(),就没有用处。
请大家帮忙解决。
function KeyboardHookHandler(iCode: Integer;wParam:
WPARAM; lParam: LPARAM): LRESULT;stdcall;export;
const _KeyPressMask=$80000000;
//var
//f:textfile;
//temp:string;
begin
result:=0;
if iCode<0 then
Result:=CallNextHookEx(hHook,iCode,wParam,lParam);
//侦测Ctrl+Alt+F12组合键
if ((lParam and _KeyPressMask)=0)
and (GetKeyState(vk_Control)<0)
and (getKeyState(vk_menu)<0) and (wParam=vk_F12) then
begin
if HideHook then
begin
showmessage('HideHook:true;显示');
showWindow(hbefore,SW_SHOW);
hideHook:=false;
end
else
begin
showmessage('HideHook:false;隐藏');
showWindow(hbefore,SW_HIDE);
hideHook:=true;
end
end;
end;
//-这里hbefore是由调用程序传过来的,程序窗口句柄。
function EnableHideHook(hFrmHandle:longint):BOOL; export;
begin
Result:=false;
if hHook<>0 then
exit;//已经有一个HOOK存在
hHook:=SetWindowsHookEx(WH_KEYBOARD,KeyboardHookHandler,HInstance,0);
hbefore:=hFrmHandle;
Result:=hHook<>0;
end;
=====================
//调用程序代码
procedure THideForm.Button1Click(Sender: TObject);
begin
if EnableHideHook(HideForm.Handle) then
showMessage('HotKy Testing...');
end;
=====================
现在问题是,只有调用程序为当前窗口,才能正常显示/隐藏该窗口,否则发送的showMessage(),就没有用处。
请大家帮忙解决。
解决方案 »
- 大家用delphi开发ocx有没这种感觉?
- 捕获不到ClientDataSet执行SQL语句时的错误?
- 请问delphi中的is和as在cb中该怎样写?????
- 请问有没有介绍Object Pascal 方面的书?
- 我的数据库记录怎么老丢失啊?新手吐血求教
- 我是新手,怎么样做登陆窗口
- 如何得到某个目录下的所有文件的文件名呢?小弟初学D,望指教!第一次提问,分就100吧
- 怎样在下拉框中放置树型控件
- 散分,顺便做广告~~~~~
- 请教高手:Delphi中的异常问题...
- 大虾们好:DATASET里用 FILTER ,想达到 name like '%sth%'的功能,如何填写 FILTER 呢? 能:name = '*sth*' ?
- 日你妈的腾讯,从今天起拒绝QQ
解决可以有不同的途径:
1.不传入handle,而是在钩子中通过FindWindow得到需要操作窗口的handle
2.传入handle,开辟一块进程间共享的内存保存该值
3.只是想给自己的开发的软件增加一些快捷健功能的话,那不必用钩子来实现这样的功能,在程序里面使用GetKeyState就可以了,不用写dll,只是需要放在一个定时器里面。
不知道直接用GetKeyState是否可以,做个死循环不停地Getkeystate,不知能否在游戏状态下也能用,现在没机会测试,搂主可以试试看