You can use this technique with any control and by responding to the right message implement what is missing natively in PB, in this case some messaging to let you know if you clicked / double clicked a field in the tray bar.
The number of the field were you clicked is also automatically determined without the need to hardcode the fields size in the routine.
OK, here it is.
Code: Select all
EnableExplicit
Macro LOWORD (word)
(word & $FFFF)
EndMacro
Macro HIWORD (word)
((word >> 16) & $FFFF)
EndMacro
Enumeration
#WIN_MAIN
#SBG_STATUS
EndEnumeration
Procedure StatusBar_GrabClickEvents_Subclass (hWnd, Msg, wParam, lParam)
Protected tRECT.RECT
Protected k, X, Y
Protected *fpFunc
Protected *oldWinProc = GetProp_(hWnd, "oldWinProc")
Select Msg
Case #WM_NCDESTROY
; cleanup
RemoveProp_(hWnd, "oldWinProc")
RemoveProp_(hWnd, "callback")
Case #WM_LBUTTONDBLCLK, #WM_RBUTTONDBLCLK, #WM_LBUTTONDOWN, #WM_RBUTTONDOWN
X = LOWORD (lParam) ; X mouse coordinates
Y = HIWORD (lParam) ; Y mouse coordinates
*fpFunc = GetProp_(hWnd, "callback") ; callback address
If *fpFunc > 0
While SendMessage_(hWnd, #SB_GETRECT, k, @tRECT)
If X < tRECT\right
; call callback procedure
CallFunctionFast(*fpFunc, Msg, k, X, Y)
Break
EndIf
k + 1
Wend
EndIf
EndSelect
ProcedureReturn CallWindowProc_(*oldWinProc, hWnd, Msg, wParam, lParam)
EndProcedure
Procedure StatusBar_GrabClickEvents (hWnd, *fpFunc)
SetProp_(hWnd, "oldWinProc", GetWindowLongPtr_(hWnd, #GWL_WNDPROC))
SetProp_(hWnd, "callback", *fpFunc)
SetWindowLongPtr_(hWnd, #GWL_WNDPROC, @StatusBar_GrabClickEvents_Subclass())
EndProcedure
; *** TEST ***
; this procedure process the click events
Procedure SBClickEvents (iMessage, iField, iXPos, iYPos)
Select iMessage
Case #WM_RBUTTONDOWN
Debug "RMB pressed on " + Str(iField) + " at (" + Str(iXPos) + ", " + Str(iYPos) + ")"
Case #WM_LBUTTONDOWN
Debug "LMB pressed on " + Str(iField) + " at (" + Str(iXPos) + ", " + Str(iYPos) + ")"
Case #WM_LBUTTONDBLCLK
Debug "LMB double clicked on " + Str(iField) + " at (" + Str(iXPos) + ", " + Str(iYPos) + ")"
Case #WM_RBUTTONDBLCLK
Debug "RMB double clicked on " + Str(iField) + " at (" + Str(iXPos) + ", " + Str(iYPos) + ")"
EndSelect
EndProcedure
Procedure Main()
Protected iEvent
Protected hStatus
If OpenWindow(#WIN_MAIN, 10, 10, 640, 480, "Main Window", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
hStatus = CreateStatusBar(#SBG_STATUS, WindowID(#WIN_MAIN))
AddStatusBarField(100) ; width 100
AddStatusBarField(200) ; width 200
AddStatusBarField(#PB_Ignore) ; autosize
; this call does the work
StatusBar_GrabClickEvents (hStatus, @SBClickEvents())
Repeat
iEvent = WaitWindowEvent()
Until iEvent = #PB_Event_CloseWindow
EndIf
EndProcedure
Main()