This topic obviously has been hitted over and over again here, but now I just run out of options from my point of view.
OS: Windows XP SP3
So, here is Drag and Drop example for RichEdit I use in my app:
procedure TForm1.AcceptFiles( var msg : TMessage ); // or TWMDROPFILES
const
cnMaxFileNameLen = 255;
var
i,
nCount : integer;
acFileName : array [0..cnMaxFileNameLen] of char;
begin
// find out how many files we're accepting
nCount := DragQueryFile( msg.WParam, // or msg.Drop
$FFFFFFFF,
acFileName,
cnMaxFileNameLen );
// query Windows one at a time for the file name
for i := 0 to nCount-1 do
begin
DragQueryFile( msg.WParam, { or msg.Drop} i,
acFileName, cnMaxFileNameLen );
// do your thing with the acFileName
MessageBox( Handle, acFileName, '', MB_OK );
end;
// let Windows know that you're done
DragFinish( msg.WParam ); // or msg.Drop
end;
Problem is that after some recent changes ( unforutinetly I do not use any SVN so I cannot track which commit was introducing this issue ) Drag and Drop do not work any more.
I have run breakpoints without success in every event that might be somehow related ( called ):
RichEditMouseOver;
RichEditChange;
FormClick;
My app is processing these WM’s:
procedure WMDropFiles(var Msg: TWMDROPFILES); message WM_DROPFILES;
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
procedure WMGetMinMaxInfo(var AMsg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
procedure CMDialogKey(var Msg: TCMDialogKey ); message CM_DIALOGKEY;
On blank project with TRichEdit on form – all is working OK.
Also tried changing DragAcceptFiles() Form1.Handle to RichEdit.Handle – still no luck.
When echo’ing nCount and acFileName parameters, acFileName do not have File Path of Dragged file … Why????
Currently I just have no clue what makes the acFileName parameter losing Dragged files path. Could you suggest where problem is hiding?
I’m afraid I’m not an expert on how Dragging and Dropping files actually works. So I can’t go through your code an figure out what’s wrong.
What I can do is give you the code that I use. It works for me now under Delphi 2009 on XP, Vista and Windows 7. It also worked when I was previously using Delphi 4 on Windows 98 and Windows XP.
Maybe you can figure out what’s wrong in your code using this, or you might want to try using or adapting this code. It is originally from the book: “Delphi 3 – User Interface Design”, pages 169 – 171.
If I’ve left out an important routine, let me know in a comment and I’ll edit my answer to include it.