HOOK的热键已经可以正常截获,但是不知道该怎么让主窗口显示/隐藏
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(),就没有用处。
请大家帮忙解决。