About how to copy and paste clipboard in VC!

Source: Internet
Author: User

 

I would like to encourage you!

The first note is that the clipboard is a function provided by the system that can be used to implement inter-process communication. The implementation in VC is also very simple.
The following is the vc6.0 MFC environment:

If (openclipboard () // open a clipboard first. If yes, return a non-0 value {handle hclip; // declare a handle cstring STR; char * pbuf; emptyclipboard (); // leave the clipboard empty and get the ownership of the clipboard. getdlgitemtext (idc_edit1, STR); // assign the value of the text box to STR hclip = globalalloc (gmem_moveable, str. getlength () + 1); // apply to lock a memory area pbuf = (char *) globallock (hclip) where data is stored ); // obtain the first byte pointer strcpy (pbuf, STR) pointing to the memory area; // copy the value of the text box to globalunlock (hclip) in the memory ); // unlock the memory setclipboarddata (cf_text, hclip); // set the data to closeclipboard (); // close the clipboard}


 

In this way, the content entered in the text box has been "copied", and is in the memory area. For example, open a notepad and paste it directly to extract the memory, in this way, communication between cities is achieved.

The VC implementation of "paste" is as follows:

If (openclipboard () // open a clipboard {If (isclipboardformatavailable (cf_text) // check whether the data in the clipboard is text. You can set it to something else! {Handle hclip; // declare a handle char * pbuf; hclip = getclipboarddata (cf_text); // obtain the clipboard handle pbuf = (char *) globallock (hclip ); // obtain the pointer globalunlock (hclip) pointing to this memory; // unlock the memory. setdlgitemtext (idc_edit2, pbuf); // set it to a text box to display closeclipboard (); // close this clipboard }}


 

In this way, the "copy" and "Paste" functions are implemented. Of course, windows already provides this function, but we mainly use it for communication between cities.

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.