2011-01-09 29 views
3

我一直在使用Windows剪貼板玩耍。我注意到,如果您提供格式,您只能查看剪貼板。我見過可以轉儲剪貼板原始內容的程序。看看http://www.autohotkey.com/docs/misc/Clipboard.htm#ClipboardAll就是我的意思。獲取剪貼板中的數據在C++中

有沒有辦法做同樣的事情,我想要做的是能夠備份剪貼板,操作它,那麼當我的程序完成恢復。

我正在尋找一個解決方案non-.net如果這實際上是一個東西

編輯:

我想這個至今:

struct clipData { 
vector<void*> data; 
vector<int> size; 
}; 

struct clipData saveClipboard(int &size) { 
clipData ret; 
UINT currentFormat = 0; 
HGLOBAL hData; 
if (OpenClipboard(0)) { 

    while(currentFormat = EnumClipboardFormats(currentFormat)) { 
    hData = GetClipboardData(currentFormat); 
    int currentClipboardFormatSize = GlobalSize(hData); //Only works with text formats. Help! 
    char *savedClipboardData = new char[currentClipboardFormatSize]; 
    char *ptrToData = (char*) GlobalLock(hData); 
    memcpy(savedClipboardData, ptrToData, currentClipboardFormatSize); 
    ret.data.push_back(savedClipboardData); 
    ret.size.push_back(currentClipboardFormatSize); 
    } 
    CloseClipboard(); 
} 
return ret; 
} 

但問題是,世界上沒有其他辦法告訴剪貼板在每種格式下的大小如何

回答

4

有沒有「原始」數據涉及。只需enumerate all the formats currently on the clipboard,並獲取並保存每種格式的內容。但要小心自動格式轉換。

如果你仔細閱讀您鏈接的文檔的AutoHotkey,它甚至會告訴你,這是單獨檢索每個格式,並且它可能只在檢索的格式的子集成功。

+0

@ Dave18我粘貼了我到目前爲止所嘗試的內容,這是我的主要問題 – qwertymk 2011-01-09 04:12:23

2

MSDN擁有使用剪貼板API操作剪貼板數據時需要知道的所有示例。