使用Microsoft Spy++,我看到当您打开/创建一个新文档时,Notepad++会收到一条WM_SETTEXT消息。我需要在Windows上挂载标题更改,所以我尝试做WH_GETMESSAGE钩子,并且只过滤WM_SETTEXT。但到目前为止我还没成功。这是我的DLL:
uses
System.SysUtils,
Windows,
Messages,
System.Classes;
var
CurrentHook: HHOOK;
{$R *.res}
function GetMessageHookProc(Code: Integer; iWParam: WPARAM; iLParam: LPARAM): LRESULT; stdcall;
begin
Result:= CallNextHookEx(CurrentHook, Code, iWParam, iLParam);
if (Code = HC_ACTION) and (PMSG(iLParam).message = wm_settext) then
begin
MessageBox(0, 'WM_SETTEXT', 'WM_SETTEXT', MB_OK);
//this code below is just a prototype to what I will try when this works:
if IntToStr(PMSG(iLParam).lParam) = 'new - Notepad++' then
MessageBox(0, 'Notepad++', 'Notepad++', MB_OK);
end;
end;
procedure SetHook; stdcall;
begin
CurrentHook:= SetWindowsHookEx(WH_GETMESSAGE, @GetMessageHookProc, HInstance, 0);
if CurrentHook <> 0 then
MessageBox(0, 'HOOKED', 'HOOKED', MB_OK);
end;
procedure UnsetHook; stdcall;
begin
UnhookWindowsHookEx(CurrentHook);
end;
exports
SetHook,
UnsetHook;
begin
end.
我得到了“钩子”消息框,表示钩子已经解决了,但是在回调过程的if中,我从来没有得到'WM_SETTEXT‘消息框。如何只过滤这类消息,并检查消息的字符串?
谢谢!
发布于 2016-02-18 16:40:16
WM_SETTEXT
是已发送的消息,而不是已发布的消息。WH_GETMESSAGE
钩子只看到发送到目标线程的消息队列的消息,因此它将永远不会看到WM_SETTEXT
消息。若要挂起直接发送到窗口而不经过消息队列的消息,您需要使用WH_CALLWNDPROC
或WH_CALLWNDPROCRET
钩子。
https://stackoverflow.com/questions/35487224
复制相似问题