MFC access Clipboard

Source: Internet
Author: User
MFC clipboard Application

How to copy data to a clipboard:
1: Open the clipboard ()
2: emptyclipboard () clears the clipboard so that the current process has a clipboard
3: globalalloc () allocates global heap memory.
4: globallock () locks the memory and returns the first address of the memory.
5: strcpy () assigns a value to the memory.
6: globalunlock () Unlock memory
7: setclipboarddata () is set to clipboard
8: closeclipboard () Close the clipboard


<textarea cols="50" rows="15" name="code" class="cpp">Void cclipboarddlg: onbnclickedbutton2 () <br/>{< br/> If (openclipboard () // open the clipboard <br/>{< br/> emptyclipboard (); // clear the clipboard so that the current window process has a clipboard <br/> cstring STR; <br/> getdlgitemtext (idc_edit_send, STR); // obtain data <br/> handle hclip; <br/> hclip = globalalloc (gmem_moveable, str. getlength () + 1); // address returned by memory allocation object (this function allocates memory from the global heap) <br/> char * pbuf; <br/> pbuf = (char *) globallock (hclip); // lock the memory block specified in the global memory and return an address value, point it to the starting position of the memory block <br/> strcpy (pbuf, STR); // copy the data in the STR object to the memory space <br/> globalunlock (hclip ); // unlock the global memory block <br/> setclipboarddata (cf_text, hclip); // set the Clipboard data <br/> closeclipboard (); // close <br/>}< br/>}</textarea>

Void cclipboarddlg: onbnclickedbutton1 () <br/>{< br/> // todo: add the <SPAN class = 'wp _ keywordlink '> Program </span> <SPAN class = 'wp _ keywordlink'> Code </span> <br/> If (isclipboardformatavailable (cf_text )) // obtain whether the format in the clipboard can be processed <br/>{< br/> If (openclipboard () <br/>{< br/> handle hclip; <br/> char * pbuf; <br/> hclip = getclipboarddata (cf_text); // retrieves Clipboard data from the specified format, return a clipboard object handle <br/> pbuf = (char *) globallock (hclip); // lock the memory block specified in the global memory and return an address value, return the Data Pointer header address <br/> globalunlock (hclip); // unlock <br/> setdlgitemtext (idc_edit_recv, pbuf); <br/> closeclipboard (); <br/>}< br/>}
 

 

From: http://blog.sina.com.cn/s/blog_613bf01c0100h0o4.html

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.