WH_SHELL Hook无法识别Windows 8上的其他进程消息

时间:2014-05-18 03:32:13

标签: delphi winapi hook

我正在注意,当OneNote打开或设置为前景时。所以我搜索了我的旧源文件,发现了Hooks的DLL,它们在Win XP上完成了它们的工作。 但是,他们不会在Windows 8上。我从我自己的应用程序中获取消息,包括按钮和文本字段,但没有其他应用程序触发回调函数:-( 以管理员身份运行Hook-starting Exe不会改变问题。

var
HookHandle: Cardinal = 0;
WindowHandle : Cardinal = 0;

function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM):
LRESULT; stdcall;
var s:PChar;
begin
Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);

// debug if the callback function is triggerd...
SendMessage(WindowHandle,WM_USER+999,wParam,lParam);
case nCode < 0 of
TRUE: exit;
FALSE:
begin

  if nCode=HSHELL_WINDOWCREATED then begin
     SendMessage(WindowHandle,WM_USER+999,wParam,lParam);
    GetMem(s,GetWindowTextLength(wParam)+2);
    GetWindowText(wParam,s,GetWindowTextLength(wParam)+2);
    //if (AnsiEndsStr('OneNote',s)) then begin
    CallNextHookEx(HookHandle, nCode, wParam, lParam);
  end;
end;
end;
end;

function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
begin
Result := False;
if HookHandle = 0 then begin
HookHandle := SetWindowsHookEx(WH_SHELL, @HookProc, HInstance, 0);
WindowHandle := Hwnd;
Result := TRUE;
end;
end;

function UninstallHook: Boolean; stdcall;
begin
Result := UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;

exports
InstallHook,
UninstallHook;
end. 

0 个答案:

没有答案