【MoreWindows工作筆記9】OleGetClipboard 訪問剪下板的常值內容

來源:互聯網
上載者:User

// 【MoreWindows工作筆記9】OleGetClipboard 訪問剪下板的常值內容// http://blog.csdn.net/morewindows/article/details/17655053// By MoreWindows( http://blog.csdn.net/MoreWindows )#include <Windows.h>#include <ObjBase.h>#include <iostream>using namespace std;void DisplayDataObject(IDataObject *pDataObject){ FORMATETC fmtetc = {CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; STGMEDIUM stgmedium; if (pDataObject->GetData(&fmtetc, &stgmedium) == S_OK) { cout<<" 剪下板資料格式上為CF_TEXT, 常值內容如下:"<<endl; char* data = (char*)GlobalLock(stgmedium.hGlobal); cout<<data<<endl; GlobalUnlock(stgmedium.hGlobal); ReleaseStgMedium(&stgmedium); } else { cout<<" 剪下板資料格式不為CF_TEXT"<<endl; }} int main() { printf(" 【MoreWindows工作筆記9】OleGetClipboard 訪問剪下板的常值內容\n"); printf(" - http://blog.csdn.net/morewindows/article/details/17655053 -\n"); printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n"); if (OleInitialize(NULL) != S_OK) return 0; IDataObject *pDataObject; // Retrieves a data object that you can use to access the contents of the clipboard. if (OleGetClipboard(&pDataObject) == S_OK) { DisplayDataObject(pDataObject); pDataObject->Release(); } OleUninitialize(); return 0;}

HRESULT OleGetClipboard( _Out_ LPDATAOBJECT *ppDataObj);

typedef struct tagFORMATETC { CLIPFORMAT cfFormat; // 剪貼簿資料格式DVTARGETDEVICE *ptd; // 裝置有關的資訊DWORD dwAspect; // 圖形資料的表現方式LONG lindex; // dwAspect 成員的補充DWORD tymed; // 資料的儲存介質} FORMATETC;

FORMATETC cFmt = {(CLIPFORMAT) CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};

// winuser.h#ifndef NOCLIPBOARD/* * Predefined Clipboard Formats */#define CF_TEXT 1#define CF_BITMAP 2#define CF_METAFILEPICT 3#define CF_SYLK 4#define CF_DIF 5#define CF_TIFF 6#define CF_OEMTEXT 7#define CF_DIB 8#define CF_PALETTE 9#define CF_PENDATA 10#define CF_RIFF 11#define CF_WAVE 12#define CF_UNICODETEXT 13#define CF_ENHMETAFILE 14#if(WINVER >= 0x0400)#define CF_HDROP 15#define CF_LOCALE 16#endif /* WINVER >= 0x0400 */#if(WINVER >= 0x0500)#define CF_DIBV5 17#endif /* WINVER >= 0x0500 */#if(WINVER >= 0x0500)#define CF_MAX 18#elif(WINVER >= 0x0400)#define CF_MAX 17#else#define CF_MAX 15#endif#define CF_OWNERDISPLAY 0x0080#define CF_DSPTEXT 0x0081#define CF_DSPBITMAP 0x0082#define CF_DSPMETAFILEPICT 0x0083#define CF_DSPENHMETAFILE 0x008E/* * "Private" formats don't get GlobalFree()'d */#define CF_PRIVATEFIRST 0x0200#define CF_PRIVATELAST 0x02FF/* * "GDIOBJ" formats do get DeleteObject()'d */#define CF_GDIOBJFIRST 0x0300#define CF_GDIOBJLAST 0x03FF#endif /* !NOCLIPBOARD */

typedef struct tagSTGMEDIUM {  DWORD    tymed;  union {    HBITMAP       hBitmap;    HMETAFILEPICT hMetaFilePict;    HENHMETAFILE  hEnhMetaFile;    HGLOBAL       hGlobal;    LPOLESTR      lpszFileName;    IStream       *pstm;    IStorage      *pstg;  };  IUnknown *pUnkForRelease;} STGMEDIUM, *LPSTGMEDIUM;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.