// [MoreWindows work Note 9] OleGetClipboard access Clipboard text content // 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-> GetD Ata (& fmtetc, & stgmedium) = S_ OK) {cout <"the Clipboard data format is CF_TEXT. The text content is as follows:" <endl; char * data = (char *) globalLock (stgmedium. hGlobal); cout <data <endl; GlobalUnlock (stgmedium. hGlobal); ReleaseStgMedium (& stgmedium);} else {cout <"Clipboard data format not CF_TEXT" <endl ;}} int main () {printf ("[MoreWindows work Note 9] OleGetClipboard access Clipboard text content \ n"); printf ("-http://blog.csdn.net/morewindows/article/details/17655053-\ n" ); Printf ("-- By MoreWindows (http://blog.csdn.net/MoreWindows) -- \ 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; // Clipboard data format DVTARGETDEVICE * ptd; // device-related information DWORD dwAspect; // Graphical Data Representation LONG lindex; // dwAspect member supplement DWORD tymed; // data storage medium} 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_DIF 3 # define CF_SYLK 4 # define CF_DIF 5 # define CF_TIFF 6 # define 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 limit 0x0083 # define limit 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;