1. Copy Text to Clipboard
CString StrText = L "text to be copied to clipboard", if (:: OpenClipboard (m_hwnd)) {if (:: EmptyClipboard ())//empty clipboard data {int nSize = strtext.ge Tlength () *2+1;//Here is the number of bytes, Unicode encoding each character occupies 2 bytes, followed by an end character. Hglobal Hmem =:: GlobalAlloc (GHND, nSize); byte* pdata= (byte*):: GlobalLock (HMEM); memcpy_s (PData, NSize, Strdata.getdata (), nSize-1);pD ata[nsize-1]= ';:: GlobalUnlock (HMEM);:: SetClipboardData (Cf_unicodetext, Hmem);:: CloseClipboard ();:: GlobalFree (HMEM);}}
2. Copy the bitmap handle to the Clipboard
Save screenshot Area bitmap to Clipboard if (:: OpenClipboard (m_hwnd)) {if (:: EmptyClipboard ()) {Hbitmap hbmp = Getbitmaprect (G_hscreenbmp, M_rect );:: SetClipboardData (Cf_bitmap, hbmp);D eleteobject (hbmp);:: CloseClipboard ();}}
3. In general, you must follow this order to manipulate the Clipboard: Open----Empty----setdata-----close. (Open-empty-set-off)
A number of other specific references are available for the MSDN instructions
Remarksopenclipboard fails if another window has the the Clipboard Open. An application should call the CloseClipboard function after every successful call to OpenClipboard. The window identified by the Hwndnewowner parameter does not become the Clipboard owner unless the EmptyClipboard function is called. If an application calls OpenClipboard with HWND set to NULL, EmptyClipboard sets the clipboard owner to null; This causes SetClipboardData to fail.
Windows clipboard Operations Simple small example