問題描述
我想我過去可能問過類似的問題,但我仍然卡住了......
I think I may have asked a similar question in the past, but I am still stuck...
作為自動化流程的一部分,我必須將媒體文件的特定子集導(dǎo)入"到封閉源代碼的第三方應(yīng)用程序(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 個特定文件必須導(dǎo)入到應(yīng)用程序中.
- 應(yīng)用中沒有必須接收文件的導(dǎo)入功能.
- 這個相同的應(yīng)用確實允許您將文件拖放到特定窗格中,這允許您從本質(zhì)上導(dǎo)入它們.
- 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.
我目前使用的解決方法非常不穩(wěn)定和丑陋,并且使用正則表達式查詢的復(fù)雜過程來隔離 Xplorer2 中的文件,然后使用 AutoIT 選擇它們,最后將它們拖到應(yīng)用程序中.
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.
建議的解決方案:
我需要一種在任何給定時間將我需要的特定視頻文件子集拖放到此應(yīng)用程序中的方法,最好不要自動單擊和光標(biāo)移動(此設(shè)置中有太多故障點).
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).
我本質(zhì)上只是將文件名列表傳遞給應(yīng)用程序(通過將它們拖到那里),所以我認(rèn)為必須有一種方法可以純粹在代碼中自動進行這種拖放 - 可能使用 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.
如果有人能指出我正確的方向(編程語言無關(guān)緊要;我會學(xué)習(xí)我需要知道的任何東西),最好給我一個基本大綱或示例,說明我如何完成這樣的任務(wù), 我真的很感激!這已經(jīng)讓我發(fā)瘋一年多了!
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) 注入目標(biāo)進程
2) 獲取目標(biāo)窗口的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) 使用您的文件創(chuàng)建 IDataObject
3) Create IDataObject with your files
4) 調(diào)用 IDropTarget.DragEnter
4) Call IDropTarget.DragEnter
5) 調(diào)用 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) 創(chuàng)建 13 個名稱的固定文件
3) Create fixed file with 13 names
4) 將步驟 1 中注冊的唯一消息發(fā)送到目標(biāo)窗口
4) Send unique message registered in steip 1 to target window
5) 你的鉤子會被加載到目標(biāo)進程中
5) You hook will be loaded into target process
6) 內(nèi)部鉤子程序檢查消息
6) Inside hook procedure check message
7) 如果消息是您的唯一消息
7) If message is your unique message
7.1) 獲取目標(biāo)窗口的IDropTarget
7.1) Get IDropTarget of target window
7.2) 從固定文件加載名稱
7.2) Load names from fixed file
7.3) 使用您的文件創(chuàng)建 IDataObject
7.3) Create IDataObject with your files
7.4) 調(diào)用 IDropTarget.DragEnter
7.4) Call IDropTarget.DragEnter
7.5) 調(diào)用 IDropTarget.Drop
7.5) Call IDropTarget.Drop
8) 如果所有文件尚未處理,則轉(zhuǎn)到 3
8) If all files don’t processed yet then go to 3
9) 卸載全局鉤子
更新 2
您也可以嘗試從掛鉤 dll 向目標(biāo)窗口發(fā)送 WM_DROPFILES 消息.
Also you can try send WM_DROPFILES message to target window from you hook dll.
這篇關(guān)于用代碼模擬窗口拖放?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!