我正在使用 C#,并且我已经让程序使用SetWindowsHookEx
with成功记录了日志消息WH_JOURNALRECORD
。
我的问题在该停下来的时候出现了。文档显示,如果用户按下 CTRL-ESC 或 CTRL-ALT-DELETEWM_CANCELJOURNAL
将发布一条消息,我可以查看该消息以了解何时停止。我的应用程序未绑定,但我似乎从未获得WM_CANCELJOURNAL
.
我有两个钩子设置。一个用来做日志记录的钩子和一个用来检查取消消息的钩子:
IntPtr hinstance = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
JournalRecordProcedure = JournalRecordProc;
journalHook = SetWindowsHookEx(WH_JOURNALRECORD, JournalRecordProcedure, hinstance, 0);
GetMessageProcedure = GetMessageProc;
messageHook = SetWindowsHookEx(WH_GETMESSAGE, GetMessageProcedure, hinstance, 0);
------
public static int JournalRecordProc(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0) return CallNextHookEx(journalHook, nCode, wParam, lParam);
EventMsgStruct msg = (EventMsgStruct) Marshal.PtrToStructure(lParam, typeof (EventMsgStruct));
script.Add(msg); //just a quick way to record for now
return CallNextHookEx(journalHook, nCode, wParam, lParam);
}
public static int GetMessageProc(int code, IntPtr wParam, IntPtr lParam)
{
//it comes here but how do I test if it's WM_CANCELJOURNAL ??
//code always seems to be equal to zero.. I must be missing something
return CallNextHookEx(journalHook, code, wParam, lParam);
}