Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const CB_LIMITTEXT = &H141
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function SetWindowText Lib "user32" _
Alias "SetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String) As Long
Private Sub Command1_Click()
Dim maxEditLength As Long
'how many chrs to allow
maxEditLength = CLng(Text1.Text)
'clear existing text
Call SetWindowText(Combo1.hwnd, "")
'set the limit
Call SendMessage(Combo1.hwnd, CB_LIMITTEXT, maxEditLength, ByVal 0&)
End Sub
Private Sub Command2_Click()
'clear existing text
Call SetWindowText(Combo1.hwnd, "")
'reset to the control default
Call SendMessage(Combo1.hwnd, CB_LIMITTEXT, 0&, ByVal 0&)
End Sub
|
Pressing the Limit button will restrict user input into
the Style-0 or Style-1 combo to the value passed as maxEditLength. Passing 0& as wParam, as in the Command2 routine, removes the input
restriction.
The MSDN has the following notes on CB_LIMITTEXT:
If the combo box does not have the CBS_AUTOHSCROLL style, setting
the text limit to be larger than the size of the edit control has no effect.
The CB_LIMITTEXT message limits only the text the user can enter.
It has no effect on any text already in the edit control when the message is sent, nor does it affect the length of the text copied to the
edit control when a string in the list box is selected.
The default limit to the text a user can enter in the edit control
is 30,000 characters.
The value of wParam specifies the maximum number of characters the
user can enter. If this parameter is zero, the text length is set to 0x7FFFFFFE (2147483646) characters.
The return value is always TRUE.
|