Handle setclipboarddata (
Uint uformat,
Handle hmem );
Parameters
Format:
[In] unsigned integer that specifies a clipboard format. This parameter can be a registered format or any of the standard clipboard formats. Windows CE supports the following standard clipboard:
Value |
Description |
Cf_bitmap |
A handle to a bitmap (Hbitmap). |
Cf_dib |
A memory object containingBitmapinfoStructure followed by the bitmap bits. |
Cf_dif |
Software arts 'data interchange format. |
Cf_palette |
[See msdn] |
Cf_pendata |
Data for the pen extensions to the Microsoft Windows for Pen computing. |
Cf_riff |
Represents audio data more complex than can be represented in a cf_wave standard wave format. |
Cf_sylk |
Microsoft Symbolic Link (sylk) format. |
Cf_text |
Text format. Each line ends with a carriage return/linefeed (CR-LF) combination. a null Character signals the end of the data. Use this format for ANSI text. |
Cf_wave |
Represents audio data in one of the standard wave formats, such as 11 kHz or 22 kHz pulse code modulation (PCM ). |
Cf_tiff |
Tagged-image file format. |
Cf_unicodetext |
Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. a null Character signals the end of the data. |
Example 1: copy and paste text
/*
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 ()Set to clipboard
8: closeclipboard () Close the clipboard
*/
Void cclipboarddlg: onbnclickedbutton2 ()
{
If (Openclipboard ()) // Open the clipboard
{
Emptyclipboard ();// Clear the clipboard so that the current window process has a clipboard
Cstring STR;
Getdlgitemtext (idc_edit_send, STR); // get data
Handle hclip;
Hclip =Globalalloc(Gmem_moveable,Str. getlength () + 1); // Allocate the return address of the Memory Object (this function is used to allocate memory from the global heap)
Char * pbuf;
Pbuf = (char *)Globallock(Hclip); // lock the memory block specified in the global memory and return an address value to point it to the starting position of the memory block.
Strcpy(Pbuf, STR); // copy data from the STR object to the memory space
Globalunlock(Hclip); // unlock the global memory block
Setclipboarddata(Cf_text, hclip); // sets the Clipboard data.
Closeclipboard (); // close
}
}
/*
How to retrieve data from a clipboard:
1: isclipboardformatavailable () determines whether the clipboard has data to be retrieved
2: Open the clipboard ()
3: getclipboarddata () retrieves the object handle in the specified format
4: globallock () locks the memory and retrieves the object data.
5: globalunlock unlock
6: closeclipboard () Close the clipboard
*/
Void cclipboarddlg: onbnclickedbutton1 ()
{
// Todo: add the control notification handler code here
If (Isclipboardformatavailable(Cf_text) // obtain the format in the clipboard for processing
{
If (Openclipboard ())
{Handle hclip;
Char * pbuf;
Hclip =Getclipboarddata (cf_text );// Retrieve the Clipboard data in the specified format and return a clipboard object handle
Pbuf = (char *)Globallock(Hclip); // lock the memory block specified in the global memory, return an address value, and return the Data Pointer header address.
Globalunlock(Hclip); // unlock
Setdlgitemtext (idc_edit_recv, pbuf );
Closeclipboard ();
}
}
}
Example 2. copy and paste bitmap
Bitmap copying
If (: openclipboard (m_hwnd )){
// Make a copy of the bitmap.
Bitmap bm;
Cbitmap bitmap;
CbitmapM_bitmap;
M_bitmap. Loadbitmap (Idb_bitmap2);
M_bitmap.getobject (sizeof (BM), & BM );
Bitmap. createbitmapindirect (& BM );
CDC dcmemsrc, dcmemdest;
Dcmemsrc. createcompatibledc (null );
Cbitmap * poldbitmapsrc = dcmemsrc. SelectObject (& m_bitmap );
Dcmemdest. createcompatibledc (null );
Cbitmap * poldbitmapdest = dcmemdest. SelectObject (& Bitmap );
Dcmemdest. bitblt (0, 0, BM. bmwidth, BM. bmheight, & dcmemsrc,
0, 0, srccopy );
HbitmapHbitmap= (Hbitmap) bitmap. Detach ();
Dcmemdest. SelectObject (poldbitmapdest );
Dcmemsrc. SelectObject (poldbitmapsrc );
// Place the copy on the clipboard.
: Emptyclipboard ();
: Setclipboarddata (cf_bitmap,Hbitmap);
: Closeclipboard ();
}
Bitmap pasting:
Display the bitmap data in the clipboard to the client area of the program:
Hwnd = getsafehwnd (); // obtain the security window handle
: Openclipboard (hwnd); // open the clipboard
Handle hbitmap =: getclipboarddata (cf_bitmap); // obtain the Clipboard data handle
HDC =: getdc (hwnd); // obtain the device environment handle
HDC hdcmem = createcompatibledc (HDC); // create a device-related memory Environment
SelectObject (hdcmem, hbitmap); // select an object
Setmapmode (hdcmem, getmapmode (HDC); // you can specify the ing mode.
Bitmap bm; // obtain the bitmap object.
GetObject (hbitmap, sizeof (Bitmap), & BM );
Bitblt (HDC, 0, 0, BM. bmwidth, BM. bmheight, hdcmem, 0, 0, srccopy); // bitmap
Copy
: Releasedc (hwnd, HDC); // release the device environment handle
Deletedc (hdcmem); // deletes the memory environment.
: Closeclipboard (); // close the clipboard
3. Multiple Data items
To put data to the clipboard, you must call the emptyclipboard () function to clear the current
The content in the clipboard, instead of appending a new data item to the original data item. However, you can
Call setclipboarddata () multiple times between emptyclipboard () and closeclipboard ()
Function to place multiple data items in different formats. For example
Openclipboard (hwnd );
Emptyclipboarddata ();
Setclipboarddata (cf_text, hgmemtext );
Setclipboarddata (cf_bitmap, hbitmap );
Closeclipboard ();
In this case, if you use the format cf_text or cf_bitmap to mark the callIsclipboardformatavailable ()
Returns true, indicating that the data in these formats is stored in the clipboard at the same time. Mark it in different formats
Use the getclipboarddata () function to obtain the corresponding data handle.
You can also use countclipboardformats () and
The enumclipboardformats () function obtains the number of data formats and specific data in the current clipboard.
Format. The function prototype of enumclipboardformats () is:
Uint enumclipboardformats (uint format );
The format parameter specifies the data format of the clipboard. If the execution is successful, the next one in the format specified by format is returned.
Data format value. If format is the final data format value, 0 is returned. It is not difficult to write and Process
Code of the program segment for all data items in the clipboard:
Uint format = 0; // starts from the first format Value
Openclipboard (hwnd );
While (format = enumclipboardformats (Format ))
{
...... // Process related format data
}
Closeclipboard ();
4. Delayed submission
Http://apps.hi.baidu.com/share/detail/30391289