How to capture WM_CANCELJOURNAL message

Posted on 2006-05-03
Last Modified: 2012-06-21
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
Question by:gem56
    LVL 26

    Expert Comment


    Author Comment

    Hi EDDYKT,
    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?

    LVL 26

    Accepted Solution


    Author Comment

    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.


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now