I have a D2006 app and want to implement "open a file by dragging and dropping onto the main form". The code fragments I an using are:
In the main form OnCreate
DragAcceptFiles (Handle, True ) ;
In the main forms private section:
procedure HandleDropFilesMessage (var Message : TWMDropFiles); message WM_DROPFILES;
In the main form's message handler:
procedure TMainForm.HandleDropFilesM
essage (var Message : TWMDropFiles);
var
DropPt : TPoint;
FilesDropped : Integer ;
DroppedFileIndex : Integer ;
DroppedName : Array [0..255] of Char;
S : String;
begin
DragQueryPoint(Message.Dro
p,DropPt);
FilesDropped := DragQueryFile(Message.Drop
, $FFFFFFFF, nil, 0);
for DroppedFileIndex := 1 to FilesDropped do
begin
DragQueryFile(Message.Drop
, pred (DroppedFileIndex), DroppedName, SizeOf(DroppedName));
S := StrPas (DroppedName);
load_file (S) ;
end ;
DragFinish(Message.Drop);
end;
It just doesn't work. When a file is dragged onto the main form, I get the 'cannot drop here' cursor. The strange thing is I have the same code working in another app. There must be some property I'm not setting or something.
Start Free Trial