Simulate windows drag and drop with code?
Question: I think I may have asked a similar question in the past, but I am still
stuck...

As part of an automated process, I must "import" a specific subset of media
files into a closed-source third-party application (Dartfish, incase it
matters). **Here is the situation:**

  * The media (video) files are all in one folder (there are 1000s of them, and reorganization is not an option unfortunately).
  * On any given iteration of the script I am writing, only 13 _specific_ files must be imported into the application.
  * There is no import function in the app that must receive the files.
  * This same app _does_ allow you to drap and drop files into a specific pane, and this allows you to essentially import them.

The current workaround I am using is very unstable and ugly, and uses a
complex procedure of regex queries to isolate the files in Xplorer2, and then
uses AutoIT to select them, and then finally drag them into the application.

**Proposed Solution:**

I need a way to drag and drop the specific subset of video files I need at any
given time into this application, preferably without automating clicks and
cursor movement (there are way too many points of failure in this setup).

I am essentially just passing a list of filenames to the application (by
dragging them there), so I figure there has got to be a way of automating this
drag and drop purely in code - perhaps using C/C#/C++ and the windows API?
Bonus points if the solution can be ported to Python somehow... but not
necessary.

If anyone can point me in the right direction with this (programming language
doesn't matter; I'll learn whatever I need to know), and preferably give me a
basic outline or example of how I can accomplish such a task, I would really
appreciate it! This has been driving me nuts for over a year now!


Answer: 1) Inject into target process

2) Get IDropTarget of target window

    
    
    function GetDropTargetFromWnd(AWnd: HWND): IDropTarget;
    var Unknow: IUnknown;
    begin
      Unknow := IUnknown(GetProp(AWnd, PChar(GlobalFindAtom('OleDropTargetInterface'))));
      if Assigned(Unknow) then
        Unknow.QueryInterface(IDropTarget, Result)
    end;
    

3) Create IDataObject with your files

4) Call IDropTarget.DragEnter

5) Call IDropTarget.Drop

**Updated algorithm:**

1) Register your unique message with RegisterWindowMessage

2) Install global hook with SetWindowsHookEx with WH_CALLWNDPROC type
(additional dll is required)

3) Create fixed file with 13 names

4) Send unique message registered in steip 1 to target window

5) You hook will be loaded into target process

6) Inside hook procedure check message

7) If message is your unique message

7.1) Get IDropTarget of target window

7.2) Load names from fixed file

7.3) Create IDataObject with your files

7.4) Call IDropTarget.DragEnter

7.5) Call IDropTarget.Drop

8) If all files don’t processed yet then go to 3

9) Uninstall global hook

**Update 2**

Also you can try send WM_DROPFILES message to target window from you hook dll.

