ComboBox whit editable : numberic chr only
Posted: Mon May 28, 2012 5:18 pm
hello
i need a editable combo box whit number input only.
i need a editable combo box whit number input only.
http://www.purebasic.com
https://www.purebasic.fr/english/
Something like this:Tomi wrote:hello
i need a editable combo box whit number input only.
Code: Select all
#ES_NUMBER=$2000
If OpenWindow(0, 0, 0, 270, 440, "Test ComboBoxGadget",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 20, #PB_ComboBox_Editable)
;--> Get the handle to the Edit control (child of the editable ComboBoxGadget)
hComboEdit = FindWindowEx_(GadgetID(0), #Null, "Edit", #Null)
SetWindowLongPtr_(hComboEdit, #GWL_STYLE, GetWindowLongPtr_(hComboEdit, #GWL_STYLE) | #ES_NUMBER)
AddGadgetItem(0, -1, "123")
AddGadgetItem(0, -1, "456")
AddGadgetItem(0, -1, "789")
AddGadgetItem(0, -1, "EDIT ME")
SetGadgetState(0,0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
Code: Select all
Procedure Win()
;--------------
If OpenWindow(0, 0, 0, 200, 140, "Combo Numbers",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ComboBoxGadget(1,10, 10,180,20,#PB_ComboBox_Editable)
AddGadgetItem(1,-1,"10")
AddGadgetItem(1,-1,"20")
EndIf
EndProcedure
Procedure WaitForUser()
;---------------------
sInput.s = ""
sNumber.s = ""
sChar.s = ""
Repeat
iEvent.i = WaitWindowEvent(1)
Select iEvent
Case #PB_Event_Gadget
If((EventGadget() = 1) And (EventType() = #PB_EventType_Change))
sInput = GetGadgetText(1)
iLen = Len(sInput)
sNumber = ""
For iCnt = 1 To iLen
sChar = Mid(sInput,iCnt,1)
iAscii = Asc(sChar)
iIncludeChar = #True
Select iAscii
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 ;Accepted numbers
Case 45, 46 ; Minus sign, accepted delimiter
Default: iIncludeChar = #False
EndSelect
If((iAscii = 45) And (iCnt > 1)) : iIncludeChar = #False : EndIf
If(iIncludeChar = #True) : sNumber = sNumber + sChar : EndIf
Next
iLen = (Len(sNumber) + 1)
SetGadgetText(1,"")
SetGadgetText(1,sNumber)
SendMessage_(GadgetID(1),#CB_SETEDITSEL,iLen,iLen)
SendMessage_(GadgetID(1),#CB_SETEDITSEL,-1,-1)
EndIf
EndSelect
Until iEvent = #PB_Event_CloseWindow
EndProcedure
;###Main Entry Point
Win()
WaitForUser()
End
Code: Select all
Global ComboGadgetSC
Procedure ComboGadgetProc(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_CHAR
If (wParam < 48 And wParam <> 8) Or wParam > 57
ProcedureReturn 0
EndIf
EndSelect
ProcedureReturn CallWindowProc_(ComboGadgetSC,hWnd,uMsg,wParam,lParam)
EndProcedure
If OpenWindow(0, 0, 0, 270, 440, "Test ComboBoxGadget",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 20, #PB_ComboBox_Editable)
hComboEdit = FindWindowEx_(GadgetID(0), #Null, "Edit", #Null)
ComboGadgetSC = SetWindowLongPtr_(hComboEdit,#GWL_WNDPROC,@ComboGadgetProc())
AddGadgetItem(0, -1, "123")
AddGadgetItem(0, -1, "456")
AddGadgetItem(0, -1, "789")
AddGadgetItem(0, -1, "EDIT ME")
SetGadgetState(0,0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
Code: Select all
Global gComboGadgetSC.i
Procedure ComboGadgetProc(hWnd,uMsg,wParam,lParam)
;------------------------------------------------
Select uMsg
Case #WM_CHAR
Select wParam
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 ;Accepted numbers
Case 45, 46 ; Minus sign, accepted delimiter
Default: ProcedureReturn 0
EndSelect
EndSelect
ProcedureReturn CallWindowProc_(gComboGadgetSC,hWnd,uMsg,wParam,lParam)
EndProcedure
Procedure Win()
;--------------
If OpenWindow(0, 0, 0, 270, 140, "ComboBox Floats",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(1, 10, 10, 250, 20, #PB_ComboBox_Editable)
ihComboEdit = FindWindowEx_(GadgetID(1), #Null, "Edit", #Null)
gComboGadgetSC = SetWindowLongPtr_(ihComboEdit,#GWL_WNDPROC,@ComboGadgetProc())
AddGadgetItem(1, -1, "123")
AddGadgetItem(1, -1, "456")
AddGadgetItem(1, -1, "789")
AddGadgetItem(1, -1, "EDIT ME")
SetGadgetState(1,3)
EndIf
EndProcedure
Win()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
Code: Select all
#ES_NUMBER=$2000
If OpenWindow(0, 0, 0, 270, 200, "Test ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 24, #PB_ComboBox_Editable)
;--> Get the handle to the Edit control (child of the editable ComboBoxGadget)
hComboEdit = FindWindowEx_(GadgetID(0), #Null, "Edit", #Null)
SetWindowLong_(hComboEdit, #GWL_STYLE, GetWindowLong_(hComboEdit, #GWL_STYLE) | #ES_NUMBER)
AddGadgetItem(0, -1, "123")
AddGadgetItem(0, -1, "456")
AddGadgetItem(0, -1, "789")
AddGadgetItem(0, -1, "EDIT ME")
SetGadgetState(0,0)
Repeat
If IsGadget(0)
SendMessage_(hComboEdit, #EM_HIDEBALLOONTIP, 0, 0)
EndIf
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
End
...as does my snippet that allows negative numbers/floats and performs the char-check in the loop.Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it.
Incidentally, the same across and got help to solve the issue of the ClearClipboard()MachineCode wrote:Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it.