c# - 什么是 Windows 剪贴板 CF_ 格式,如 -16230、-15835、-15834 等?

标签 c# winapi

我能找到的所有格式都是 these in the MS documentation .当尝试执行文件拖放操作(从我的应用程序到 Windows 的文件资源管理器)时,我收到很多对 cfFormat 值的 GetData 请求,例如 -16230、-15835、- 15834,但我不知道它们是什么。

[当我尝试使用 DoDragDrop 函数将文件名从我的应用程序拖动到文件资源管理器时的完整日志。]

Mouse Down
EnumFormatEtc
EnumFormatEtc::Next(1)
EnumFormatEtc::Next(1)
EnumFormatEtc::Reset
EnumFormatEtc::Next(1)
EnumFormatEtc::Next(1)
QueryGetData(cf = 15, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16230, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15835, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15834, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15833, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16215, ty = TYMED_ISTREAM, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
QueryGetData(cf = -16230, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15797, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
GetData(cf = -16206, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -15832, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
GetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
Returning null.
SetData(cf = -16207, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
SetData(cf = -15864, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)
SetData(cf = -15835, ty = TYMED_HGLOBAL, asp = DVASPECT_CONTENT)

[相关代码]

public void GetData(ref FORMATETC format, out STGMEDIUM medium)
{
    Debug.WriteLine($"GetData(cf = {format.cfFormat}, ty = {format.tymed}, asp = {format.dwAspect})");

    if (format.cfFormat == CF_HDROP &&
        (format.tymed & TYMED.TYMED_HGLOBAL) == TYMED.TYMED_HGLOBAL)
    {
        Debug.WriteLine("Returning file drop data");
        var mem = CreateDropFiles(new[] { file1, file2 
        });

        medium = new STGMEDIUM();
        medium.tymed = TYMED.TYMED_HGLOBAL;
        medium.unionmember = mem;
        medium.pUnkForRelease = IntPtr.Zero;
    }
    else
    {
        Debug.WriteLine("Returning null.");
        medium = new STGMEDIUM();
        medium.tymed = TYMED.TYMED_NULL;
        medium.unionmember = IntPtr.Zero;
        medium.pUnkForRelease = IntPtr.Zero;
    }
}

public int QueryGetData(ref FORMATETC format)
{
    Debug.WriteLine($"QueryGetData(cf = {format.cfFormat}, ty = {format.tymed}, asp = {format.dwAspect})");
    if (format.cfFormat == CF_HDROP)
        return S_OK;
    else
        return DV_E_FORMATETC;
}

public void SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
{
    Debug.WriteLine($"SetData(cf = {formatIn.cfFormat}, ty = {formatIn.tymed}, asp = {formatIn.dwAspect})");
}

我在 System.Runtime.InteropServices.ComTypes 中使用了 FORMATETC,它有 public short cfFormat,但在 Windows 的 API 中,它被定义为 CLIPFORMAT cfFormat,它又是 typedef WORD CLIPFORMAT,它又是 typedef unsigned short WORD;。所以,对我来说,类型不匹配(short 和 unsigned short)。我不确定这是否重要。

最佳答案

首先,您声明类型不匹配是对的。剪贴板格式是无符号的。让我们取一个值:

-16230

当作签名的WORD,这是

0xC09A

这并不奇怪。 RegisterClipboardFormat 的文档是这样说的:

Registered clipboard formats are identified by values in the range 0xC000 through 0xFFFF.

the clipboard formats 的文档中提到了其他可能的值:

An application can identify a private clipboard format by defining a value in the range CF_PRIVATEFIRST through CF_PRIVATELAST

CF_PRIVATEFIRSTCF_PRIVATELAST 映射到 0x02000x02FF

很明显,您看到的是一种已注册的剪贴板格式。要查看它到底是什么类型,您需要在遇到该值时调用 GetClipboardFormatName。它可能会不时更改,因为这些值是在不同组件注册其剪贴板格式时分发的。

关于c# - 什么是 Windows 剪贴板 CF_ 格式,如 -16230、-15835、-15834 等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57863065/

相关文章:

c++ - MFT 的大小与 MFT 的解析

windows - 通过 Go 写入 Windows 注册表

c++ - 如何在 Windows 8 中获取事件窗口的标题颜色

c# - 关于mssql和mysql中的select查询以及表名的保留关键字问题

c# - C# 中的 Spartan 编程示例

c# - Service Fabric 可靠服务管道设计

c++ - 如何在窗口消息中发送 float

c# - 在某些情况下,OptimisticConcurrencyException 在 Entity Framework 中不起作用

c# - 有没有办法删除此代码中的重复项

c++ - SendInput 始终将鼠标指针移动到左上角