[bmx] Simple Query by Zakk [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

Title : Simple Query
Author : Zakk
Posted : 1+ years ago

Description : Simple query window designed to be used like the BRL.System commands like Prompt and RequestFile. Asks the user for a string and returns the result.

Example usage:
Code: BASIC
'query example.bmx

Import MaxGui.Drivers
Include "query.bmx"

input_text:String=Query("Enter a string.", "Default")
Notify "User entered: '"+input_text+"'"

End


Code :
Code: blitzmax
'query.bmx, requires maxgui

'=============================
Global query_window:TGadget=CreateWindow("Query", 0, 0, 182, 58, Null, WINDOW_CENTER|WINDOW_TITLEBAR|WINDOW_TOOL|WINDOW_CLIENTCOORDS|WINDOW_HIDDEN)
Global query_field:TGadget=CreateTextField(4, 4, 174, 22, query_window)
Global query_okay:TGadget=CreateButton("Okay", 4, 30, 85, 24, query_window)
Global query_cancel:TGadget=CreateButton("Cancel", 93, 30, 85, 24, query_window)
'=============================
Function Query:String(text:String, initial:String)
Local id:Int, es:Object
	SetGadgetText(query_window, text)
	SetGadgetText(query_field, initial)
	ActivateGadget(query_field)
	ShowGadget query_window
	Repeat
		id=WaitEvent()
		es=EventSource()
		Select id
			Case EVENT_WINDOWCLOSE
				Select es
					Case query_window
						HideGadget query_window
						Return initial
					Default
				End Select
			Case EVENT_WINDOWACTIVATE
				Select es
					Case query_window
					Default
						ActivateGadget(query_window)
				End Select
			Case EVENT_GADGETACTION
				Select es
					Case query_okay
						HideGadget query_window
						Return GadgetText(query_field)
					Case query_cancel
						HideGadget query_window
						Return initial
				End Select
			Default
		End Select
	Forever
End Function
'=============================


Comments : none...