Results 1 to 2 of 2

Thread: Trapping [BACKSPACE] (subclassing)

  1. #1

    Thread Starter
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439

    Resolved 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:
    1. Dim WasProcessed As Boolean
    2.    WasProcessed = False
    3.    
    4.     Dim StartSel As Long, Temp As String, PrevLineSpaces As Integer, PrevLineTabs As Integer
    5.     StartSel = frmMain.txtDocument.SelStart
    6.     PrevLineSpaces = 0
    7.     PrevLineTabs = 0
    8.    
    9.     Select Case Msg
    10.         Case WM_KEYDOWN
    11.             Select Case wp
    12.                 Case 8 '[BACKSPACE] is pressed
    13.                     If frmMain.TabsAsSpaces = True Then
    14.                    
    15.                     End If
    16.                
    17.                 Case 9 '[TAB] Is Pressed
    18.                     If frmMain.TabsAsSpaces Then
    19.                         WasProcessed = True
    20.                         frmMain.txtDocument.Text = Mid(frmMain.txtDocument.Text, 1, StartSel) & String(frmMain.AmountOfSpacePerTab, " ") & Mid(frmMain.txtDocument.Text, StartSel + 1)
    21.                         frmMain.txtDocument.SelStart = StartSel + frmMain.AmountOfSpacePerTab
    22.                     End If
    23.             End Select
    24.         Case WM_KEYUP
    25.             If frmMain.TabsAsSpaces And wp = 8 Then WasProcessed = True
    26.             If frmMain.TabsAsSpaces And wp = 9 Then WasProcessed = True
    27.         Case WM_CHAR
    28.             If frmMain.TabsAsSpaces And wp = 8 Then WasProcessed = True
    29.             If frmMain.TabsAsSpaces And wp = 9 Then WasProcessed = True
    30.         Case WM_DEADCHAR
    31.             If frmMain.TabsAsSpaces And wp = 8 Then WasProcessed = True
    32.             If frmMain.TabsAsSpaces And wp = 9 Then WasProcessed = True
    33.    End Select
    34.     If Not WasProcessed Then
    35.         'Default processing...
    36.         CallWindowProc OldProcAddy, SubClasshWnd, Msg, wp, lp
    37.         WindowProc = DefWindowProc(SubClasshWnd, Msg, wp, lp)
    38.     End If
    "I don't want to live alone until I'm married" - M.M.R.P

  2. #2

    Thread Starter
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439

    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
  •  



Click Here to Expand Forum to Full Width