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.