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

C# 什么是Windows剪贴板CF_uu格式,如-16230、-15835、-15834等?,c#,winapi,C#,Winapi,我能找到的所有格式都是。在尝试实现文件拖放(从我的应用程序到Windows的文件资源管理器)时,我收到了许多GetData对cfFormat值的请求,如-16230、-15835、-15834,但我不知道它们是什么 [当我尝试使用DoDragDrop功能将文件名从我的应用程序拖到文件资源管理器时,记录完整。] Mouse Down EnumFormatEtc EnumFormatEtc::Next(1) EnumFormatEtc::Next(1) EnumFormatEtc::Reset En

我能找到的所有格式都是。在尝试实现文件拖放(从我的应用程序到Windows的文件资源管理器)时,我收到了许多
GetData
cfFormat
值的请求,如-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-cformat
,但在Windows的API中,它被定义为
CLIPFORMAT-cfFormat
,这反过来又是
typedef-WORD-CLIPFORMAT
,这反过来又是
typedef-unsigned-short-WORD。因此,对我来说,类型不匹配(short和unsignedshort)。我不确定这是否重要。

首先,您正确地指出您的类型不匹配。剪贴板格式未签名。让我们取一个值:

-16230

作为一个有符号的词处理,这是

0xC09A

这并不奇怪。其文档说明如下:

已注册的剪贴板格式由0xC000到0xFFFF范围内的值标识

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

应用程序可以通过定义范围为CF_PRIVATEFIRST到CF_PRIVATELAST的值来识别专用剪贴板格式

CF_PRIVATEFIRST
CF_PRIVATELAST
映射到
0x0200
0x02FF


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

尝试调用
GetClipboardFormatName()