我正在尝试获取多个 Outlook剪贴板中的附件。
当用户选择多个附件并将它们放入剪贴板(或拖动它们)时,将创建一个 IDataObject
并将其放入剪贴板。
我知道可以使用包含虚拟对象名称的 CLIPFORMAT CFSTR_FILEDESCRIPTOR
在 IDataObject
中找到文件名。此外,据我所知,正在使用 CLIPFORMAT CFSTR_FILECONTENTS
接收文件内容。但是当我这样做时,我只得到一个文件,而且我不明白如何获得已复制到剪贴板的其他文件。
我发现使用 FORMATETC
中的 lindex
成员我可以获得其他文件,但由于某些原因它不起作用。
任何人都可以解释或举例说明如何获得其他附件(更喜欢 C++)吗?
最佳答案
看看 CodeProject Outlook Drag-n-Drop example .它在包装类 OutlookDataObject
中使用 IDataObject
,但它与 Clipboard 使用的接口(interface)相同。在 C# 中,您可以执行以下操作...
// IDataObject wrapper
OutlookDataObject dataObject = new OutlookDataObject(Clipboard.GetDataObject());
// retrieving filenames
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
this.label1.Text = "filenames:\n " + string.Join(",", filenames) + "\n";
// writing out file contents
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
this.label1.Text += "Files:\n";
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
//use the fileindex to get the name and data stream
string filename = filenames[fileIndex];
MemoryStream filestream = filestreams[fileIndex];
this.label1.Text += " " + filename + "\n";
//save the file stream using its name to the application path
FileStream outputStream = File.Create(filename);
filestream.WriteTo(outputStream);
outputStream.Close();
}
查看 OutlookDataObject
包装类,您应该能够在 C++ 中实现类似的东西。
关于c++ - 从剪贴板获取多个 Outlook 附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11041005/