How do I allow dropping files on a specific control only? lazarus / 31-LCL ---------------------------------------------------------------------- dummzeuch · 2016-06-26 11:22 I know about the AllowDropFiles property of a form and the associated OnDropFiles event. While this works fine, I want to allow dropping of files only to a particular control (a TEdit in this case). The only solution I found through google is using the form's AllowDropFiles/OnDropFiles and in the event check the mouse position to find out on which control the user dropped the files. So the code can ignore any files dropped outside the control I want to accept the files. This is an option, but it will give no visual feedback to the user on whether a control accepts files or not. Is there any way to give that feedback? Since this is for Windows only I also tried to implement the functionality using the Windows API DragAcceptFiles. In that case, the visual feedback to the user works fine, but unfortunately my code never gets the WM_DROPFILES message because it apparently already gets handled somewhere inside the LCL. Can I somehow get this message? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TWindowProcHook.Create(_WinControl: TWinControl);begin  inherited Create;  FCtrl := _WinControl;   FOldWindowProc := FCtrl.WindowProc;  FCtrl.WindowProc := NewWindowProc;  DragAcceptFiles(FCtrl.Handle, True);end; procedure TWindowProcHook.NewWindowProc(var _Msg: TMessage);begin  if _Msg.Msg = WM_DROPFILES then   // the code never gets here    WmDropFiles(_Msg);  // more code hereend;  In the debugger I can see that the WM_DROPFILES message arrives and gets handled in function TWindowProcHelper.DoWindowProc. So, how do I get at it? ---------------------------------------------------------------------- dummzeuch · 2016-06-26 12:44 One way that seems to work is this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor Tf_SyncDpr.Create(_Owner: TComponent);begin  inherited;  Application.OnDropFiles := @AppDropFiles;  DragAcceptFiles(ed_DprTo.Handle, True);end; procedure Tf_SyncDpr.AppDropFiles(Sender: TObject; const FileNames: array of string);begin  ed_DprTo.Text := FileNames[0];end;  I'm not sure whether this could be made to play nice with multiple forms that accept files. Also, the form probably must remove the event when it gets destroyed. All that does not matter for my simple use case where there is only one form in the application. The Sender parameter apparently is the application object, so there is no way to determine the drop target if there are more than one. One can probably resort to using the mouse position for that which is less than optimal. ---------------------------------------------------------------------- dummzeuch · 2016-06-27 21:24 Found a solution for the multiple forms support dropping files: Instead of assigning an event handler to Application.OnDropFiles, add one using Application.AddOnDropFilesHandler. And don't forget to remove it in the destructor with Application.RemoveOnDropFilesHandler or Application.RemoveAllHandlersOfObject.