开发者

How do you copy/paste image data?

开发者 https://www.devze.com 2023-03-17 11:17 出处:网络
Using C++ and the WinAPI, how do 开发者_JAVA技巧I copy the image data from a pre-loaded image into the clipboard?You need to create an object that implements IDataObject, and then place it on the clip

Using C++ and the WinAPI, how do 开发者_JAVA技巧I copy the image data from a pre-loaded image into the clipboard?


You need to create an object that implements IDataObject, and then place it on the clipboard using OleSetClipboard.

When you place data in the clipboard you have the ability to specify multiple formats. This is so that the application reading the clipboard can enumerate the formats and decide which one to use.

There are quite a few "standard" clipboard formats (with known constant values), e.g.:

  • CF_BITMAP: A handle to a bitmap (HBITMAP).
  • CF_DIB: A memory object containing a BITMAPINFO structure followed by the bitmap bits.
  • CF_DIBV5: A memory object containing a BITMAPV5HEADER structure followed by the bitmap color space information and the bitmap bits.

You can also register custom formats using RegisterClipboardFormat. Office exposes images as a number of different formats that they've registered, e.g.:

DWORD CF_PNG = RegisterClipboardFormat("PNG");
DWORD CF_JFIF = RegisterClipboardFormat("JFIF");
DWORD CF_GIF = RegisterClipboardFormat("GIF");
DWORD CF_ENHMETAFILE = RegisterClipboardFormat("CF_ENHMETAFILE");
DWORD CF_METAFILEPICT = RegisterClipboardFormat("CF_METAFILEPICT ");


The EditCopy function on this page of MSDN gives a good example of what you want to achieve:

http://msdn.microsoft.com/en-us/library/ms649016(v=vs.85).aspx

You will need to change the data type from CF_TEXT to CF_BITMAP in order to tell windows it is of an bitmap mime type.

0

精彩评论

暂无评论...
验证码 换一张
取 消