Why doesn't my form receive WM_DropFiles when files are dropped on it?

前端 未结 2 1780
遇见更好的自我
遇见更好的自我 2020-12-11 05:38

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

TMainF         


        
相关标签:
2条回答
  • 2020-12-11 06:26

    in TForm.Create use two lines

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

    that's all

    0 讨论(0)
  • 2020-12-11 06:27

    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:

    1. The main form's window handle is re-created after the initial call to DragAcceptFiles.
    2. Your process is running at a higher integrity level than the process that is dropping files on it. For example, are you running your process as administrator. Note that running the Delphi IDE as administrator would lead to your process running as administrator when started from the IDE.
    3. Something else in your process is interfering with drag/drop. Without knowing what's in your app, it's hard to guess what this could be. Start removing portions of your app until there's nothing left but the code in the question.

    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

    0 讨论(0)
提交回复
热议问题