• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1261
  • Last Modified:

Drag and drop Outlook and/or Groupwise email

Is there a way to drag and drop an email message from Outlook and/or Groupwise into my D5 application?  If so, any pointers (no pun intended) on how to do it?
0
bjones8888
Asked:
bjones8888
  • 2
1 Solution
 
Lee_NoverCommented:
yes..  with OLE d&d
register a control as a droptarget with RegisterDragDrop :)
you'll need to implement IDropTarget
then in the implementation handle the IDataObject

here's a starter helper unit to get a list of files from an IDataObject

you'll need to figure out what kind of data Outlook "drags" and handle it
it probably provides a few formats



{-----------------------------------------------------------------------------
 Unit Name: DragDropHelpers
 Author:    Lee_Nover
 Date:      2004.10.26
 Purpose:   Helper functions for OLE Drag&Drop
 Copyright: Lee_Nover - Lee_Nover@delphi-si.com
 History:
  2004.10.26
    first implementation
    ReadFilesFrom* functions are taken from Drag&Drop suite:
      Drag and Drop Component Suite Version 4.0
      Released 18-may-2001
      © 1997-2001 Angus Johnson & Anders Melander

-----------------------------------------------------------------------------}
unit DragDropHelpers;

interface

uses Classes, ActiveX;

function FilesFromIDataObject(ADataObject: IDataObject; AFiles: TStrings): Integer;

implementation

uses Windows, ShlObj;

function ReadFilesFromZeroList(Data: pointer; Size: integer;
  Wide: boolean; Files: TStrings): boolean;
var
  StringSize: Integer;
begin
  Result := False;
  if (Data <> nil) then
    while (Size > 0) and (PChar(Data)^ <> #0) do
    begin
      if (Wide) then
      begin
        Files.Add(PWideChar(Data));
        StringSize := (Length(PWideChar(Data)) + 1) * 2;
      end else
      begin
        Files.Add(PChar(Data));
        StringSize := Length(PChar(Data)) + 1;
      end;
      inc(PChar(Data), StringSize);
      dec(Size, StringSize);
      Result := True;
    end;
end;

function ReadFilesFromData(Data: pointer; Size: integer; Files: TStrings): boolean;
var
  Wide: boolean;
begin
  Files.Clear;
  if (Data <> nil) then
  begin
    Wide := PDropFiles(Data)^.fWide;
    dec(Size, PDropFiles(Data)^.pFiles);
    inc(PChar(Data), PDropFiles(Data)^.pFiles);
    ReadFilesFromZeroList(Data, Size, Wide, Files);
  end;

  Result := (Files.Count > 0);
end;

function ReadFilesFromHGlobal(const HGlob: HGlobal; Files: TStrings): boolean;
var
  DropFiles: PDropFiles;
begin
  DropFiles := PDropFiles(GlobalLock(HGlob));
  try
    Result := ReadFilesFromData(DropFiles, GlobalSize(HGlob), Files)
  finally
    GlobalUnlock(HGlob);
  end;
end;

function FilesFromIDataObject(ADataObject: IDataObject; AFiles: TStrings): Integer;
var
  I: Integer;
  Data: TStgMedium;
  SOF: TFormatEtc;
  Enum: IEnumFORMATETC;
begin
  Result:=0;
  if ADataObject = nil then
    exit;

  ZeroMemory(@Data, SizeOf(Data));
  ADataObject.EnumFormatEtc(DATADIR_GET, Enum);
  while (Enum.Next(1, SOF, @I) = S_OK) and (I > 0) do
    if SOF.cfFormat = CF_HDROP then
    begin
      if Succeeded(ADataObject.GetData(SOF, Data)) then
      try
        case SOF.tymed of
          TYMED_FILE: AFiles.Text:=Data.lpszFileName;
          TYMED_HGLOBAL: ReadFilesFromHGlobal(Data.hGlobal, AFiles);
          else exit;
        end;
        Result:=AFiles.Count;
        exit;
      finally
        ReleaseStgMedium(Data);
      end;
    end;
end;

end.
0
 
bjones8888Author Commented:
Wow.  Some of this is beyond my current Delphi experience.  Can you email me? (bob@cycominc.com)  
Thanks.
0
 
Lee_NoverCommented:
although the comment was accepted we can continue the conversation here ... which I'd prefer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now