Enumeration #formMain EndEnumeration Enumeration #buttonTest #buttonClose #maskMain #maskTest #maskSimple #textInfo EndEnumeration XIncludeFile "xMask.pb" ;- Even Procedure Procedure fMainNotifyChange01(inGadgetID.l, MaskedText.s) ; This will be the Change Event procedure for #maskMain. You can set the event procedures ; to do whatever you want with the procedure itself as long as the parameter types are the ; same. Unless you modify the xMask procedures to react differently, the Change Event will ; always expect and pass the xMask gadget id as a long and the new xMask text as a string. SetGadgetText(#textInfo, "Event! Changed xMask Gadget #1: "+MaskedText) ; Do some stuff... EndProcedure Procedure fMainNotifyChange02(inGadgetID.l, MaskedText.s) ; See fMainNotifyChange01 - this is for #maskTest and #maskSimple. I'm using 1 procedure ; for both xMask gadgets just to show you that it can be done. If inGadgetID = #maskTest SetGadgetText(#textInfo, "Event for maskTest! Changed xMask Gadget #2: "+MaskedText) ElseIf inGadgetID = #maskSimple SetGadgetText(#textInfo, "Event for maskSimple! Changed xMask Gadget #2: "+MaskedText) EndIf EndProcedure Procedure fMainNotifyBadKey(inGadgetID.l, Mask.s, BadKey.s, ErrorType.l) ; Again, you can name the procedure what you want but unless you modify the xMask.pb code you'll ; need to keep the parameter types the same (although you can change the names if you like. If inGadgetID = #maskMain MessageRequester("xMask Error", "Error! The key '"+BadKey+"' fails the mask '"+Mask+"' for #maskMain.") ElseIf inGadgetID = #maskSimple If ErrorType = 0 ; Error by physically typing. MessageRequester("xMask Error", "Error! The key '"+BadKey+"' fails the mask '"+Mask+"' for #maskMain.") ElseIf ErrorType = 1 ; Error by pasting. MessageRequester("xMask Error", "Error! Trying to paste '"+BadKey+"' fails the mask '"+Mask+"' for #maskMain.") EndIf EndIf ; EndProcedure Procedure fMainNotifyReturn(inGadgetID.l, MaskedText.s) ; This will fire when the user presses the return key. SetGadgetText(#textInfo, "You pressed return in #maskMain!: "+MaskedText) xmActivate(#maskTest, #True) ; Just for the heck of it. EndProcedure Procedure fMainNotifyLostFocus(inGadgetID.l, MaskedText.s) ; This will fire when our xMask gadget loses focus. SetGadgetText(#textInfo, "The #maskSimple gadget lost focus!: "+MaskedText) EndProcedure ;- Main program If OpenWindow(#formMain, 216, 0, 450, 150, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Test") ; If CreateGadgetList(WindowID()) ; ButtonGadget(#buttonTest, 220, 110, 75, 18, "Test") ButtonGadget(#buttonClose, 220, 130, 75, 18, "Close") ; xmCreate(#maskMain, WindowID(), 5, 5, 120, 18, "000-00-0000", "371983719", Asc("_")) ; Simple Social Security mask. xmCreate(#maskTest, WindowID(), 5, 30, 120, 18, "->LLLLLL-", "xombie", Asc("*")) ; Little test to show a alpha mask. xmCreate(#maskSimple, WindowID(), 5, 55, 120, 18, "#Financial", "1000.5498", Asc("_")) ; And a phone number mask. TextGadget(#textInfo, 5, 80, 445, 18, "") ; Create a simple text gadget. EndIf ; EndIf doQuit.b EventID.l ;{ Set xMask Options xmSetChangeEvent(#maskMain, @fMainNotifyChange01()) xmSetChangeEvent(#maskTest, @fMainNotifyChange02()) xmSetChangeEvent(#maskSimple, @fMainNotifyChange02()) ; Now set three event procedures - a different one for each xMask gadget. Watch the text gadget when you make a change in the xMask gadget :D xmSetBadKeyEvent(#maskMain, @fMainNotifyBadKey()) xmSetBadKeyEvent(#maskSimple, @fMainNotifyBadKey()) ; Now set the events for bad key entries. xmSetReturnEvent(#maskMain, @fMainNotifyReturn()) xmSetLostFocusEvent(#maskSimple, @fMainNotifyLostFocus()) ; Now set up our example lost focus and return key events. xmSelectAllOnFocus(#maskSimple, #True) ; When we select the financial gadget, select all the text. Only works by tabbing, not clicking in the control with the mouse. ;} Repeat ; EventID = WaitWindowEvent() ; Select EventID Case #PB_EventGadget Select EventGadgetID() Case #buttonClose If EventType() = #PB_EventType_LeftClick : doQuit = #True : EndIf Case #buttonTest ; If EventType() = #PB_EventType_LeftClick : xmSetGadgetText(#maskMain, "00000000") : Debug xmGetGadgetText(#maskMain) : EndIf ; If EventType() = #PB_EventType_LeftClick : xmForceGadgetText(#maskMain, "2:34:56.789") : Debug xmGetGadgetText(#maskMain) : EndIf ; If EventType() = #PB_EventType_LeftClick : xmResizeGadget(#maskMain, -1, 80, 150, -1) : EndIf ; If EventType() = #PB_EventType_LeftClick : xmSetMask(#maskMain, "\090", "HIIIIIII", Asc("_")) : EndIf If EventType() = #PB_EventType_LeftClick : xmSetGadgetText(#maskSimple, "138 15711.511551") : EndIf EndSelect Case #PB_Event_CloseWindow doQuit = #True EndSelect ; Until doQuit = #True xmDestroyAll() ; Now destroy all created xMask gadgets. End ; jaPBe Version=2.5.4.22 ; FoldLines=000100030004000B000F00160017001F0020002F00300035003600390051005E ; Build=2 ; FirstLine=25 ; CursorPosition=95 ; ExecutableFormat=Windows ; Executable=C:\Programs\PureBasic\Code\xMask\xMask.exe ; DontSaveDeclare ; EOF