Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WMLiberty Demos - Decimal Number Textbox
 
WMLiberty -> Demos -> Customized Controls -> Decimal Number Textbox (Download)

Code:
' Decimal Number Textbox Demo
' By Brent D. Thorn, 8/2015
' Demonstrates how to limit a textbox to allow only digits and a decimal point.
' PUBLIC DOMAIN

Open "WMLiberty" For DLL As #wmlib

StaticText #demo, "Enter a number", 5, 5, 300, 20
TextBox    #demo.num, 5, 25, 300, 20
StaticText #demo, "Enter some text", 5, 45, 300, 20
TextBox    #demo.text, 5, 65, 300, 20

Open "Decimal Number Textbox Demo" For Dialog As #demo
#demo "TrapClose [Quit]"

Callback lpfn, OnChar(ULong, ULong, ULong, ULong), Long
hWnd = HWnd(#demo.num)
CallDLL #wmlib, "SetWMHandler", hWnd As ULong, _WM_CHAR As ULong, lpfn As ULong, 0 As Long, r As Long

[Wait]
    CallDLL #kernel32, "Sleep", 1 As Long, r As Void
    Scan
    GoTo [Wait]

[Quit]
    Close #demo
    Close #wmlib
    End

Function OnChar(hWnd, uMsg, wParam, lParam)
    ' Test for various character codes.
    Select Case wParam
    Case 8, 13, 27, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57
        ' Disallow multiple decimal points.
        If wParam = 46 Then
            ' Get textbox contents. The old way is faster.
            Print #demo.num, "!Contents?"
            Input #demo.num, text$
            If InStr(text$, ".") Then [bad]
        End If

        ' Let the character through.
        OnChar = wParam
        Exit Function
    End Select

[bad]
    CallDLL #user32, "MessageBeep", -1 As Long, r As Long
End Function

Powered by phpBB © 2001, 2005 phpBB Group