Simulate windows drag and drop with code?

前端 未结 2 427
我寻月下人不归
我寻月下人不归 2021-01-24 00:50

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

相关标签:
2条回答
  • 2021-01-24 01:36

    Mouse move/click is probably the best solution in this case. Here is something you can try. Assuming you are using windows since you put c# in the title

    1. open up the folder
    2. move mouse to the search box of the folder ( does not have to be hard coded coordinate, some GUI tool can recognize it)
    3. use send string method to input the name of the file that you wish to import
    4. move mouse to select the first result
    5. mouse down
    6. use either pixel detection or GUI tool's detection to determine the coordinate of the panel that you wish to drop on
    7. drop it and do some error check.

    OR

    If you are an expert of Windows you can try to do some inter process communication to send the drag and drop event to the program.

    0 讨论(0)
  • 2021-01-24 01:46

    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.

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