How do I get file paths of items dropped onto a console application window?

对着背影说爱祢 提交于 2019-12-05 03:35:19

You can just listen for the keyboard. When dragging a file onto a console window the window gets keyboard events as if the file name was entered directly.

That's how you can drop a file on a cmd or PowerShell window and get the full file name as if entered directly and it works the same for your own applications too.

A console application doesn't own its window, csrss.exe does. As a result, even if you locate the window HANDLE, you won't be able to register for drag-and-drop or handle drop messages. Your console application is therefore limited to the types of messages forwarded by csrss.exe through the Console API. They are listed here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683499.aspx Drag-and-drop isn't among them, although mouse event inside the console are.

Your best bet is probably to make an application that LOOKS like a console application, but doesn't use a Windows console. Instead you'd draw text and a cursor on the screen and take keyboard input, creating a command-line interface.

This sort of thing is called a "console emulator", and you can probably find one already built that meets your needs.

You cant because console application has no window. It has standard input, output and error streams.

Window that contain console application is window of CMD application (cmd.exe) and you cant change fundamental behaviors of windows console.

CMD works like terminal (putty, telnet, ssh etc.) - it sends characters from keyboard to application (precisely - it sends characters to "standard input") and displays characters generated by "standard output" of application.

Read a little about standard streams. http://en.wikipedia.org/wiki/Standard_streams

Behavior of CMD.exe under my Windows 7

I can pass filename (with full path) from drag/drop. Dropping one "file icon" on cmd window will "type" filename - but there is no CR/LF (line feed) character, so "readline" function will not work.

Dropping multiple file icons will pass only one file.

Sorry, if i made some language mistakes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!