2010-08-13 76 views
5

我正在玩拖放。我做了一個示例應用程序,並將文件從文件夾My Music中刪除到我的應用程序。下面是e.Data.GetFormats()返回:各種剪貼板/拖放格式的含義是什麼?

  • 殼牌陣列IDList表
  • UsingDefaultDragImage
  • DragImageBits
  • DragContext
  • DragSourceHelperFlags
  • InShellDragLoop
  • FileDrop
  • FileNameW
  • 文件名
  • IsShowingLayered
  • DragWindow
  • IsComputingImage
  • DropDescription
  • DisableDragText
  • ComputedDragImage
  • IsShowingText

什麼是每一種含義及如何解碼和使用它們?

使用谷歌搜索他們沒有得到任何有用的信息。

回答

1

FileDrop是標準的,由DataFormats類覆蓋。 Windows資源管理器常用Shell IDList和FileName/W。其餘的人都是習慣的。按照他們的名字,這聽起來像是當你拖動到其他微軟應用程序(如媒體播放器)時,它們會增強D + D反饋。這些東西記錄不完整,可能是故意的。

4

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來代替更好的兼容性。

+0

+1 - 我用這個代碼的一些不同的答案:http://stackoverflow.com/a/8468171/25216雖然這工作,它可以通過使用BinaryReader簡化。 – 2011-12-12 01:42:03

+0

我在繪製顏色時遇到了麻煩。大多數顏色與原始顏色完美匹配,但白色區域顯示爲灰色? – Karel 2013-03-09 02:44:36