Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataFormats.GetFormat允许我创建新的私有格式吗?_C#_.net_Winforms_Base Class Library - Fatal编程技术网

C# DataFormats.GetFormat允许我创建新的私有格式吗?

C# DataFormats.GetFormat允许我创建新的私有格式吗?,c#,.net,winforms,base-class-library,C#,.net,Winforms,Base Class Library,我尝试了以下方法: DataFormats.Format binaryData = DataFormats.GetFormat("BinaryData"); 返回的binaryData.Id为50151 我可以假设“BinaryData”严格地说是我的私有名称,还是一个众所周知的名称 我这样问是因为我正在与第三方应用程序(colaSoft)进行接口,它将名为BinaryData的格式(Id也为Id也为50151)推送到剪贴板。这只是巧合吗?如何确定Id?来自以下文档: 此方法也可用于注册新格式

我尝试了以下方法:

DataFormats.Format binaryData = DataFormats.GetFormat("BinaryData");
返回的binaryData.Id为50151

我可以假设“BinaryData”严格地说是我的私有名称,还是一个众所周知的名称


我这样问是因为我正在与第三方应用程序(colaSoft)进行接口,它将名为
BinaryData
的格式(Id也为
Id
也为50151)推送到剪贴板。这只是巧合吗?如何确定
Id

来自以下文档:

此方法也可用于注册新格式。如果找不到指定的格式,将自动将其注册为新的数据格式

这并不能回答您的问题:

我可以假设“BinaryData”严格地说是我的私有名称,还是一个众所周知的名称

因此,下一步是查看该方法的源代码

    public static Format GetFormat(string format) {
        lock(internalSyncObject) {
            EnsurePredefined();

            // It is much faster to do a case sensitive search here.  So do 
            // the case sensitive compare first, then the expensive one.
            //
            for (int n = 0; n < formatCount; n++) {
                if (formatList[n].Name.Equals(format))
                    return formatList[n];
            }

            for (int n = 0; n < formatCount; n++) {
                if (String.Equals(formatList[n].Name, format, StringComparison.OrdinalIgnoreCase))
                    return formatList[n];
            }

            // need to add this format string
            //
            int formatId = SafeNativeMethods.RegisterClipboardFormat(format);
            if (0 == formatId) {
                throw new Win32Exception(Marshal.GetLastWin32Error(), SR.GetString(SR.RegisterCFFailed));
            }


            EnsureFormatSpace(1);
            formatList[formatCount] = new Format(format, formatId);
            return formatList[formatCount++];
        }
    }
现在,请参阅以下文档:

如果已存在具有指定名称的已注册格式,则会出现新的 未注册格式,返回值标识现有格式 格式。这使多个应用程序能够复制和粘贴数据 使用相同的注册剪贴板格式。请注意,格式名称 比较不区分大小写

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

根据这一点以及每个会话只有一个剪贴板的事实,您应该能够推断出格式ID在给定会话中是通用的

至于ID是如何生成的,我无法回答这一部分 我没有访问该代码的权限

    [DllImport(ExternDll.User32, SetLastError=true, CharSet=System.Runtime.InteropServices.CharSet.Auto)]
    [ResourceExposure(ResourceScope.None)]
    public static extern int RegisterClipboardFormat(string format);