I was playing around with drag and drop. I made a sample application and dropped a file from folder My Music onto my application. Here's what e.Data.GetFormats()
returned:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With