A Conversation for The H2G2 Programmers' Corner
Windopws Hook help - WH_CBT
Is mise Duncan Started conversation Jul 26, 2002
Hi,
I have written a WH_CBT hook handling code and it works OK except for where Code = WHCBT_SYSCOMMAND...which causes a GPF.
The code (snippet) is ...
'--8<---------------------------------------------------------------
Case HOOKPROC_CBT '<--CBT Hook is triggered
Code = Arguments(1)
wParam = Arguments(2)
lParam = Arguments(3)
Select Case Code '<--What type of message?
'....
Case Case Code = HCBT_SYSCOMMAND
Dim ptMouse As New APIPoint
Dim activeBy As SystemCommandActivationMethods
Select Case APIDispenser.HiWord(lParam)
Case 0
activeBy = SCAM_BYMNEMONIC
Case -1
activeBy = SCAM_BYSYSACCELERATOR
Case Else
activeBy = SCAM_BYMOUSE
ptMouse.y = APIDispenser.HiWord(lParam)
ptMouse.x = APIDispenser.LoWord(lParam)
End Select
'\\ Only the upper 3 bytes are used - the lower 4 are reserved for the system...
wParam = (wParam And &HFFF0)
Select Case wParam
Case SC_HOTKEY
'\\ A window is being activated by a hotkey
wndThis.hWnd = lParam
RaiseEvent ActivateWindowByHotkey(wndThis, Cancel)
Case SC_TASKLIST
RaiseEvent StartMenu(activeBy, ptMouse, Cancel)
Case SC_MONITORPOWER
If lParam = 1 Then
RaiseEvent MonitorLowPower(activeBy, ptMouse, Cancel)
ElseIf lParam = 2 Then
RaiseEvent MonitorPowerOff(activeBy, ptMouse, Cancel)
End If
Case SC_CONTEXTHELP
RaiseEvent InitiateContextHelp(activeBy, ptMouse, Cancel)
'.......
End Select
If Cancel Then
Arguments(4) = 1
End If
'.......
'--8<--------------------------------------------------------------
Does anybody have any experience of this hook proc that could guide me to finding the source of the GPF?
Windows Hook help - WH_CBT [Resoved]
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Jul 26, 2002
What does it do?
-- DoctorMO --
Windows Hook help - WH_CBT [Resoved]
Is mise Duncan Posted Jul 26, 2002
The WH_CBT hook is called whenever one of a number of events that is of use to a computer based training application occurs. For example, when a new window is created, when the user switches between windows, when the screensaver kicks in etc.
However I am using it to write a remote monitoring/debugging tool for one of the work apps we use here. The idea is that the hook (and a WH_JOURNALRECORD hook) will record what the user is doing in the app and save this as a log file. Then the developer can play back this log in the development environment and (hopefully) reproduce whatever behaviour the user was reporting.
The WH_JOURNALRECORD hook was quite easy, but the CBT one is giving me lots of grief...and the documentation is a bit sparce
Windows Hook help - WH_CBT [Resoved]
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Jul 26, 2002
Looks like fun, would you beable to have Remote access Via the hooks?
-- DoctorMO --
Windows Hook help - WH_CBT [Resoved]
Is mise Duncan Posted Jul 27, 2002
You can connect the hooks via TCP/IP on WinSock (or network protocol of choice) but the software must be installed on client and server - you couldn't spy on someone without their knowing it. Also hooks involve a performance hit - it is best to use them sparingly....
Windows Hook help - WH_CBT [Resoved]
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Jul 27, 2002
Ah,
--DoctorMO --
Windows Hook help - WH_CBT [Resoved]
Is mise Duncan Posted Jul 27, 2002
Ah indeed...
*goes to get another whisky..*
Windows Hook help - WH_CBT [Resoved]
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Jul 28, 2002
Wounder if you could do the same in Linux??
-- DoctorMO --
Windows Hook help - WH_CBT [Resoved]
Is mise Duncan Posted Jul 28, 2002
I'm not to knowledgeable about Linux..., but the new EventVB version H is fixed to do CBT hooks..
Option Explicit
Dim WitheEvents vbLink As EventVB.ApiFunctions
Dim WithEvents vbHook As EventVB.ApiSystemHook
Private Sub Form_Load()
Set vbLink = New ApiFunctions
Set vbHook = vbLink.System.Hooks
vbHook.StartHook WH_CBT, HOOK_PROCESS_LOCAL
End Sub
Windows Hook help - WH_CBT [Resoved]
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Jul 28, 2002
Looks alot easier, but whats this New VB?
-- DoctorMO --
Windows Hook help - WH_CBT [Resoved]
Is mise Duncan Posted Sep 16, 2002
Not new VB - a DLL wot I wrote to make this API stuff a bit easier. Bit of a moot point though, as we're all going .Net now...
The dll is at http://www.merrioncomputing.com/EventVB/Release_H.htm fyi...
Windows Hook help - WH_CBT [Resoved]
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Sep 16, 2002
Ah I see, looks usefull, but yes .NET train is here and we'er all paying microsoft for the journey, coffe and window room.
-- DoctorMO --
Key: Complain about this post
Windopws Hook help - WH_CBT
- 1: Is mise Duncan (Jul 26, 2002)
- 2: Is mise Duncan (Jul 26, 2002)
- 3: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Jul 26, 2002)
- 4: Is mise Duncan (Jul 26, 2002)
- 5: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Jul 26, 2002)
- 6: Is mise Duncan (Jul 27, 2002)
- 7: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Jul 27, 2002)
- 8: Is mise Duncan (Jul 27, 2002)
- 9: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Jul 28, 2002)
- 10: Is mise Duncan (Jul 28, 2002)
- 11: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Jul 28, 2002)
- 12: Is mise Duncan (Sep 16, 2002)
- 13: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Sep 16, 2002)
More Conversations for The H2G2 Programmers' Corner
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."