[SOLVED] Files drag&drop is broken on Windows 10? lazarus / 34-Windows ---------------------------------------------------------------------- edgen · 2023-06-30 18:10 Hello, I need to allow user to drop files onto my form from Windows Explorer. The fastest way (set form's AllowDropFiles to true, and use OnDropFiles handler to process the dropped files) didn't work for me, the OnDropFiles just doesn't fire. Then I wrote Windows-specific code to use OLE drag&drop, with implementation of IDropTarget and registering my form as drop target. And it also doesn't work from Explorer. But I've tried to drag files from FarManager (console-based file manager for Windows) and got succeed in it. 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 type   {TFileDropTarget}  TFileDropTarget = class(TInterfacedObject, IDropTarget)  private    FHandle: HWND;    FDropAllowed: Boolean;    procedure SetEffect(var dwEffect: LongWord);    function DragEnter(const dataObj: IDataObject; grfKeyState: LongWord; pt: TPoint; var dwEffect: LongWord): HResult; stdcall;    function DragOver(grfKeyState: LongWord; pt: TPoint; var dwEffect: LongWord): HResult; stdcall;    function DragLeave: HResult; stdcall;    function Drop(const dataObj: IDataObject; grfKeyState: LongWord; pt: TPoint; var dwEffect: LongWord): HResult; stdcall;  public    constructor Create(AHandle: HWND);    destructor Destroy; override;  end; //...implementation procedure TFileDropTarget.SetEffect(var dwEffect: LongWord);begin  dwEffect:=DROPEFFECT_COPY;end; function TFileDropTarget.DragEnter(const dataObj: IDataObject; grfKeyState: LongWord; pt: TPoint; var dwEffect: LongWord): HResult;stdcall;begin  Result := S_OK;  try    FDropAllowed := true;    SetEffect(dwEffect);  except    Result := E_UNEXPECTED;  end;end; function TFileDropTarget.DragLeave: HResult;stdcall;begin  Result := S_OK;end; function TFileDropTarget.DragOver(grfKeyState: LongWord; pt: TPoint; var dwEffect: LongWord): HResult;stdcall;begin  Result := S_OK;  try    SetEffect(dwEffect);  except    Result := E_UNEXPECTED;  end;end; function TFileDropTarget.Drop(const dataObj: IDataObject; grfKeyState: LongWord; pt: TPoint; var dwEffect: LongWord): HResult;stdcall;begin  Result := S_OK;  try    FDropAllowed := true;  if FDropAllowed then begin      MessageDlg('Drop called!', mtInformation, [mbOk], 0);     end;  except    Application.HandleException(Self);  end;end; // ...// Form's OnShowprocedure TfmDocsToLoad.FormShow(Sender: TObject);begin  FDropTarget := TFileDropTarget.Create(Handle) as IDropTarget;end;   So, the code seems to be ok (yes, it accepts any data, but I just want to see if the Drop() method is called actually). Moreover, the same code works fine with Windows Explorer on Windows 7. Then seems like the Windows version does matter, the problem appears on Windows 10 22H2 19045.3086. I've tried to build both 32 and 64 bits apps, the same effect. Used Lazarus version — current trunk, also tested on Lazarus 2.2.6 stable. Did anyone faced such Windows behaviour? Could you please advise me how to make drag&drop working? Best regards, Eugene. ---------------------------------------------------------------------- loaded · 2023-06-30 18:41 Hi, The link below will hopefully help solve your problem. https://forum.lazarus.freepascal.org/index.php/topic,56890.msg422998.h tml#msg422998 ---------------------------------------------------------------------- edgen · 2023-06-30 18:56 Quote from: loaded on June 30, 2023, 08:41:02 pmHi, The link below will hopefully help solve your problem. https://forum.lazarus.freepascal.org/index.php/topic,56890.msg422998.h tml#msg422998 hi, thank you, I've compiled the program from that thread, but unfortunately it doesn't work too. That example uses the same OnDropFiles event, which doesn't fire. Best regards, Eugene. ---------------------------------------------------------------------- Josh · 2023-06-30 19:48 can u try on the file your dragging, press and hold the leftmouse button down, press escape, then release mouse button.  Then try drag and drop ---------------------------------------------------------------------- wp · 2023-06-30 20:27 Quote from: edgen on June 30, 2023, 08:10:03 pmThe fastest way (set form's AllowDropFiles to true, and use OnDropFiles handler to process the dropped files) didn't work for me, the OnDropFiles just doesn't fire. Cannot confirm this: - Laz/main + FPC/3.2.2, Win 11 - Laz 2.2.6 + FPC 3.2.2, Win 11 - Laz 2.0.10 + FPC 3.2.0, Win 11 - Laz 2.0.10 + FPC 3.2.0 on Win 10 Maybe you have some buggy explorer add-on in your system, or some aggressive anti-virus scanner? ---------------------------------------------------------------------- nanobit · 2023-07-01 05:19 Quote from: edgen on June 30, 2023, 08:10:03 pmUsed Lazarus version — current trunk, also tested on Lazarus 2.2.6 stable. Even if the same eventhandler works on most systems, a LCL bug might be hidden and is visible only on specific (your) systems. Consider testing an older Lazarus version (2.0.x or older) on the same system. ---------------------------------------------------------------------- edgen · 2023-07-03 15:31 Thank you everyone! The case is solved, the source of the problem was inside one of Explorer helpers. After switching that helper off I've tested the code shown above on all listed FPC and Lazarus versions, it works fine. Best regards, Eugene.