Cut, copy, and paste using API functions

Cut, copy, and paste using API functions

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:

Private Const WM_CUT = &H300Private Const WM_COPY = &H301Private Const WM_PASTE = &H302Private Const WM_CLEAR = &H303Private 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 ClipboardSub ControlCopy(ByVal hWnd As Long)    SendMessage hWnd, WM_COPY, 0, ByVal 0&End Sub' Cut the contents of a control into the ClipboardSub ControlCut(ByVal hWnd As Long)    SendMessage hWnd, WM_CUT, 0, ByVal 0&End Sub' Paste the contents of the Clipboard into a controlSub ControlPaste(ByVal hWnd As Long)    SendMessage hWnd, WM_PASTE, 0, ByVal 0&End Sub' Delete the selected contents of a controlSub ControlDelete(ByVal hWnd As Long)    SendMessage hWnd, WM_CLEAR, 0, ByVal 0&End Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes