如何可靠地检测剪贴板上的RICHTEXT格式? [英] How to reliably detect RICHTEXT format on clipboard?

查看:85
本文介绍了如何可靠地检测剪贴板上的RICHTEXT格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Embarcadero RAD Studio VCL具有 TClipboard.HasFormat 方法,其用法例如 Clipboard.HasFormat(CF_TEXT) Clipboard.HasFormat(CF_BITMAP)等.

Embarcadero RAD Studio VCL has the TClipboard.HasFormat Method, with a usage e.g. Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_BITMAP) etc..

但是我没有找到任何受支持的 CF_RTF CF_RICHTEXT 格式描述符,这些描述符在剪贴板中指示富文本格式.

But I did not find any supported CF_RTF or CF_RICHTEXT format-descriptor which indicates a rich-text format in the clipboard.

因此,我在Microsoft写字板中创建了一些格式化的文本并将其复制到剪贴板.然后,我使用了一个剪贴板间谍程序检查剪贴板上的格式:

So I created some formatted text in Microsoft WordPad and copied it to the clipboard. Then I used a clipboard-spy program to inspect the formats on the clipboard:

这列出了3种RichText格式,格式分别为 C078 C16B C1A5 .

This lists 3 RichText formats with the format-descriptors C078, C16B and C1A5.

这些格式描述符是通用的还是依赖于单个系统或当前情况的?即,我通常可以使用 Clipboard.HasFormat($ C078)来检测剪贴板上的任何RichText格式吗?还是有另一种方法?

Are these format-descriptors universal or dependent from the individual system or from the current situation? I.e., can I generally use Clipboard.HasFormat($C078) to detect any RichText format on the clipboard? Or is there another method?

推荐答案

我通常可以使用 Clipboard.HasFormat($ C078)来检测任何剪贴板上的RichText格式?

Can I generally use Clipboard.HasFormat($C078) to detect any RichText format on the clipboard?

否,您需要通过 RegisterClipboardFormat 函数.返回值是由系统生成的,可能会有所不同.

No, You need to register the RTF clipboard format via RegisterClipboardFormat function. The returned value is generated by the system and may vary.

注册新的剪贴板格式.然后可以将该格式用作有效的剪贴板格式.

Registers a new clipboard format. This format can then be used as a valid clipboard format.

如果已经存在具有指定名称的注册格式,则新格式未注册,并且返回值标识现有格式格式.这使多个应用程序可以复制和粘贴数据使用相同的注册剪贴板格式.

If a registered format with the specified name already exists, a new format is not registered and the return value identifies the existing format. This enables more than one application to copy and paste data using the same registered clipboard format.

var
  CF_RTF: UINT;
...
initialization
  CF_RTF := RegisterClipboardFormat('Rich Text Format');

然后检查:

if Clipboard.HasFormat(CF_RTF) then ...
{ or // if Windows.IsClipboardFormatAvailable(CF_RTF) then ... }


阅读文档后: 如何使用Rich Edit剪贴板操作

常量 CF_RTF 已在 RichEdit 单元中声明为:

The constant CF_RTF is already declared in RichEdit unit as:

CF_RTF                 = 'Rich Text Format';
CF_RTFNOOBJS           = 'Rich Text Format Without Objects'; 
CF_RETEXTOBJ           = 'RichEdit Text and Objects';

因此,对返回的 RegisterClipboardFormat 值使用其他命名可能是一个更好的主意.例如

So it might be a better idea to use other naming for the returned value of RegisterClipboardFormat. e.g.

uses RichEdit;
...
var
  CF_RICHTEXT: UINT;
...
initialization
  CF_RICHTEXT := RegisterClipboardFormat(RichEdit.CF_RTF);

并且:

if Clipboard.HasFormat(CF_RICHTEXT) then ...

注意:已经有一些保留的系统剪贴板格式,例如 CF_TEXT (= 1), CF_BITMAP (= 2)等...但"CF_RTF"或"CF_RICHTEXT"不是其中之一.它是 RICHEDIT 通用控件使用的一种自定义格式,并且已通过 RegisterClipboardFormat 注册,如前所述.

Note: There are already a few reserved system clipboard formats such as CF_TEXT (=1), CF_BITMAP(=2) etc ... but the "CF_RTF" or "CF_RICHTEXT" is not one of them. it is a custom format used by the RICHEDIT common control, and registered via RegisterClipboardFormat as already mentioned.

这篇关于如何可靠地检测剪贴板上的RICHTEXT格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆