I am using Embarcadero RAD Studio XE to develop an application. I am trying catch the file(s) drag and drop to the 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 complied without problem. Also, when I drag and drop files, the cursor show that the status changed to drag and drop but after things dropped, nothing happen (no message shown too). Is that anything wrong with that?
in TForm.Create
use two lines
ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter (WM_COPYGLOBALDATA, MSGFLT_ADD);
that's all
In a plain vanilla application, the code in the question results in WMDropFiles
executing when an object is dropped on the form. So, clearly there's something else happening to stop it working. The most obvious potential causes are:
DragAcceptFiles
.Option 2 seems quite plausible. To learn more see: Q: Why Doesn’t Drag-and-Drop work when my Application is Running Elevated? – A: Mandatory Integrity Control and UIPI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With