开发者

Simulating a drag & drop operation using SendInput

开发者 https://www.devze.com 2023-02-15 14:32 出处:网络
Can SendInput be used to simulate a drap & drop operation? I\'ve got an application that accepts files of a certain format that are dropped on it, but not from the command line, and I want to ass

Can SendInput be used to simulate a drap & drop operation?

I've got an application that accepts files of a certain format that are dropped on it, but not from the command line, and I want to associate it with a file. I thought I'd create a smal开发者_如何转开发l tool that finds the window, and simulates a drag & drop of the file - is this at all possible? Do I need to use SendInput or possibly SendMessage? What would be the parameters?


Yes, pretty likely. SendInput injects mouse events at a very low level. SendMessage won't work.

You'll need a thread since DoDragDrop is a blocking call. Fake the mouse down first, start the thread, call DoDragDrop. The thread should sleep to give enough time for DoDragDrop to get started, then fake mouse move and mouse up. Keep fingers crossed that it works the first time, it is impossible to debug if it doesn't.


The shell already has a function that simulates a drop: SHDoDragDrop, no need for hacks like faking mouse input.

Since you are talking about the commandline, XP added support for simulating D&D for applications/registered file types: How do I accept files to be opened via IDropTarget instead of on the command line?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号