Simulate windows drag and drop with code?

前端 未结 2 430
我寻月下人不归
我寻月下人不归 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: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.

提交回复
热议问题