Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Cut, copy, and paste using API functions

Total Hit ( 4772)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Copying and pasting text and images programmatically isn't difficult at all, using the methods of the Clipboard object. However, implementing a generic Edit menu that copies and pastes the highlighted contents of whatever control is the selected control is often cumberson. For example, depending on the type of the active control you might need to query the SelText property (TextBox and ComboBox controls), the SelRTF property (the RichTextBox control), or the Picture property (the PictureBox control), not to mention other ActiveX controls.

A better approach is to send the proper Windows message to whatever control is the ActiveControl. For example, sending the WM_CUT message cuts the current contents to the Clipboard, regardless of the type of the control. Here are a collection of routine that encapsulate the proper call to the SendMessage API function:

Click here to copy the following block
Private Const WM_CUT = &H300
Private Const WM_COPY = &H301
Private Const WM_PASTE = &H302
Private Const WM_CLEAR = &H303
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

' Copy the contents of a control into the Clipboard
Sub ControlCopy(ByVal hWnd As Long)
  SendMessage hWnd, WM_COPY, 0, ByVal 0&
End Sub

' Cut the contents of a control into the Clipboard
Sub ControlCut(ByVal hWnd As Long)
  SendMessage hWnd, WM_CUT, 0, ByVal 0&
End Sub

' Paste the contents of the Clipboard into a control
Sub ControlPaste(ByVal hWnd As Long)
  SendMessage hWnd, WM_PASTE, 0, ByVal 0&
End Sub

' Delete the selected contents of a control
Sub ControlDelete(ByVal hWnd As Long)
  SendMessage hWnd, WM_CLEAR, 0, ByVal 0&
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.