I need to react on the user drag an drop action on my form.
Accepting files from explorer was not difficult, but acceping OLE objects (Outlook E-Mail) drop is to difficult to me to handle myself.
So far I have a Delphi form with implemented IDropTarget interface.
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;
Here is the Drop method implementation:
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;
This implementation adds the preview of the message to the Memo.
How to save message recieved from Outlook onto the hard drive? I would apreciate samples in any language, even in the pseudo code.
i dealt with Outlook
IDataObjects before.Outlook exposes the same
CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTSas regular shell objects from Explorer.When i enumerate the formats in the
IDataObjecti see them:i use Drag-Drop when dropping onto a
VirtualStringTree, but the shell concepts are the same. i can repost snippets of my code (which eventually saves the Outlook e-mails to a database)The trick above is we enumerate the formats that
IDataObjectcontains. We likeCF_FILEDESCRIPTOR, and handle it specially:And my application has a callback so it can put the file where it wants. In my case i stuff the file into an object so it can be saved to a database later: