// 【MoreWindows工作筆記11】EnumClipboardFormats 剪下板內容的資料格式// http://blog.csdn.net/morewindows/article/details/17655299// 參考http://msdn.microsoft.com/en-us/library/windows/desktop/ms649013(v=vs.85).aspx#include <Windows.h>#include <iostream>#include <cstdio>using namespace std;int main(){ printf(" 【MoreWindows工作筆記11】OleGetClipboard 訪問剪下板的常值內容\n"); printf(" - http://blog.csdn.net/morewindows/article/details/17655053 -\n"); printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n"); if (OpenClipboard(NULL)) { // 由於設定了VX在複製時帶上文字顏色,所以從VS2008中拷貝文本時,資料格式不為CF_UNICODETEXT UINT clipboard_format; while (clipboard_format = EnumClipboardFormats(0)) { printf("Clipboard Data Format = 0x%x\n", clipboard_format); HGLOBAL global_memory = GetClipboardData(clipboard_format); LPCSTR clipboard_data = (LPCSTR)GlobalLock(global_memory); if (clipboard_data != NULL) { // 剪下板上資料的地址 printf("Clipboard Data Address = 0x%x\n", global_memory); // 剪下板上資料大小 DWORD data_size = GlobalSize(global_memory); printf("Data Size = %d\n", data_size); // 16進位輸出資料 printf("Data: "); for (DWORD i = 0; i < data_size; i++) { if (i % 8 == 0) putchar(' '); if (i % 16 == 0) putchar('\n'); printf("%02x ", (UCHAR)clipboard_data[i]); } putchar('\n'); // 輸出部分資料 switch (clipboard_format) { case CF_TEXT: printf(" 資料格式:CF_TEXT 資料內容:\n%s\n", clipboard_data); break; case CF_UNICODETEXT: printf(" 資料格式:CF_UNICODETEXT 資料內容:\n%ls\n", (LPCWSTR)clipboard_data); break; } GlobalUnlock(global_memory); } CloseClipboard(); } } return 0;}