-
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)
-
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
-
Well... I'm using a RICHtextbox. Is it done differently for a rtb?
-
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
-
Do you have any other code associated with copy/pasting that may influence this code?
-
use EM_CANUNDO and see if undoing is allowed. If you are accessing someone else's window, they might not allow it.
-
Here is the constant for it.
Code:
Private Const EM_CANUNDO = &HC6