How to capture WM_CANCELJOURNAL message

Hi experts,
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
    End If
End Function

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)
End Function

Friend Function SendCancelJournal()
' This routine fires an event to indicate cancel Journal.
    RaiseEvent CancelJournal
End Function

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)
     Exit Function
  End If
  ResolvePointer(SHptr).FireRecordEvent nCode, wParam, lParam               ' Destination should save the message
  Call CallNextHookEx(hJournalHook, nCode, wParam, lParam)
End Function

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)
      Exit Function
   End If
   CopyMemory msg, ByVal lParam, Len(msg)
   Select Case msg.message
            If wParam = 1 Then ResolvePointer(SHptr).SendCancelJournal
   End Select
   Call CallNextHookEx(hAppHook, nCode, wParam, ByVal lParam)
End Function

Private Function ResolvePointer(ByVal lpObj&) As cGemSysHook
  Dim oSH As cGemSysHook
  CopyMemory oSH, lpObj, 4&
  Set ResolvePointer = oSH
  CopyMemory oSH, 0&, 4&
End Function
Who is Participating?
gem56Author Commented:
Thanks for yoiur response. I originally based my code on the code you suggested and some other examples however even running the (above) example as is, I'm still not able to trap WM_CANCELJOURNAL message.

Any more suggestions?

gem56Author Commented:
Thanks EDDYKT,
I wasn't able to use the examples from the above links as they were but they gave me ideas to resolve the problem.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.