One-day Windows API training (85) OpenClipboard Function

Source: Internet
Author: User

Data sharing among multiple software is very important. It is hard to imagine how inconvenient it is to edit the software without the CTRL + C and CTRL + V functions. Many operations are the copy action for data sharing. Clipboard sharing is an important function in Windows. For example, many data collection software can use the clipboard function to facilitate data import to Excel. You can also use the clipboard function to export the obtained interface to Word.
 
The function OpenClipboard declaration is as follows:
 
WINUSERAPI
BOOL
WINAPI
OpenClipboard (
_ In_opt HWND hWndNewOwner );
HWndNewOwner is the window of the front board.
 
An example of calling a function is as follows:
#001 // copy the data to the clipboard.
#002 // Cai junsheng 2007/12/09 QQ: 9073204 Shenzhen
#003 void TestClipBoard (void)
#004 {
#005 // open the clipboard and clear it.
#006 if (OpenClipboard (m_hWnd )&&
#007 EmptyClipboard ())
#008 {
#009 //
#010 HGLOBAL hMem;
#011 std: wstring strText (_ T ("Copy Data to clipboard "));
#012
#013 // allocate global memory.
#014 hMem = GlobalAlloc (GMEM_MOVEABLE,
#015 (strText. length () + 1) * sizeof (TCHAR ));
#016 if (hMem = NULL)
#017 {
#018 CloseClipboard ();
#019 return;
#020}
#021
#022 // copy data to the clipboard memory.
#023 LPTSTR lpStr = (LPTSTR) GlobalLock (hMem );
#024 memcpy (lpStr, strText. c_str (),
#025 strText. length () * sizeof (TCHAR ));
#026 lpStr [strText. length ()] = (TCHAR) 0;
#027 GlobalUnlock (hMem );
#028
#029 // set data to clipboard
#030 SetClipboardData (CF_UNICODETEXT, hMem );
#031
#032 // close the clipboard.
#033 CloseClipboard ();
#034}
#035}
#036

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/12/09/1925509.aspx

Related Article

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.