How to parse the C ++ operation clipboard

Source: Internet
Author: User

The C ++ programming language can be used in practical programming applications in a flexible manner to help us achieve various functional requirements. Here we will be fully aware of the specific implementation of the C ++ operation clipboard. I hope to help you.

  • How to use C ++ Endian
  • How to use C ++ switch-case statements
  • How To Connect C ++ to MySqL database
  • Analysis of basic application methods of C ++ youyuan Functions
  • Usage of C ++ Constructor

The clipboard is embedded in windows and uses the system's internal resource RAM or virtual memory to temporarily save cut and copy information. There are various types of information that can be stored. The information on the clipboard is saved during cropping or copying. The clipboard content can be updated or cleared only when another information is cut or copied, or when a power failure, windows exit, or intentionally cleared, that is, you can copy the clipboard once and paste it multiple times.

The following describes how to operate the clipboard in C ++, mainly writing data and obtaining data. operations on the clipboard can be seen as a way of inter-process communication.

1. In VC ++ 6.0 ~ 9.0) create a dialog box-based MFC project ClipboardTest

2. Add two editing controls: IDC_EDIT_SEND and IDC_EDIT_RECV) and two buttons: IDC_BTN_SEND and IDC_BTN_RECV)

3. Add the code for writing data to the clipboard for IDC_BTN_SEND

 
 
  1. If (OpenClipboard () // open the clipboard
  2. {
  3. CString str;
  4. HANDLE hClip;
  5. Char * pBuf;
  6. EmptyClipboard (); // clear the clipboard
  7. GetDlgItemText (IDC_EDIT_SEND, str); // obtain data in IDC_EDIT_SEND
  8. // Write data
  9. HClip = GlobalAlloc (GMEM_MOVEABLE, str. GetLength () + 1 );
  10. PBuf = (char *) GlobalLock (hClip );
  11. Strcpy (pBuf, str );
  12. GlobalUnlock (hClip); // unlock
  13. SetClipboardData (CF_TEXT, hClip); // set the format
  14. // Close the clipboard
  15. CloseClipboard ();
  16. }

4. Add the code to read the Clipboard data for IDC_BTN_RECV.

 
 
  1. If (OpenClipboard () // open the clipboard
  2. {
  3. If (IsClipboardFormatAvailable (CF_TEXT) // determine whether the format is what we need
  4. {
  5. HANDLE hClip;
  6. Char * pBuf;
  7. // Read data
  8. HClip = GetClipboardData (CF_TEXT );
  9. PBuf = (char *) GlobalLock (hClip );
  10. GlobalUnlock (hClip );
  11. SetDlgItemText (IDC_EDIT_RECV, pBuf); // The lecture data is displayed in IDC_EDIT_RECV.
  12. CloseClipboard ();
  13. }
  14. }

The preceding section describes how to operate the clipboard in C ++.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.