Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
Declare Function WinMsg Lib "WINMSG.DLL" Alias "WindowMessageA" (ByVal MsgNum As Long) As String
Global hDlg,hConsole,ghHook As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Toolbar Test",400,400,400,300, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
ghHook = SetWindowsHookEx(%WH_Mouse, CodePtr(MouseProc), GetModuleHandle(""), GetCurrentThreadId)
Case %WM_Destroy
UnhookWindowsHookEx ghHook '<---- As a minumum, unhook here - sooner is recommended
End Select
End Function
Function MouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
CPrint WinMsg(wParam)
Function = CallNextHookEx(ByVal ghHook, ByVal nCode, ByVal wParam, ByVal lParam)
If nCode < 0 Then Exit Function 'prevent from doing stuff below
'do stuff ...
'UnhookWindowsHookEx ghHook '<---- unhook as soon as possible, but doesn't have to be here
End Function
Sub CPrint (SOut As String)
Static cWritten,iCount As Long
Incr iCount
SOut = Format$(iCount,"000000") + SOut
If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
End Sub
'gbs_00972
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm