简体   繁体   English

如何将项目的文件路径放到控制台应用程序窗口中?

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

I'd like to be able to let users drag and drop files onto my console app's window so they are not forced to drag'n'drop files onto the app's icon (or link, or even worse write a command line in console). 我希望能够让用户将文件拖放到我的控制台应用程序窗口,这样他们就不会被迫将文件拖放到应用程序的图标上(或链接,甚至更糟糕的是在控制台中编写命令行)。 How do I get the list of paths of files I drop onto my app's window? 如何获取我放入应用程序窗口的文件路径列表?

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. 这就是你可以在cmd或PowerShell窗口上删除文件并获得完整文件名的方式,就好像直接输入一样,它也适用于你自己的应用程序。

A console application doesn't own its window, csrss.exe does. 控制台应用程序不拥有其窗口, csrss.exe确实如此。 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. 因此,即使您找到窗口HANDLE ,您也无法注册拖放或处理丢弃消息。 Your console application is therefore limited to the types of messages forwarded by csrss.exe through the Console API. 因此,您的控制台应用程序仅限于csrss.exe通过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. 它们列在这里: http//msdn.microsoft.com/en-us/library/windows/desktop/ms683499.aspx拖放不在其中,尽管控制台内有鼠标事件。

Your best bet is probably to make an application that LOOKS like a console application, but doesn't use a Windows console. 您最好的选择可能是使应用程序看起来像一个控制台应用程序,但不使用Windows控制台。 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应用程序(cmd.exe)的窗口,您无法更改Windows控制台的基本行为。

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. CMD的工作方式类似于终端(putty,telnet,ssh等) - 它将字符从键盘发送到应用程序(确切地说 - 它将字符发送到“标准输入”)并显示由应用程序的“标准输出”生成的字符。

Read a little about standard streams. 阅读一些关于标准流的内容。 http://en.wikipedia.org/wiki/Standard_streams http://en.wikipedia.org/wiki/Standard_streams

Behavior of CMD.exe under my Windows 7 我的Windows 7下CMD.exe的行为

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. 在cmd窗口中删除一个“文件图标”将“键入”文件名 - 但没有CR / LF(换行符)字符,因此“readline”功能将不起作用。

Dropping multiple file icons will pass only one file. 删除多个文件图标只会传递一个文件。

Sorry, if i made some language mistakes. 对不起,如果我犯了一些语言错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM