Code : Tout sélectionner
; Windows XP only
; XP Theme enabled in compiler options
XIncludeFile "richedit.pb"
Macro IsFloat(c)
( ( (c>='0') And (c<='9') ) Or (c='.') )
EndMacro
If OpenWindow(0, 0, 0, 320, 240, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
TextGadget(1, 5, 5, 310, 18, "Amount :")
StringGadget(2, 5, 25, 310, 22, "", #PB_Text_Right)
TextGadget(3, 5, 55, 310, 18, "Filename :")
StringGadget(4, 5, 75, 310, 22, "")
EM_SetLimitText(GadgetID(2), 12)
EM_SetLimitText(GadgetID(4), #MAX_PATH)
Edit_SetCueBannerText(GadgetID(2), "<Enter an amount>")
Edit_SetCueBannerText(GadgetID(4), "<Enter a filename>")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 2
;// Amount Test
If EventType() = #PB_EventType_Change
curInput2.s = GetGadgetText(2)
EM_GetSel(GadgetID(2), @curPos1, @curPos2)
If curInput2
If IsFloat( Asc(Mid(curInput2, curPos1, 1)) )
If CountString(curInput2, ".") < 2
If Len(curInput2) = 12
Edit_ShowBalloonTip(GadgetID(2), "Field `Amount`", "The maximum number of caracters for an amount is fixed to 12 !", #TTI_INFO)
ElseIf Len(StringField(curInput2, 1, ".")) > 9
Edit_ShowBalloonTip(GadgetID(2), "Field `Amount`", "An amount is usually composed by a maximum of 9 digits before the point !", #TTI_WARNING)
ElseIf Len(StringField(curInput2, 2, ".")) > 2
Edit_ShowBalloonTip(GadgetID(2), "Field `Amount`", "An amount is usually composed by a maximum of 2 digits after the point !", #TTI_WARNING)
EndIf
oldInput2.s = curInput2
Else
Edit_ShowBalloonTip(GadgetID(2), "Field `Amount`", "Only one point is allowed !", #TTI_ERROR)
SetGadgetText(2, oldInput2)
EM_SetSel(GadgetID(2), CurPos1-1, CurPos2-1)
EndIf
Else
Edit_ShowBalloonTip(GadgetID(2), "Field `Amount`", "Allowed caracters : . 0 1 2 3 4 5 6 7 8 9", #TTI_ERROR)
SetGadgetText(2, oldInput2)
EM_SetSel(GadgetID(2), CurPos1-1, CurPos2-1)
EndIf
EndIf
EndIf
Case 4
;// Filename Test
If EventType() = #PB_EventType_Change
curInput4.s = GetGadgetText(4)
EM_GetSel(GadgetID(4), @curPos1, @curPos2)
If curInput4
If CheckFilename(curInput4)
If FindString(curInput4, " ", curPos1)
Edit_ShowBalloonTip(GadgetID(4), "Field `Filename`", "Spaces are allowed but it might cause problem with some program !", #TTI_INFO)
ElseIf Len(curInput4) = #MAX_PATH
Edit_ShowBalloonTip(GadgetID(4), "Field `Filename`", "The maximum number of caracters for a filename is fixed to "+Str(#MAX_PATH)+" !", #TTI_ERROR)
EndIf
oldInput4.s = curInput4
Else
Edit_ShowBalloonTip(GadgetID(4), "Field `Filename`", "Forbidden caracters : / \ : * ? < > | "+Chr(34), #TTI_ERROR)
SetGadgetText(4, oldInput4)
EM_SetSel(GadgetID(4), CurPos1-1, CurPos2-1)
EndIf
EndIf
EndIf
EndSelect
EndSelect
ForEver
EndIf