【发布时间】:2016-02-18 16:35:15
【问题描述】:
使用 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.
我收到“HOOKED”消息框,表明挂钩已解决,但我从未在回调过程的 if 中收到“WM_SETTEXT”消息框。如何只过滤这种消息,并检查消息的字符串?
谢谢!
【问题讨论】: