html调用c 客户端,使用 Visual c + + 将 HTML 代码发送到剪贴板 - Visual C++ | Microsoft Docs...

使用 Visual c + + 向剪贴板添加 HTML 代码

04/24/2020

本文内容

本文演示如何使用 Visual c + + 将超文本标记语言(HTML)代码添加到 Microsoft Windows 剪贴板中。

原始产品版本:  Visual c + +

原始 KB 数:  274308

摘要

本文包含一个示例函数,您可以在应用程序中使用该函数简化将 HTML 代码添加到剪贴板的过程。

HTML 剪贴板格式

HTML 有其自己的称为 HTML 格式(CF_HTML)的剪贴板格式,您可以使用它向其他应用程序(如 Excel、Word 或其他 Office 应用程序)提供数据。

CF_HTML 完全是基于文本的格式,其中包括说明、上下文和该上下文中的片段。 生成要发送到剪贴板的数据时,必须包含数据说明,以指示剪贴板版本和上下文和片段的偏移量。 计算偏移量可能是困难部分。 不过,您可以使用以下例程来简化此任务。

有关详细信息,请参阅HTML 剪贴板格式。

示例代码

// CopyHtml() - Copies given HTML to the clipboard.

// The HTML/BODY blanket is provided, so you only need to

// call it like CallHtml("This is a test");

void CopyHTML(char *html)

{

// Create temporary buffer for HTML header...

char *buf = new char [400 + strlen(html)];

if(!buf) return;

// Get clipboard id for HTML format...

static int cfid = 0;

if(!cfid) cfid = RegisterClipboardFormat("HTML Format");

// Create a template string for the HTML header...

strcpy(buf,

"Version:0.9\r\n"

"StartHTML:00000000\r\n"

"EndHTML:00000000\r\n"

"StartFragment:00000000\r\n"

"EndFragment:00000000\r\n"

"

\r\n"

"\r\n");

// Append the HTML...

strcat(buf, html);

strcat(buf, "\r\n");

// Finish up the HTML format...

strcat(buf,

"\r\n"

"\r\n"

"");

// Now go back, calculate all the lengths, and write out the

// necessary header information. Note, wsprintf() truncates the

// string when you overwrite it so you follow up with code to replace

// the 0 appended at the end with a '\r'...

char *ptr = strstr(buf, "StartHTML");

wsprintf(ptr+10, "%08u", strstr(buf, "") - buf);

*(ptr+10+8) = '\r';

ptr = strstr(buf, "EndHTML");

wsprintf(ptr+8, "%08u", strlen(buf));

*(ptr+8+8) = '\r';

ptr = strstr(buf, "StartFragment");

wsprintf(ptr+14, "%08u", strstr(buf, "

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值