且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在正在运行的Windows控制台应用程序中处理拖放文件

更新时间:2023-10-20 16:27:40

AFAIK,默认情况下,控制台窗口不支持拖放.您始终可以使用自己的消息循环创建自己的单独弹出窗口,以便用户可以将项目拖到上面.

AFAIK, a console window does not support drag&drop by default. You can always create your own separate popup window with its own message loop so the user has something to drag items onto.

要在控制台窗口本身上使用拖放,请尝试使用

To use drag&drop on the console window itself, try using GetConsoleWindow() to get the console HWND, then either:

  1. 使用 SetWindowSubClass() ,然后使用

  1. subclass the HWND using SetWindowLong/Ptr() or SetWindowSubClass(), then register the HWND using DragAcceptFiles() to start receiving WM_DROPFILES messages. Be sure to call DragAcceptFiles() again to stop receiving the messages and then unhook your subclass before exiting the app.

实现 IDropTarget 接口,然后使用 RevokeDragDrop() 退出应用程序.

implement the IDropTarget interface and then register the HWND using RegisterDragDrop() to start receiving notifications. Be sure to call RevokeDragDrop() before exiting the app.

WM_DROPFILES 易于编码,但是 IDropTarget 更加灵活,因为它可以处理虚拟项目和物理文件.

WM_DROPFILES is easier to code for, but IDropTarget is more flexible as it handles virtual items as well as physical files.