我找到了一个脚本(http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C),可以将图像拖动到c#应用程序中。(特别是从outlook) fileDrop格式是用来复制(拖动)图像从我的硬盘到c#应用程序。当图像存储在我的硬盘上时,这工作得很好,但当我试图直接从存储卡(从相机或智能手机(如三星S3))拖动图像时,它将不起作用。这些是我从这些图片中获取的拖动格式:
(0): "Shell IDList Array"
(1): "FileContents"
(2): "FileGroupDescriptorW"
(3): "WPD Storage Attributes"
(4): "Preferred DropEffect"
(5): "WPD NSE"
(6): "WPD NSE PnPDevicePath"
(7): "WPD NSE StoragePUID"
(8): "UsingDefaultDragImage"
(9): "DragImageBits"
(10): "DragContext"
(11): "DragSourceHelperFlags"
(12): "InShellDragLoop"
(13): "IsShowingLayered"
(14): "DragWindow"
(15): "IsComputingImage"
(16): "DataObjectAttributes"
(17): "DisableDragText"
(18): "IsShowingText"
(19): "DropDescription"
(20): "ComputedDragImage"
(21): "Logical Performed DropEffect"
(22): "Performed DropEffect"
(23): "Paste Succeeded"
当我尝试访问'FileGroupDescriptorW'时,我收到一个非法访问违规错误。此外,"FileGroupDescriptor"似乎在这里失踪?有人能帮我解决这个问题吗?我搜索了这个网站和谷歌,但没有找到任何有用的。
解决方案是由John Schroedl发布的,隐藏在该主题的许多反应中。
这两个'修复'解决了我的问题:
http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C?msg=3535951 xx3535951xx
老c#:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class FILEGROUPDESCRIPTORA
{
public uint cItems;
public FILEDESCRIPTORA[] fgd;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public sealed class FILEGROUPDESCRIPTORW
{
public uint cItems;
public FILEDESCRIPTORW[] fgd;
}
固定c#: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class FILEGROUPDESCRIPTORA
{
public uint cItems;
public FILEDESCRIPTORA fgd;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public sealed class FILEGROUPDESCRIPTORW
{
public uint cItems;
public FILEDESCRIPTORW fgd;
}
这个修复:http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C?msg=3551197#xx3551197xx
旧:
case "FileContents":
//override the default handling of FileContents which returns the
//contents of the first file as a memory stream and instead return
//a array of MemoryStreams containing the data to each file dropped
//get the array of filenames which lets us know how many file contents exist
string[] fileContentNames = (string[])this.GetData("FileGroupDescriptor");
修复:
case "FileContents":
//override the default handling of FileContents which returns the
//contents of the first file as a memory stream and instead return
//a array of MemoryStreams containing the data to each file dropped
//
// FILECONTENTS requires a companion FILEGROUPDESCRIPTOR to be
// available so we bail out if we don't find one in the data object.
string fgdFormatName;
if (GetDataPresent("FileGroupDescriptorW"))
fgdFormatName = "FileGroupDescriptorW";
else if (GetDataPresent("FileGroupDescriptor"))
fgdFormatName = "FileGroupDescriptor";
else
return null;
//get the array of filenames which lets us know how many file contents exist
string[] fileContentNames = (string[])this.GetData(fgdFormatName);
如果有人需要…