Folks,

I am using Outlook 2003 with Delphi 6 and I am trying to implement COM Drag
and Drop using samples that I have gathered from around the internet.
Unfortunately, for some unknown reason, whenever I drag an Outlook message
over my form, Outlook crashes completely with the 'Send details to
Microsoft' dialog. I am only able to test this on Outlook 2003, so I don't
know if it is version specific. Can anyone tell me if there is a problem
with the following code, or even if it works with previous versions of
Outlook. I don't even get a breakpoint in the DragEnter or DragOver methods,
suggesting that something is wrong with my RegisterDragDrop procedure call.
All help very much appreciated.

The code for my form is posted below. There are no controls on the form.

Many thanks,
Darren



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ActiveX;

type
  TForm1 = class(TForm, IDropTarget)
  protected
    function DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt:
TPoint; var dwEffect: Longint): HResult; stdcall;
    function IDropTarget_DragOver(grfKeyState: Longint; pt: TPoint; var
dwEffect: Longint): HResult; stdcall;
    function IDropTarget.DragOver = IDropTarget_DragOver;
    function DragLeave: HResult; stdcall;
    function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt:
TPoint; var dwEffect: Longint): HResult; stdcall;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

var
  Form1: TForm1;

implementation

uses
  ComObj;

{$R *.dfm}

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  OleInitialize(nil);
  OleCheck(RegisterDragDrop(Handle, Self as IDropTarget));
end;

destructor TForm1.Destroy;
begin
  RevokeDragDrop(Handle);
  OleUninitialize;
  inherited Destroy;
end;

function TForm1.DragEnter(const dataObj: IDataObject; grfKeyState: Longint;
pt: TPoint; var dwEffect: Longint): HResult; stdcall;
begin
  ShowMessage('Beep');
  dwEffect := DROPEFFECT_COPY;
  Result := S_OK;
end;

function TForm1.IDropTarget_DragOver(grfKeyState: Longint; pt: TPoint; var
dwEffect: Longint): HResult; stdcall;
var
  m: TPoint;
  i: Integer;
begin
  ShowMessage('Beep');
  dwEffect := DROPEFFECT_COPY;
  m := pt;
  Windows.ScreenToClient(Handle, m);
  i := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(m.x, m.y));
  SendMessage(Handle, EM_SETSEL, Lo(i), Lo(i));
  Result := S_OK;
end;

function TForm1.DragLeave: HResult; stdcall;
begin
  Result := S_OK;
end;

function TForm1.Drop(const dataObj: IDataObject; grfKeyState: Longint; pt:
TPoint; var dwEffect: Longint): HResult; stdcall;
var
  Medium: TStgMedium;
  Format: TFormatEtc;
begin
  dataObj._AddRef;

  Format.cfFormat := CF_TEXT;
  Format.ptd := nil;
  Format.dwAspect := DVASPECT_CONTENT;
  Format.lindex := -1;
  Format.tymed := TYMED_HGLOBAL;

  if dataObj.GetData(Format, Medium) = S_OK then
  begin
  end;

  dataObj._Release;
  dwEffect := DROPEFFECT_COPY;
  Result := S_OK;
end;

end.


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to