Advertisement
7_2009-2012 String Manipulation #227323

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

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에서 복구됨