Results 1 to 7 of 7

Thread: To do with SendMessage and Clipboard commands, including Undo

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Code:
    Function UNDO(hWnd As Long)
        SendMessage hWnd, EM_UNDO, 0, 0
    End Function
    
    Function ToClip(hWnd As Long)
        SendMessage hWnd, WM_COPY, 0, 0
    End Function
    
    Function FromClip(hWnd As Long)
        SendMessage hWnd, WM_PASTE, 0, 0
    End Function
    
    Function CleanToClip(hWnd As Long)
        SendMessage hWnd, WM_CUT, 0, 0
    End Function
    Okay... I have some problems with these.

    When I call...

    Undo - Just selects all the text.
    ToClip - Works, but see FromClip (copy command)
    FromClip - Pastes it TWICE. Error might be in ToClip when using that, or CleanToClip while using that(paste command)
    CleanToClip - Works, but has same side-effects as ToClip when pasting back (see From Clip) (cut command)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Guest
    This all works for me.


    Code:
    Private Declare Function SendMessage _
    Lib "user32" Alias "SendMessageA" (ByVal hWnd As _
    Long, ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long
    
    Private Const WM_COPY = &H301
    Private Const WM_CUT = &H300
    Private Const WM_PASTE = &H302
    Private Const WM_UNDO = &H304
    
    Private Function Undo(hWnd As Long)
        SendMessage hWnd, WM_UNDO, 0, 0
    End Function
    
    Private Function ToClip(hWnd As Long)
        SendMessage hWnd, WM_COPY, 0, 0
    End Function
    
    Private Function FromClip(hWnd As Long)
        SendMessage hWnd, WM_PASTE, 0, 0
    End Function
    
    Private Function CleanToClip(hWnd As Long)
        SendMessage hWnd, WM_CUT, 0, 0
    End Function
    
    Private Sub Command1_Click()
        ToClip Text1.hWnd
    End Sub
    
    Private Sub Command2_Click()
        CleanToClip Text1.hWnd
    End Sub
    
    Private Sub Command3_Click()
        Undo Text1.hWnd
    End Sub
    
    Private Sub Command4_Click()
        FromClip Text1.hWnd
    End Sub

  3. #3

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well... I'm using a RICHtextbox. Is it done differently for a rtb?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Guest
    Should work.


    Code:
    Private Sub Command1_Click()
        ToClip RichTextBox1.hWnd
    End Sub
    
    Private Sub Command2_Click()
        CleanToClip RichTextBox1.hWnd
    End Sub
    
    Private Sub Command3_Click()
        Undo RichTextBox1.hWnd
    End Sub
    
    Private Sub Command4_Click()
        FromClip RichTextBox1.hWnd
    End Sub

  5. #5
    Guest
    Do you have any other code associated with copy/pasting that may influence this code?

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    use EM_CANUNDO and see if undoing is allowed. If you are accessing someone else's window, they might not allow it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7
    Guest
    Here is the constant for it.


    Code:
    Private Const EM_CANUNDO = &HC6

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