This is a way to get #PB_EventType_LostFocus events from spin gadgets.
Caution, it will not work if the spin gadget was created using #PB_Any.
It seems the gadget numbers are too large to fit in the Low word of wParam.
Code: Select all
; generate LostFocus events from spin gadgets
#WinMain = 0
Procedure WIN_CALLBACK(hWnd, uMsg, wParam, lParam)
; Window callback to generate LostFocus events for spin gadgets
Protected gadget
Select uMsg
Case #WM_COMMAND
Select wParam >> 16 ; get HiWord
Case #EN_KILLFOCUS
gadget = wParam & $FFFF ; get LoWord
If GadgetType(gadget) = #PB_GadgetType_Spin
PostEvent(#PB_Event_Gadget, #WinMain, gadget, #PB_EventType_LostFocus)
EndIf
EndSelect
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(#WinMain,0,0,400,250,"Spin gadget LostFocus events",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowCallback(@WIN_CALLBACK(),#WinMain)
SpinGadget(1,10,010,100,25,0,9999,#PB_Spin_Numeric) : SetGadgetText(1,"0")
SpinGadget(2,10,060,100,25,0,9999,#PB_Spin_Numeric) : SetGadgetText(2,"0")
SpinGadget(3,10,110,100,25,0,9999,#PB_Spin_Numeric) : SetGadgetText(3,"0")
SpinGadget(4,10,160,100,25,0,9999,#PB_Spin_Numeric) : SetGadgetText(4,"0")
ButtonGadget(#PB_Any,150,010,100,25,"1")
ButtonGadget(#PB_Any,150,060,100,25,"2")
ButtonGadget(#PB_Any,150,110,100,25,"3")
ButtonGadget(#PB_Any,150,160,100,25,"4")
CheckBoxGadget(#PB_Any,300,010,50,25,"1")
CheckBoxGadget(#PB_Any,300,060,50,25,"2")
CheckBoxGadget(#PB_Any,300,110,50,25,"3")
CheckBoxGadget(#PB_Any,300,160,50,25,"4")
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
If EventType() = #PB_EventType_LostFocus
Select EventGadget()
Case 1 : Debug "spin_1 lost focus"
Case 2 : Debug "spin_2 lost focus"
Case 3 : Debug "spin_3 lost focus"
Case 4 : Debug "spin_4 lost focus"
EndSelect
EndIf
Case #PB_Event_CloseWindow
exit = #True
EndSelect
Until exit
EndIf