开发者

What do various clipboard/drag-and-drop formats mean?

I was playing around with drag and drop. I made a sample application and dropped a file from folder My Music onto my a开发者_开发知识库pplication. Here's what e.Data.GetFormats() returned:

  • Shell IDList Array
  • UsingDefaultDragImage
  • DragImageBits
  • DragContext
  • DragSourceHelperFlags
  • InShellDragLoop
  • FileDrop
  • FileNameW
  • FileName
  • IsShowingLayered
  • DragWindow
  • IsComputingImage
  • DropDescription
  • DisableDragText
  • ComputedDragImage
  • IsShowingText

What do each of these mean and how to decode and use them?

Googling each of them didn't yield any useful information.


DragImageBits describes the image that's displayed when you drag stuff. Its header is described by 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);

One should still use DragDropHelper instead for better compatibility.


FileDrop is standard, covered by the DataFormats class. Shell IDList and FileName/W are common for Windows Explorer. The rest of them are all custom. By their names, it sounds like they enhance the D+D feedback when you drag to other Microsoft apps, like Media Player. This stuff is poorly documented, possibly intentional.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜