PDA

Click to See Complete Forum and Search --> : To do with SendMessage and Clipboard commands, including Undo


Sastraxi
Mar 15th, 2001, 06:21 PM
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)

Mar 15th, 2001, 07:08 PM
This all works for me.


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

Sastraxi
Mar 15th, 2001, 08:24 PM
Well... I'm using a RICHtextbox. Is it done differently for a rtb?

Mar 15th, 2001, 08:49 PM
Should work.


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

Mar 15th, 2001, 09:41 PM
Do you have any other code associated with copy/pasting that may influence this code?

Lord Orwell
Mar 16th, 2001, 09:10 PM
use EM_CANUNDO and see if undoing is allowed. If you are accessing someone else's window, they might not allow it.

Mar 16th, 2001, 09:37 PM
Here is the constant for it.


Private Const EM_CANUNDO = &HC6