windows 在winapi中拖放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/190596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:25:49  来源:igfitidea点击:

Drag and drop in winapi

cwindowswinapidrag-and-drop

提问by Peter Olsson

I have a pure Winapi application that needs a few new features. One of them would best be implemented as two lists where you can drag-and-drop (multiple) elements between the lists. The new feature can be limited to a single dialog.

我有一个需要一些新功能的纯 Winapi 应用程序。其中之一最好实现为两个列表,您可以在其中在列表之间拖放(多个)元素。新功能可以限制为单个对话框。

What would be the quickest way to implement this? A few ideas:

实现这一点的最快方法是什么?一些想法:

  • Pure Winapi (is it DetectDrag)
  • A separate MFC or .NET DLL that provides this one dialog
  • Embed the Microsoft WebBrowser Control and use JQuery
  • 纯 Winapi(是不是 DetectDrag)
  • 提供此对话框的单独 MFC 或 .NET DLL
  • 嵌入 Microsoft WebBrowser Control 并使用 JQuery

Any of these options that should be avoided?
Any better ideas?
What is quickest to implement?
Any pointers on how to get started?

这些选项中的任何一个都应该避免?
有什么更好的想法吗?
什么是最快的实施?
关于如何开始的任何指示?

回答by macbirdie

My advice would be that if the application is in pure winapi, keep it that way.

我的建议是,如果应用程序是纯 winapi,请保持这种方式。

Starting a .NET framework runtime just for one dialog with draggable items is as bad as hosting a WebBrowser control and using JQuery for that one functionality - it's at least thedailywtf.com-worthy if you ask me (but then again, you're not asking me ;) ).

只为一个带有可拖动项目的对话框启动 .NET 框架运行时与托管 WebBrowser 控件并使用 JQuery 来实现该功能一样糟糕 - 如果你问我,它至少是 thedailywtf.com 值得的(但话说回来,你不是问我 ;) )。

Otherwise you will put yourself (and potentially others) into some maintainability nightmare and the quickest way will become the most problematic one.

否则,您会将自己(以及可能的其他人)置于一些可维护性噩梦中,而最快的方法将成为最有问题的方法。

Edit:Maybe thosetwoarticles will help in implementing drag-drop - they're about row reordering in ListViews, but will probably help in getting the idea.

编辑:也许两篇文章将有助于实现拖放 - 它们是关于 ListViews 中的行重新排序,但可能有助于获得这个想法。

回答by Ben Straub

Raymond Chen wrote a series of blogposts on this topic not too long ago. Start here.

不久前,Raymond Chen 写了一系列关于这个主题的博文。从这里开始。

回答by Peter Olsson

A few notes after implementing this in Win32 api:

在 Win32 api 中实现后的一些注意事项:

Drag and drop is not supported by the ListBox control. It has to be a ListView control.

ListBox 控件不支持拖放。它必须是一个 ListView 控件。

This CodeProject articleis very good. (Thanks macbirdie)
The MSDN section of ListViewsis of course very useful.

这篇CodeProject 文章非常好。(感谢 macbirdie)ListViews
的 MSDN 部分当然非常有用。

回答by Peter Olsson

All the code is in MSDN in C and win32 api Just copy-paste.

所有代码都在C和win32 api的MSDN中,只需复制粘贴即可。

And see professional Win32 api ng news://194.177.96.26/comp.os.ms-windows.programmer.win32 where all this has been discussed for decades...

并查看专业的 Win32 api ng news://194.177.96.26/comp.os.ms-windows.programmer.win32,其中所有这些已经讨论了几十年......

回答by Phil Wright

Whichever method you are most familiar with is going to be the quickest.

无论您最熟悉哪种方法,都将是最快的。

Certainly it is very easy to do this in .NET Windows Forms. You can easily drag and drop items between ListBox entries by writing just a few lines of code. Look at somewhere like CodeProjectfor samples.

当然,在 .NET Windows 窗体中很容易做到这一点。只需编写几行代码,您就可以轻松地在 ListBox 条目之间拖放项目。在CodeProject 之类的地方查看示例。