目前共有2篇帖子。 内容转换:不转换▼
 
点击 回复
283 1
【原创程序】剪切板内容导出程序
一派护法 十九级
1楼 发表于:2016-1-24 22:17
【功能】
查看当前剪切板中有哪些格式的剪切板内容(显示出格式编号,名称以及内容的字节数),输入要保存的剪切板格式编号和文件名即可导出到文件。
【代码】
// ClipboardExporter.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <Windows.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    UINT format = 0;
    TCHAR name[50];
    char filename[MAX_PATH];
    HGLOBAL hMem;
    size_t size;
    OpenClipboard(NULL);
    while (format = EnumClipboardFormats(format))
    {
        GetClipboardFormatName(format, name, sizeof(name) / sizeof(TCHAR));
        cout << '[' << format << ']';
        wcout << name;
        hMem = GetClipboardData(format);
        size = GlobalSize(hMem);
        cout << ", " << size << " bytes";
        cout << endl;
    }
    cout << endl << "Which one would you like to save as a file?" << endl;
    cin >> format;
    if (IsClipboardFormatAvailable(format))
    {
        cout << "Input the file name:" << endl;
        cin >> filename;
        ofstream file(filename, ios::binary);
        hMem = GetClipboardData(format);
        size = GlobalSize(hMem);
        char *data = (char *)GlobalLock(hMem);
        file.write(data, size);
        GlobalUnlock(hMem);
        file.close();
        cout << "File saved, " << size << " bytes written." << endl;
    }
    else
        cout << "File not saved." << endl;
    CloseClipboard();
    system("pause");
    return 0;
}
【运行效果】

从中可以看到剪切板中有RTF格式,其编号为49311。于是输入49311,并输入文件名,扩展名为rtf。保存后,可用Word或者写字板打开查看剪切板中的RTF格式的完整内容。
打开保存的rtf文件,内容如下:
一派护法 十九级
2楼 发表于:2016-1-24 22:17

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:283 回复数:1
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2016-1-24 22:17
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。