2010-08-13 10 views
5

Stavo giocando con il drag and drop. Ho creato un'applicazione di esempio e ho scaricato un file dalla cartella My Music sulla mia applicazione. Ecco cosa e.Data.GetFormats() restituito:Che cosa significano vari formati di appunti/trascinamento?

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

Cosa ciascuno di questi significa e come decodificare e li usa ?

Cercare su Google non ha fornito alcuna informazione utile.

risposta

1

FileDrop è standard, coperto dalla classe DataFormats. Shell IDList e FileName/W sono comuni per Windows Explorer. Il resto di loro sono tutti personalizzati. Con il loro nome, sembra che migliorino il feedback D + D quando si trascina su altre app Microsoft, come Media Player. Questa roba è scarsamente documentata, forse intenzionale.

4

DragImageBits descrive l'immagine visualizzata quando si trascina la roba. La sua intestazione è descritta da 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); 

Si dovrebbe comunque usare DragDropHelper invece per una migliore compatibilità.

+0

+1: ho utilizzato parte di questo codice per una risposta diversa: http://stackoverflow.com/a/8468171/25216 Mentre funziona, può essere semplificato utilizzando un BinaryReader. –

+0

Ho problemi con il disegno dei colori .. La maggior parte dei colori corrisponde perfettamente all'originale, ma le regioni bianche appaiono in grigio? – Karel

Problemi correlati