用代码模拟窗口拖放?

Simulate windows drag and drop with code?(用代码模拟窗口拖放?)

本文介绍了用代码模拟窗口拖放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我过去可能问过类似的问题,但我仍然卡住了......

I think I may have asked a similar question in the past, but I am still stuck...

作为自动化流程的一部分,我必须将媒体文件的特定子集导入"到封闭源代码的第三方应用程序(Dartfish,以防万一).情况如下:

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:

  • 媒体(视频)文件都在一个文件夹中(有 1000 多个,不幸的是,重组不是一种选择).
  • 在我正在编写的脚本的任何给定迭代中,只有 13 个特定文件必须导入到应用程序中.
  • 应用中没有必须接收文件的导入功能.
  • 这个相同的应用确实允许您将文件拖放到特定窗格中,这允许您从本质上导入它们.
  • 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.

我目前使用的解决方法非常不稳定和丑陋,并且使用正则表达式查询的复杂过程来隔离 Xplorer2 中的文件,然后使用 AutoIT 选择它们,最后将它们拖到应用程序中.

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.

建议的解决方案:

我需要一种在任何给定时间将我需要的特定视频文件子集拖放到此应用程序中的方法,最好不要自动单击和光标移动(此设置中有太多故障点).

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).

我本质上只是将文件名列表传递给应用程序(通过将它们拖到那里),所以我认为必须有一种方法可以纯粹在代码中自动进行这种拖放 - 可能使用 C/C#/C++ 和窗户API?如果解决方案可以以某种方式移植到 Python,则可以加分……但不是必需的.

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!

推荐答案

1) 注入目标进程

2) 获取目标窗口的IDropTarget

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) 使用您的文件创建 IDataObject

3) Create IDataObject with your files

4) 调用 IDropTarget.DragEnter

4) Call IDropTarget.DragEnter

5) 调用 IDropTarget.Drop

5) Call IDropTarget.Drop

更新算法:

1) 使用 RegisterWindowMessage 注册您的唯一消息

1) Register your unique message with RegisterWindowMessage

2) 使用 WH_CALLWNDPROC 类型的 SetWindowsHookEx 安装全局挂钩(需要额外的 dll)

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

3) 创建 13 个名称的固定文件

3) Create fixed file with 13 names

4) 将步骤 1 中注册的唯一消息发送到目标窗口

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

5) 你的钩子会被加载到目标进程中

5) You hook will be loaded into target process

6) 内部钩子程序检查消息

6) Inside hook procedure check message

7) 如果消息是您的唯一消息

7) If message is your unique message

7.1) 获取目标窗口的IDropTarget

7.1) Get IDropTarget of target window

7.2) 从固定文件加载名称

7.2) Load names from fixed file

7.3) 使用您的文件创建 IDataObject

7.3) Create IDataObject with your files

7.4) 调用 IDropTarget.DragEnter

7.4) Call IDropTarget.DragEnter

7.5) 调用 IDropTarget.Drop

7.5) Call IDropTarget.Drop

8) 如果所有文件尚未处理,则转到 3

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

9) 卸载全局钩子

更新 2

您也可以尝试从挂钩 dll 向目标窗口发送 WM_DROPFILES 消息.

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

这篇关于用代码模拟窗口拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:用代码模拟窗口拖放?

基础教程推荐