- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要对用户在表单上的拖放操作使用react。从资源管理器接受文件并不困难,但接受 OLE 对象(Outlook 电子邮件)放置对我来说就很难处理了。
到目前为止,我有一个已实现 IDropTarget 接口(interface)的 Delphi 表单。
IDropTarget = interface(IUnknown)
['{00000122-0000-0000-C000-000000000046}']
function DragEnter(const dataObj: IDataObject; grfKeyState: Longint;
pt: TPoint; var dwEffect: Longint): HResult; stdcall;
function DragOver(grfKeyState: Longint; pt: TPoint;
var dwEffect: Longint): HResult; stdcall;
function DragLeave: HResult; stdcall;
function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint;
var dwEffect: Longint): HResult; stdcall;
end;
这是 Drop 方法的实现:
function TForm1.Drop(const dataObj: IDataObject; grfKeyState: Integer;
pt: TPoint; var dwEffect: Integer): HResult;
var
aFmtEtc: TFORMATETC;
aStgMed: TSTGMEDIUM;
pData: PChar;
begin
if (dataObj = nil) then
raise Exception.Create('IDataObject-Pointer is not valid!');
with aFmtEtc do
begin
cfFormat := CF_UNICODETEXT;
ptd := nil;
dwAspect := DVASPECT_CONTENT;
lindex := 0;
tymed := TYMED_ISTREAM Or TYMED_ISTORAGE;
end;
{Get the data}
OleCheck(dataObj.GetData(aFmtEtc, aStgMed));
try
{Lock the global memory handle to get a pointer to the data}
pData := GlobalLock(aStgMed.hGlobal);
{ Replace Text }
Memo1.Text := pData;
finally
{Finished with the pointer}
GlobalUnlock(aStgMed.hGlobal);
{Free the memory}
ReleaseStgMedium(aStgMed);
end;
Result := S_OK;
end;
此实现将消息预览添加到备忘录中。
如何将从 Outlook 收到的邮件保存到硬盘上?我会欣赏任何语言的示例,即使是伪代码。
最佳答案
我之前处理过 Outlook IDataObject
。
Outlook 公开与 Explorer 中的常规 shell 对象相同的 CFSTR_FILEDESCRIPTOR
/CFSTR_FILECONTENTS
。
当我枚举 IDataObject
中的格式时,我看到它们:
0: cfFormat: TClipFormat = "RenPrivateSourceFolder" (49972)
tymed: Longint = 4 (TYMED_ISTREAM)
1: cfFormat: TClipFormat = "RenPrivateMessages" (49587)
tymed: Longint = 4 (TYMED_ISTREAM)
2: cfFormat: TClipFormat = "RenPrivateItem" (49812)
tymed: Longint = 1 (TYMED_HGLOBAL)
3: cfFormat: TClipFormat = CFSTR_FILEDESCRIPTOR ("FileGroupDescriptor", 49281)
tymed: Longint = 1 (TYMED_HGLOBAL)
4: cfFormat: TClipFormat = CFSTR_FILEDESCRIPTORW ("FileGroupDescriptorW", 49280)
tymed: Longint = 1 (TYMED_HGLOBAL)
5: cfFormat: TClipFormat = "FileNameW" (49159)
tymed: Longint = 2 (TYMED_FILE)
6: cfFormat: TClipFormat = CFSTR_FILECONTENTS ("FileContents", 49282)
tymed: Longint = 12 (TYMED_ISTREAM, TYMED_ISTORAGE)
7: cfFormat: TClipFormat = "Object Descriptor" (49166)
tymed: Longint = 1 (TYMED_HGLOBAL)
8: cfFormat: TClipFormat = CF_TEXT (1)
tymed: Longint = 1 (TYMED_HGLOBAL)
9: cfFormat: TClipFormat = CF_UNICODETEXT (13)
tymed: Longint = 1 (TYMED_HGLOBAL)
10: cfFormat: TClipFormat = "CSV" (49993)
tymed: Longint = 1 (TYMED_HGLOBAL)
我在拖放到VirtualStringTree
上时使用拖放,但 shell 概念是相同的。我可以重新发布我的代码片段(最终将 Outlook 电子邮件保存到数据库中)
function HandleOleDrop(DataObject: IDataObject; var DropEffect: TDropEffect;
FileContentsCallback: TFileContentsCallback;
FilenameCallback: TFilenameCallback;
BitmapCallback: TBitmapCallback;
StreamCallback: TStreamCallback): HResult;
var
enum: IEnumFORMATETC;
OLEFormat: TFormatEtc;
Fetched: Integer;
begin
//Go through the formats list in order, looking for the formats we understand.
//The order they are given to us is the order the original application's idea
//of better to worse
Result := DataObject.EnumFormatEtc(DATADIR_GET, enum);
if Failed(Result) then
Exit;
Result := enum.Reset;
if Failed(Result) then
Exit;
while enum.Next(1, OLEFormat, @Fetched) = S_OK do
begin
OutputDebugString(PChar('[HelpDeskShellOperations.HandleOleDrop] ClipboardFormat = ' + ClipFormatToStr(OleFormat.cfFormat)));
if OLEFormat.cfFormat = CF_FILEDESCRIPTOR then
begin
//Transfer data as if it were a file, regardless of how it is actually stored
//If CF_FILEDESCRIPTOR is present, then a CF_FILECONTENTS must also be
//present later on in the formats list
Result := GetFileContents(DataObject, DropEffect, FileContentsCallback);
Break;
end
else if OleFormat.cfFormat = CF_HDROP then
begin
Result := GetHDropContents(DataObject, DropEffect, FilenameCallback);
Break;
end
else if OleFormat.cfFormat = CF_BITMAP then
begin
Result := GetBitmapContents(DataObject, DropEffect, BitmapCallback);
Break;
end;
{ else if OleFormat.cfFormat = CF_PNGStream then
begin
Result := GetStreamContents(OleFormat.cfFormat, DataObject, 'untitled.png', DropEffect, StreamCallback);
Break;
end
else if OleFormat.cfFormat = CF_GIFStream then
begin
Result := GetStreamContents(OleFormat.cfFormat, DataObject, 'untitled.gif', DropEffect, StreamCallback);
Break;
end
else if OleFormat.cfFormat = CF_JFIFStream then
begin
Result := GetStreamContents(OleFormat.cfFormat, DataObject, 'untitled.jpeg', DropEffect, StreamCallback);
Break;
end;}
// else if Formats[i] = ... then
// begin
//Handle another format
// Break;
// end
end;
end;
上面的技巧是我们枚举IDataObject
包含的格式。我们喜欢CF_FILEDESCRIPTOR
,并对其进行特殊处理:
function GetFileContents(DataObject: IDataObject; var Effect: TDropEffect; FileContentsCallback: TFileContentsCallback): HResult;
var
hr: HResult;
format: TFormatEtc;
FileDescriptorMedium: TStgMedium;
fgdGlobal: hGlobal; //global memory object where the descriptors are
fgd: PFileGroupDescriptor; //descriptors
Descriptors: PFileDescriptorArray; //helper to access descriptors dynamic array
nItem: Integer;
FileContentsMedium: TStgMedium;
// stm: IStream;
begin
//1. Extract the CFSTR_FILEDESCRIPTOR format as a TYMED_HGLOBAL value.
ZeroMemory(@format, SizeOf(TFormatEtc));
format.cfFormat := CF_FILEDESCRIPTOR;
format.dwAspect := DVASPECT_CONTENT;
format.tymed := TYMED_HGLOBAL;
ZeroMemory(@FileDescriptorMedium, SizeOf(FileDescriptorMedium));
Result := DataObject.GetData(format, FileDescriptorMedium); //Free the medium at the end
if Failed(Result) then
Exit;
try
//2. The hGlobal member of the returned STGMEDIUM structure points to a
// global memory object. Lock that object by passing the hGlobal value
// to GlobalLock.
fgdGlobal := FileDescriptorMedium.hGlobal;
fgd := GlobalLock(fgdGlobal);
try
//3. Cast the pointer returned by GlobalLock to a FILEGROUPDESCRIPTOR pointer.
// It will point to a FILEGROUPDESCRIPTOR structure followed by one or more
// FILEDESCRIPTOR structures. Each FILEDESCRIPTOR structure contains a
// description of a file that is contained by one of the accompanying
// CFSTR_FILECONTENTS formats.
Descriptors := Addr(fgd.fgd[0]);
//4. Examine the FILEDESCRIPTOR structures to determine which one corresponds
// to the file you want to extract. The zero-based index of that
// FILEDESCRIPTOR structure is used to identify the file's
// CFSTR_FILECONTENTS format. Because the size of a global memory block is
// not byte-precise, use the structure's nFileSizeLow and nFileSizeHigh
// members to determine how many bytes represent the file in the global
// memory object.
for nItem := 0 to fgd.cItems - 1 do
begin
//5. Call IDataObject::GetData with the cfFormat member of the FORMATETC
// structure set to the CFSTR_FILECONTENTS value and the lIndex member
// set to the index that you determined in the previous step. The tymed
// member is typically set to TYMED_HGLOBAL | TYMED_ISTREAM | TYMED_ISTORAGE.
// The data object can then choose its preferred data transfer mechanism.
ZeroMemory(@format, SizeOf(TFormatEtc));
format.cfFormat := CF_FILECONTENTS;
format.dwAspect := DVASPECT_CONTENT;
format.lindex := nItem;
format.tymed := TYMED_HGLOBAL or TYMED_ISTREAM or TYMED_ISTORAGE;
//NOTE: IStorage based files are a bitch to deal with
ZeroMemory(@FileContentsMedium, SizeOf(FileContentsMedium));
//Now get the file's contents
hr := DataObject.GetData(format, FileContentsMedium);
if Failed(hr) then
Continue;
try
{
Progress: nItem+1 of fgd.cItems
}
//6. The STGMEDIUM structure that IDataObject::GetData returns will
// contain a pointer to the file's data. Examine the tymed member of
// the structure to determine the data transfer mechanism.
{ i now have afile's name/size/date/etc in
Descriptors[nItem]
and the guts of file in
FileContentsMedium
(which could actually be in an hGlobal, IStream or IStorage.
Use ConvertStorageMediumToIStream to convert whatever it is into an IStream)
}
// stm := ConvertStorageMediumToIStream(FileContentsMedium);
if Assigned(FileContentsCallback) then
FileContentsCallback(Descriptors[nItem], FileContentsMedium, nItem + 1, fgd.cItems);
finally
//Call ReleaseStgMedium to release the global memory object.
ReleaseStgMedium(FileContentsMedium);
end;
end;
finally
GlobalUnlock(fgdGlobal);
end;
finally
ReleaseStgMedium(FileDescriptorMedium);
end;
end;
我的应用程序有一个回调,因此它可以将文件放在它想要的位置。就我而言,我将文件填充到一个对象中,以便稍后可以将其保存到数据库中:
function TfrmTicketDetail.FileContentsCallback(const Descriptor: TFileDescriptor; const medium: TStgMedium; Progress: Integer; MaxProgress: Integer): Boolean;
var
szFilename: string;
Attachment: TAttachment;
ListItem: TVirtualListItem;
stm: IStream;
vclStream: TStream;
begin
try
szFilename := descriptor.cFilename;
Attachment := TAttachment.Create(dmodGlobal.ADOConnection);
Attachment.RecordID := ToolKit.CreateGUID;
Attachment.AutoGenerateRecordID := false;
Attachment.setStateNew;
Attachment.PrevState := Attachment.State;
Attachment.IsLink := False;
{Helpdesk attachments don't let you save the "date" of the attachment}
if (descriptor.dwFlags and FD_CREATETIME) = FD_CREATETIME then
Attachment.CreationDate := FileTimeToDateTime(descriptor.ftCreationTime)
else if (descriptor.dwFlags and FD_WRITESTIME) = FD_WRITESTIME then
Attachment.CreationDate := FileTimetoDateTime(descriptor.ftLastWriteTime)
else
Attachment.CreationDate := Now;
Attachment.FileName := ExtractFileName(szFilename);
Attachment.FullPath := ExtractFilePath(szFilename);
Attachment.Extension := ExtractFileExt(szFilename);
Attachment.Version := '';
Attachment.Comment := '';
Attachment.TicketGUID := StringToGUID(GUID);
Attachment.UserGUID := StringToGUID(dmodGlobal.UserGUID);
stm := ConvertStorageMediumToIStream(medium);
vclStream := TOleStream.Create(stm);
Attachment.FileStream := vclStream;
{Most often they don't fill in the file size structure member,
so we have to go to the contents to find the size.}
if (descriptor.dwFlags and FD_FILESIZE) = FD_FILESIZE then
begin
Attachment.Size := (Descriptor.nFileSizeLow and $7FFFFFFF);
//Yes, i know, ignoring the upper 32-bits, and throwing away the "sign" bit.
//If you wanna change the database to handle an unsigned 64-bit, you BE MY GUEST - jerk wad
//descriptor.nFileSizeLow or (descriptor.nFileSizeHigh shl 32)
end
else
begin
Attachment.Size := Integer(GetIStreamSize(stm) and $7FFFFFFF);
end;
//Add it to the listivew
ListItem := lvAttachments.Items.Add;
ListItem.Data := Attachment;
olAttachments.Add(Attachment);
TAttachment.RefreshAttachmentListItem(ListItem);
FFlags.SetFlags(FLAG_MODIFIED);
SetStatus(STATUS_MODIFIED);
Result := True;
except
on e: Exception do
begin
Result := False;
MessageDlg('New Attachment Failed: ' + ToolKit.CRLF + e.Message, mtError, [mbOK], 0);
end;
end;
end;
关于delphi - 将 IDropTarget.Drop 方法中获取的 IDataObject 转换为 Outlook 消息并将其保存在磁盘上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4303323/
我正在尝试将一个字符串逐个字符地复制到另一个字符串中。目的不是复制整个字符串,而是复制其中的一部分(我稍后会为此做一些条件......) 但我不知道如何使用迭代器。 你能帮帮我吗? std::stri
我想将 void 指针转换为结构引用。 结构的最小示例: #include "Interface.h" class Foo { public: Foo() : mAddress((uint
这有点烦人:我有一个 div,它从窗口的左上角开始过渡,即使它位于文档的其他任何位置。我试过 usign -webkit-transform-origin 但没有成功,也许我用错了。有人可以帮助我吗?
假设,如果将 CSS3 转换/转换/动画分配给 DOM 元素,我是否可以检测到该过程的状态? 我想这样做的原因是因为我正在寻找类似过渡链的东西,例如,在前一个过渡之后运行一个过渡。 最佳答案 我在 h
最近我遇到了“不稳定”屏幕,这很可能是由 CSS 转换引起的。事实上,它只发生在 Chrome 浏览器 上(可能还有 Safari,因为一些人也报告了它)。知道如何让它看起来光滑吗?此外,您可能会注意
我正在开发一个简单的 slider ,它使用 CSS 过渡来为幻灯片设置动画。我用一些基本样式和一些 javascript 创建了一支笔 here .注意:由于 Codepen 使用 Prefixfr
我正在使用以下代码返回 IList: public IList FindCodesByCountry(string country) { var query =
如何设计像这样的操作: 计算 转化 翻译 例如:从“EUR”转换为“CNY”金额“100”。 这是 /convert?from=EUR&to=CNY&amount=100 RESTful 吗? 最佳答
我使用 jquery 组合了一个图像滚动器,如下所示 function rotateImages(whichHolder, start) { var images = $('#' +which
如何使用 CSS (-moz-transform) 更改一个如下所示的 div: 最佳答案 你可以看看Mozilla Developer Center .甚至还有例子。 但是,在我看来,您的具体示例不
我需要帮助我正在尝试在选中和未选中的汉堡菜单上实现动画。我能够为菜单设置动画,但我不知道如何在转换为 0 时为左菜单动画设置动画 &__menu { transform: translateX(
我正在为字典格式之间的转换而苦苦挣扎:我正在尝试将下面的项目数组转换为下面的结果数组。本质上是通过在项目第一个元素中查找重复项,然后仅在第一个参数不同时才将文件添加到结果集中。 var items:[
如果我有两个定义相同的结构,那么在它们之间进行转换的最佳方式是什么? struct A { int i; float f; }; struct B { int i; float f; }; void
我编写了一个 javascript 代码,可以将视口(viewport)从一个链接滑动到另一个链接。基本上一切正常,你怎么能在那里看到http://jsfiddle.net/DruwJ/8/ 我现在的
我需要将文件上传到 meteor ,对其进行一些图像处理(必要时进行图像转换,从图像生成缩略图),然后将其存储在外部图像存储服务器(s3)中。这应该尽可能快。 您对 nodejs 图像处理库有什么建议
刚开始接触KDB+,有一些问题很难从Q for Mortals中得到。 说,这里 http://code.kx.com/wiki/JB:QforMortals2/casting_and_enumera
我在这里的一个项目中使用 JSF 1.2 和 IceFaces 1.8。 我有一个页面,它基本上是一大堆浮点数字段的大编辑网格。这是通过 inputText 实现的页面上的字段指向具有原始值的值对象
ScnMatrix4 是一个 4x4 矩阵。我的问题是什么矩阵行对应于位置(ScnVector3),旋转(ScnVector4),比例(ScnVector3)。第 4 行是空的吗? 编辑: 我玩弄了
恐怕我是 Scala 新手: 我正在尝试根据一些简单的逻辑将 Map 转换为新 Map: val postVals = Map("test" -> "testing1", "test2" -> "te
输入: This is sample 1 This is sample 2 输出: ~COLOR~[Green]This is sample 1~COLOR~[Red]This is sam
我是一名优秀的程序员,十分优秀!