Advertisement
4_2005-2006 String Manipulation #159769

Copy/Cut/Paste/Undo

I was just poking around this site, and noticed that a lot of folks were making the copy/paste/cut/undo functions more difficult then they really needs to be. Rather then writing your own functions, make use of the SendMessage API and let Windows do the work for you.

AI

ИИ-обзор: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Исходный код
original-source
Private Sub Command1_Click()
'=============================================
'Defined strictly for the Richtextbox, though
'might work on others.
'=============================================
SendMessage RichTextBox1.hWnd, EM_UNDO, ByVal 0&, ByVal 0&
End Sub
Private Sub Command2_Click()
SendMessage RichTextBox1.hWnd, WM_COPY, ByVal 0&, ByVal 0&
End Sub
Private Sub Command3_Click()
SendMessage RichTextBox1.hWnd, WM_PASTE, ByVal 0&, ByVal 0&
End Sub
Private Sub Command4_Click()
SendMessage RichTextBox1.hWnd, WM_CUT, ByVal 0&, ByVal 0&
End Sub
'=================================================
'This can be used on textboxes and other controls
'=================================================
Private Sub Command5_Click()
SendMessage RichTextBox1.hWnd, WM_UNDO, ByVal 0&, ByVal 0&
End Sub

Private Sub Form_Load()
RichTextBox1.Text = "This is line 1" & vbCrLf & _
          "This is line 2" & vbCrLf & _
          "This is line 3" & vbCrLf & _
          "This is line 4" & vbCrLf
          
End Sub
Оригинальные комментарии (3)
Восстановлено из Wayback Machine