Why does my form not receive WM_DropFiles when files are dropped onto it?

I am using Embarcadero RAD Studio XE for application development. I am trying to catch a drag file into an application with the following code

TMainForm = class(TForm) public: procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES; end; procedure TMainForm.FormCreate(Sender: TObject); begin DragAcceptFiles(Self.Handle, True); end; procedure TMainForm.FormDestroy(Sender: TObject); begin DragAcceptFiles(Self.Handle, False); end; procedure TMainForm.WMDropFiles(var Msg: TWMDropFiles); begin inherited; showmessage('catch here'); // some code to handle the drop files here Msg.Result := 0; end; 

This code was executed without problems. Also, when I drag and drop files, the cursor shows that the status has changed to drag, but after everything has happened, nothing happens (no message is displayed). Is there something wrong with this?

+4
source share
2 answers

In a normal application, the vanilla code in question causes WMDropFiles to execute when the object is dropped on the form. Thus, it is obvious that something else is happening to stop it from working. The most obvious potential causes are:

  • The main handle to the form window is created after the initial call to DragAcceptFiles .
  • Your process runs at a higher level of integrity than a process that deletes files on it. For example, you start your process as an administrator. Please note: starting the Delphi IDE as an administrator will cause your process to start as an administrator when starting from the IDE.
  • Something else in your process is preventing drag and drop. Not knowing what is in your application, it's hard to guess what it could be. Start removing parts of your application until there is nothing left but code in this question.

Option 2 seems quite plausible. To learn more, see Q: Why does Drag-and-Drop not work when the application is running? - A: Mandatory Integrity Control and UIPI

+7
source

in TForm.Create use two lines

 ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD); ChangeWindowMessageFilter (WM_COPYGLOBALDATA, MSGFLT_ADD); 

what all

+3
source

All Articles