【问题标题】:What do various clipboard/drag-and-drop formats mean?各种剪贴板/拖放格式是什么意思?
【发布时间】:2011-03-29 14:03:30
【问题描述】:

我在玩拖放。我制作了一个示例应用程序,并将文件夹 My Music 中的一个文件拖放到我的应用程序中。这是e.Data.GetFormats() 返回的内容:

  • Shell IDList 数组
  • 使用DefaultDragImage
  • DragImageBits
  • 拖动上下文
  • DragSourceHelperFlags
  • InShellDragLoop
  • FileDrop
  • 文件名W
  • 文件名
  • IsShowingLayered
  • 拖动窗口
  • IsComputingImage
  • DropDescription
  • 禁用拖动文本
  • ComputedDragImage
  • IsShowingText

这些分别是什么意思以及如何解码和使用它们?

谷歌搜索它们中的每一个都没有产生任何有用的信息。

【问题讨论】:

    标签: .net windows drag-and-drop clipboard


    【解决方案1】:

    DragImageBits 描述了拖动内容时显示的图像。其标头由SHDRAGIMAGE 描述。

    var data = e.Data.GetData("DragImageBits") as MemoryStream;
    var buffer = new byte[24];
    data.Read(buffer, 0, 24);
    int w = buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24);
    int h = buffer[4] + (buffer[5] << 8) + (buffer[6] << 16) + (buffer[7] << 24);
    // Stride accounts for any padding bytes at the end of each row. For 32 bit
    // bitmaps there are none, so stride = width * size of each pixel in bytes.
    int stride = width * 4;
    // x and y is the relative position between the top left corner of the image and
    // the mouse cursor.
    int x = buffer[8] + (buffer[9] << 8) + (buffer[10] << 16) + (buffer[11] << 24);
    int y = buffer[12] + (buffer[13] << 8) + (buffer[14] << 16) + (buffer[15] << 24);
    buffer = new byte[stride * h];
    // The image is stored upside down, so we flip it as we read it.
    for (int i = (h - 1) * stride; i >= 0; i -= stride) data.Read(buffer, i, stride);
    BitmapSource.Create(w, h, 96, 96, PixelFormats.Bgra32, null, buffer, stride);
    

    为了更好的兼容性,仍应使用DragDropHelper

    【讨论】:

    • +1 - 我使用其中一些代码来获得不同的答案:stackoverflow.com/a/8468171/25216 虽然这可行,但可以使用 BinaryReader 来简化它。
    • 我在绘制颜色时遇到了麻烦。大多数颜色与原始颜色完美匹配,但白色区域显示为灰色?
    【解决方案2】:

    FileDrop 是标准的,包含在 DataFormats 类中。 Shell IDList 和 FileName/W 在 Windows 资源管理器中很常见。其余的都是定制的。从他们的名字来看,当您拖动到其他 Microsoft 应用程序(如媒体播放器)时,它们听起来像是增强了 D+D 反馈。这些东西记录不充分,可能是故意的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      • 2015-05-11
      • 1970-01-01
      • 2012-07-21
      • 2011-01-28
      • 2018-01-12
      • 2010-12-09
      相关资源
      最近更新 更多