gpt4 book ai didi

delphi - 如何可靠地检测剪贴板上的 RITCHTEXT 格式?

转载 作者:行者123 更新时间:2023-12-03 15:20:56 29 4
gpt4 key购买 nike

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

但我没有找到任何支持的 CF_RTFCF_RICHTEXT 格式描述符来指示剪贴板中的富文本格式。

因此,我在 Microsoft WordPad 中创建了一些格式化文本并将其复制到剪贴板。然后我使用剪贴板 spy 程序来检查剪贴板上的格式:

enter image description here

这里列出了 3 种 RichText 格式,其格式描述符为 C078C16BC1A5

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

最佳答案

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

不可以,您需要通过RegisterClipboardFormat注册RTF剪贴板格式功能。返回值由系统生成,可能会有所不同。

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 ... }
<小时/>

编辑:阅读文档后:How to Use Rich Edit Clipboard Operations

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

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

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

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 公共(public)控件使用的自定义格式,并通过 RegisterClipboardFormat 注册,如前所述。

关于delphi - 如何可靠地检测剪贴板上的 RITCHTEXT 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45837425/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com