I want to build a MaskEdit for a TextBox it's pretty much done.
The mask will be displayed as the user enters character into the TextBox. The problem I am having is with Backspacing charters. I can seem to get the cursor to move to the correct location after the backspace key is pressed.
I thought trapping the cursor location I would be able to place the cursor at the correct location. Paul, had provided some code the should give the current location of the cursor. I appearently don't understand how to use it because it always returns 0 for the starting and ending positions. Here's a snippit of the code:
Local t As String
Local a, c As Long
Local cPos, lresult As Long
Local nStartPos As Long
Local nEndPos As Long
SendMessage cHndl, %EM_GETSEL, VarPtr(nStartPos), VarPtr(nEndPos) To lResult
t = ""
cPos = Lo(Word, lResult)
FF_TextBox_SetText (HWND_FORM1_Text3, Str$(Hi(Word, lResult))) 'Str$(nEndPos))
FF_TextBox_SetText (HWND_FORM1_Text4, 'Str$(Lo(Word, lResult))) 'Str$(nStartPos))
The whole project is attached if you would like to mess with it. (It's small just a test program for this mask edit function.
The problem is that you are using FF_TextBox_SetText for the control during that control's EN_CHANGE message. When you set the text of the TextBox, it will fire the EN_CHANGE message again! Therefore, you are firing another EN_CHANGE before the first on gets a chance to complete.
An easy way to work around this is to have a static flag in your EN_CHANGE message to filter out the second message.
Function FORM1_TEXT1_EN_CHANGE ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idTextControl As Long _ ' identifier of text control
) As Long
Static fChange As Long
If fChange = 0 Then
fChange = 1
mDateMMDDYYYY (HWND_FORM1_Text1)
fChange = 0
End If
End Function
Just to be clear... FF_TextBox_SetText is not the problem here. Even if you used SetWindowText or the WM_SETTEXT message, you would still have the exact same problem.
Yes, yes, yes... Thank you Paul Thank you.
I struggled an number of hours trying to figure out where I was going wrong. I probably would have given up if it wasn't for your help. Thank you.
Now, the process works as intended. After I put this solution into the other Mask edit functions I will repost the MaskEdit Functions for others to benefit.