|
-
Feb 8th, 2005, 10:50 PM
#1
Thread Starter
Hyperactive Member
Trapping [BACKSPACE] (subclassing)
I'm subclassing a richtextbox so I can replace some keypresses with others (like changing a TAB to four spaces). My problem is that I cannot prevent the backspace character from reaching the richtextbox. I have succeeded in preventing the TAB key, that works fine.
When the backspace key is pressed, three messages are sent to the window:
WM_KEYDOWN
WM_KEYUP
WM_CHAR
I have my code blocking those at the moment, same method as blocking the TAB key, but to no effect. Is there something different about the backspace message? My code is below:
VB Code:
Dim WasProcessed As Boolean
WasProcessed = False
Dim StartSel As Long, Temp As String, PrevLineSpaces As Integer, PrevLineTabs As Integer
StartSel = frmMain.txtDocument.SelStart
PrevLineSpaces = 0
PrevLineTabs = 0
Select Case Msg
Case WM_KEYDOWN
Select Case wp
Case 8 '[BACKSPACE] is pressed
If frmMain.TabsAsSpaces = True Then
End If
Case 9 '[TAB] Is Pressed
If frmMain.TabsAsSpaces Then
WasProcessed = True
frmMain.txtDocument.Text = Mid(frmMain.txtDocument.Text, 1, StartSel) & String(frmMain.AmountOfSpacePerTab, " ") & Mid(frmMain.txtDocument.Text, StartSel + 1)
frmMain.txtDocument.SelStart = StartSel + frmMain.AmountOfSpacePerTab
End If
End Select
Case WM_KEYUP
If frmMain.TabsAsSpaces And wp = 8 Then WasProcessed = True
If frmMain.TabsAsSpaces And wp = 9 Then WasProcessed = True
Case WM_CHAR
If frmMain.TabsAsSpaces And wp = 8 Then WasProcessed = True
If frmMain.TabsAsSpaces And wp = 9 Then WasProcessed = True
Case WM_DEADCHAR
If frmMain.TabsAsSpaces And wp = 8 Then WasProcessed = True
If frmMain.TabsAsSpaces And wp = 9 Then WasProcessed = True
End Select
If Not WasProcessed Then
'Default processing...
CallWindowProc OldProcAddy, SubClasshWnd, Msg, wp, lp
WindowProc = DefWindowProc(SubClasshWnd, Msg, wp, lp)
End If
"I don't want to live alone until I'm married" - M.M.R.P
-
Feb 8th, 2005, 10:52 PM
#2
Thread Starter
Hyperactive Member
Re: Trapping [BACKSPACE] (subclassing)
never mind the above, I was blind, forgot to put the WasProcessed = True statement in the WM_KEYDOWN section.
*feels stupid*
"I don't want to live alone until I'm married" - M.M.R.P
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
|