Page 1 of 1

Detecting lostfocus type events from combobox gadgets

Posted: Tue Dec 02, 2003 11:11 pm
by Karbon
Code updated for 5.20+

Many thanks to fr34k as this is all his work!

Code: Select all

#Combo = 0
#Text = 1  ; to loose the focus to

Procedure.l Callback(Window, Message, wParam, lParam)
	result = #PB_ProcessPureBasicEvents
	
	If Message = #WM_COMMAND 
		
		If (wParam>>16) = #CBN_KILLFOCUS And lParam = GadgetID(#Combo)
			Debug "Gadget lost focus"
			
		ElseIf (wParam>>16) = #CBN_SETFOCUS And lParam = GadgetID(#Combo)
			Debug "Gadget has focus"
			
		EndIf
		
	EndIf
	
	ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 400, 100, "ComboBox focus", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
	
	SetWindowCallback(@Callback())
	
	ComboBoxGadget(#Combo, 10, 10, 380, 300)
	AddGadgetItem(#Combo, -1, "Item Number 0")
	AddGadgetItem(#Combo, -1, "Item Number 1")
	AddGadgetItem(#Combo, -1, "Item Number 2")
	AddGadgetItem(#Combo, -1, "Item Number 3")
	
	StringGadget(#Text, 10, 40, 380, 20, "")
	
	
	Repeat
		Event = WaitWindowEvent()
	Until Event = #PB_Event_CloseWindow
	
EndIf

End

Posted: Tue Dec 02, 2003 11:21 pm
by freak
lol, i was just about to post that :mrgreen:

Timo

Posted: Tue Dec 02, 2003 11:47 pm
by Karbon
I'm SPEEDY FAST!

Thanks again, it's working like a charm!

Re: Detecting lostfocus type events from combobox gadgets

Posted: Sat Oct 01, 2016 2:27 pm
by IdeasVacuum
The code doesn't work in PB5.43LTS because #CBN_KILLFOCUS is unknown, but GetActiveGadget() can be used now.