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




Reply With Quote