How to capture WM_CANCELJOURNAL message
Posted on 2006-05-03
I have a 'System Hook' DLL that sets a hook for WH_GETMESSAGE and WH_JOURNALRECORD and all works OK with the exception of capturing WM_CANCELJOURNAL to stop the recording in my application by sending a special event (that I call CancelJournal in my code below).
I'm using Windows XP and when I press Ctrl Escape keys (simultaneously) the actual hook is deactivated in OS, because I output a message in the application status bar when events are coming in and following the Ctrl Escape the events stop coming. However, the GetMessageProc procedure doesn't seem to detect this activity and doesn't send the special (CancelJournal) event to my application so my application still thinks that the recording is on.
Below is the relevant code from the 'System Hook' DLL. I would appreciate any help on why the GetMessageProc doesn't detect WM_CANCELJOURNAL message.
Thanks a lot in advance,
P.S. I've left aout all the Playback related code as that works OK.
Public Event RecordEvent(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Event CancelJournal()
Public Function SetRecordHook(hInstance As Long, ThreadID As Long) As Boolean
If hAppHook = 0 Then hAppHook = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf GetMessageProc, App.hInstance, 0)
If hJournalHook = 0 Then hJournalHook = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf JournalRecordProc, App.hInstance, 0)
If (hAppHook <> 0) And (hJournalHook <> 0) Then
SetRecordHook = True
Friend Function FireRecordEvent(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long)
' This function handles recording of Journal messages
' by raising an event for the application to save.
RaiseEvent RecordEvent(nCode, wParam, lParam)
Friend Function SendCancelJournal()
' This routine fires an event to indicate cancel Journal.
Public Function JournalRecordProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' This routine is a handler for Journal Record calls.
If nCode < 0 Then
JournalRecordProc = CallNextHookEx(hJournalHook, nCode, wParam, lParam)
ResolvePointer(SHptr).FireRecordEvent nCode, wParam, lParam ' Destination should save the message
Call CallNextHookEx(hJournalHook, nCode, wParam, lParam)
Public Function GetMessageProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim msg As TMSG
If nCode < 0 Then
GetMessageProc = CallNextHookEx(hAppHook, nCode, wParam, lParam)
CopyMemory msg, ByVal lParam, Len(msg)
Select Case msg.message
If wParam = 1 Then ResolvePointer(SHptr).SendCancelJournal
Call CallNextHookEx(hAppHook, nCode, wParam, ByVal lParam)
Private Function ResolvePointer(ByVal lpObj&) As cGemSysHook
Dim oSH As cGemSysHook
CopyMemory oSH, lpObj, 4&
Set ResolvePointer = oSH
CopyMemory oSH, 0&, 4&