Results 1 to 4 of 4

Thread: [ignore the checkmark] Self made txtBox menu Undo problems

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Resolved [ignore the checkmark] Self made txtBox menu Undo problems

    I'm blocking the standard popup menu on a textbox and replacing it with my own.
    I'd like to keep most of the standard commands and add a few more.

    If I use my code too Cut or Delete text, then Ctrl+z from the keyboard and my Undo code won't work.
    If I Cut or Delete using the keyboard they do work.

    I'm posting a cut down version of the code for testing.
    Attached Files Attached Files
    Last edited by longwolf; Jan 27th, 2007 at 02:12 PM.

  2. #2

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Self made txtBox menu Undo problems

    Ok, I've fixed the Cut/Delete problem by using Sendkeys instead of the way I was doing it.

    I found that my EditPaste sub had the same problem and changed it to use Sendkeys too.

    The Paste works, but hitting Undo only selects/highlights the pasted text

    Here's the code from the updated module.
    VB Code:
    1. Option Explicit
    2.  
    3. Public bBlockMenu As Boolean
    4.  
    5. Public Const WM_USER = &H400
    6. Public Const EM_HIDESELECTION = WM_USER + 63
    7. Public Const WM_UNDO = &H304
    8. Public Const EM_CANUNDO = &HC6
    9.  
    10. Public Declare Function SendMessage Lib "user32" Alias _
    11.     "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    12.         ByVal wParam As Long, lParam As Long) As Long
    13.  
    14. Public Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    15.  
    16. Public Sub ReplaceMenu(ByRef objX As Object, _
    17.                        mnuX As Object)
    18.     'lock the text box for my personal use
    19.     LockWindowUpdate objX.hwnd
    20.     'the text box MUST be disabled to
    21.     'prohibit default popup menu
    22.     objX.Enabled = False
    23.     'releases the lock
    24.     LockWindowUpdate 0&
    25.     DoEvents
    26.     objX.Enabled = True
    27.     objX.SetFocus
    28.     objX.Parent.PopupMenu mnuX
    29.     On Error GoTo DeletedItself:
    30.     objX.Enabled = True
    31. DeletedItself:
    32. End Sub
    33.  
    34. Public Sub EditUndo(ByRef objX As Object)
    35.    
    36.     If CBool(SendMessage(objX.hwnd, EM_CANUNDO, 0, ByVal 0&)) Then
    37.         SendMessage objX.hwnd, WM_UNDO, 0, ByVal 0&
    38.     End If
    39. End Sub
    40.  
    41. Public Sub EditCut(ByRef objX As Object)
    42.    
    43. '    On Error GoTo NoSel:
    44. '    ' Clear the contents of the Clipboard.
    45. '    Clipboard.Clear
    46. '    ' Copy selected text to Clipboard.
    47. '    Clipboard.SetText objX.SelText
    48. '    ' Delete selected text.
    49. '    objX.SelText = ""
    50. 'NoSel:
    51.  
    52.     objX.SetFocus
    53.     SendKeys "{BACKSPACE}" ' "^C"
    54. End Sub
    55.  
    56. Public Sub EditCopy(ByRef objX As Object)
    57.  
    58.     On Error GoTo NoSel:
    59.     ' Clear the contents of the Clipboard.
    60.     Clipboard.Clear
    61.     ' Copy selected text to Clipboard.
    62.     Clipboard.SetText objX.SelText
    63. NoSel:
    64. End Sub
    65.  
    66. Public Sub EditPaste(ByRef objX As Object)
    67.  
    68. '    On Error GoTo NoSel:
    69. '    ' Place text from Clipboard into active control.
    70. '    objX.SelText = vbNullString
    71. '    objX.SelText = Clipboard.GetText()
    72. 'NoSel:
    73.     SendKeys "^v"
    74. End Sub
    75.  
    76. Public Sub EditSelectAll(ByRef objX As Object)
    77.  
    78.     On Error GoTo NoSel:
    79.     objX.SelStart = 0
    80.     objX.SelLength = Len(objX.Text)
    81. NoSel:
    82. End Sub
    83.  
    84. Public Sub EditCopyAll(ByRef objX As Object)
    85.  
    86.     On Error GoTo NoSel:
    87.     ' Clear the contents of the Clipboard.
    88.     Clipboard.Clear
    89.     ' Copy all of the text
    90.     Clipboard.SetText objX.Text
    91. NoSel:
    92. End Sub
    93.  
    94. Public Sub EditDelete(ByRef objX As Object)
    95.  
    96. '    On Error GoTo NoSel:
    97. '    objX.SelText = vbNullString
    98. 'NoSel:
    99.     objX.SetFocus
    100.     SendKeys "{DEL}"
    101. End Sub

  3. #3

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Self made txtBox menu Undo problems

    Ok, got it all now.

    Just had to add:
    VB Code:
    1. objX.SetFocus
    to the EditPaste sub

  4. #4

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Self made txtBox menu Undo problems

    Oups,

    I only thought that RESOLVED it.
    Now it sometimes will undo the Paste, and sometimes it won't.

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