查看文章 |
轻松实现限制用户输入类型
2008-05-09 16:37
Option Explicit Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Enum TextInputStyles ES_UPPERCASE = &H8& ES_LOWERCASE = &H10& ES_NUMBER = &H2000& End Enum Public Sub SetTextInputStyle(hWndTextControl As Long, InputStyle As TextInputStyles) Dim Style As Long Style = GetWindowLong(hWndTextControl, GWL_STYLE) Style = Style Or InputStyle SetWindowLong hWndTextControl, GWL_STYLE, Style End Sub Private Sub optStyle_Click(Index As Integer) Select Case Index Case 0: SetTextInputStyle txtTest.hWnd, ES_UPPERCASE Case 1: SetTextInputStyle txtTest.hWnd, ES_LOWERCASE Case 2: SetTextInputStyle txtTest.hWnd, ES_NUMBER End Select End Sub |
最近读者: