|
-
Aug 21st, 2001, 10:35 PM
#12
Fanatic Member
Someone brought up the API way to change the numbers only thing (I read all that once and didn't want to read it again, so I apologize for not giving a name), but this is how it's done. It's not as good for all cases though, as this way invalidates everything but numbers (it allows backspace and delete, but not periods, which some people may want for decimals). I took these out of a class I had myself which is somewhat like Nucleus's, but is more for giving a textbox some of the props that exist for edit controls, but aren't exposed with VB.
VB Code:
'this takes a reference to a textbox just like Nucleus's class did
'blnClassBound tells whether or not a textbox reference has been set yet
'in my clsTextBoxEx.SourceTextBox property set procedure
'txtSource is the class side textbox var
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const EM_SETREADONLY As Long = &HCF
Private Const ES_NUMBER As Long = &H2000
Private Const ES_READONLY As Long = &H800
Private Const GWL_STYLE As Long = -16
Public Property Get NumbersOnly() As Boolean
Dim lngStyle As Long
If Not blnClassBound Then Exit Property
lngStyle = GetWindowLong(txtSource.hWnd, GWL_STYLE)
NumbersOnly = CBool(lngStyle And ES_NUMBER)
End Property
Public Property Let NumbersOnly(ByVal blnNewNumbersOnly As Boolean)
Dim lngStyle As Long
If Not blnClassBound Then Exit Property
lngStyle = GetWindowLong(txtSource.hWnd, GWL_STYLE)
lngStyle = IIf(blnNewNumbersOnly, lngStyle Or ES_NUMBER, lngStyle And (Not ES_NUMBER))
SetWindowLong txtSource.hWnd, GWL_STYLE, lngStyle
End Property
'I had this in there before I even knew a textbox had a .Locked property
'but I'll include it anyway. someone may find a use for it
Public Property Get ReadOnly() As Boolean
Dim lngStyle As Long
If Not blnClassBound Then Exit Property
lngStyle = GetWindowLong(txtSource.hWnd, GWL_STYLE)
ReadOnly = CBool(lngStyle And ES_READONLY)
End Property
'SetWindowLong doesn't seem to make a textbox read only if you manually
'change the ES_READONLY flag for some reason, but SendMessage does get it
Public Property Let ReadOnly(ByVal blnNewReadOnly As Boolean)
If Not blnClassBound Then Exit Property
SendMessage txtSource.hWnd, EM_SETREADONLY, blnNewReadOnly, 0
End Property
I had a .GetLine(Index) prop too, but I remember getting a snag somewhere and ditched it. In that case, it was before I even knew of Split() (those were bad times indeed ), but I had an API way. I'm going to work on that again.
I remembered a while later I forgot one of the useful ones I intended to show in the first place...
VB Code:
Private Const EM_GETMODIFY As Long = &HB8
Private Const EM_SETMODIFY As Long = &HB9
Public Property Get Edited() As Boolean
If Not blnClassBound Then Exit Property
Edited = SendMessage(txtSource.hWnd, EM_GETMODIFY, 0, 0)
End Property
Public Property Let Edited(ByVal blnNewEdited As Boolean)
If Not blnClassBound Then Exit Property
SendMessage txtSource.hWnd, EM_SETMODIFY, blnNewEdited, 0
End Property
Private Sub txtSource_Change()
'this makes sure the edited flag is set, as I noticed there were times
'when changing text wouldn't make it apparent to the class for some reason
Me.Edited = True
End Sub
Last edited by Kaverin; Aug 21st, 2001 at 11:00 PM.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|