启用从资源管理器到以管理员身份运行应用程序的拖放
我构建了一个 winforms 应用程序,并实现了拖放功能。此功能在 WinXP 或 Win7 中通过以管理员身份运行应用程序运行良好。
当尝试从 Win7 中的非管理应用程序拖动到我的程序时,问题就出现了,它不起作用。
我理解这一点是因为操作系统过滤了消息。我在这里找到了一个解决方案: http ://blog.helgeklein.com/2010/03/how-to-enable-drag-and-drop-for.html但它似乎不起作用。
这是解决方法代码:
[DllImport("user32.dll", SetLastError = true)]
static extern bool ChangeWindowMessageFilter(uint message, uint dwFlag);
private const uint WM_DROPFILES = 0x233;
private const uint WM_COPYDATA = 0x004A;
private const uint WM_COPYGLOBALDATA = 0x0049;
private const uint MSGFLT_ADD = 1;
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
如何使其工作?
I built a winforms application, and implemented drag&drop functionality. this functionality works great in WinXP or in Win7 from Run-As-Administrator applications.
The problems become when tring to drag from non-admin application in Win7 to my program, it just not working.
I understand this because the OS filtering the messages. I found a solution for that here: http://blog.helgeklein.com/2010/03/how-to-enable-drag-and-drop-for.html but it does not seems to work.
here is the workaround code:
[DllImport("user32.dll", SetLastError = true)]
static extern bool ChangeWindowMessageFilter(uint message, uint dwFlag);
private const uint WM_DROPFILES = 0x233;
private const uint WM_COPYDATA = 0x004A;
private const uint WM_COPYGLOBALDATA = 0x0049;
private const uint MSGFLT_ADD = 1;
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
How to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您正在与 UIPI 作斗争,UIPI 是 UAC 的一个方面,可防止未提升的程序劫持提升的程序的资源。是的,ChangeWindowMessageFilter() 允许您绕过 Windows 消息的此限制。
但是,OLE 拖放不使用 Windows 消息。它使用回调,请查看 RegisterDragDrop() 的文档以了解详细信息。这个 microsoftie 博客文章告诉您,您完蛋了,尽管它为 CWMF 打开了大门。然而,我完全不清楚如何获取 WM_DROPFILES 消息。在示例 Windows 窗体应用程序中使用 DragAcceptFiles() 没有明显的效果。
Yes, you're battling UIPI, an aspect of UAC that prevents unelevated programs from hijacking the resources of an elevated one. And yes, ChangeWindowMessageFilter() allows you to bypass this restriction for Windows messages.
However, OLE drag and drop doesn't use Windows messages. It uses callbacks, review the docs for RegisterDragDrop() for details. This microsoftie blog post tells you that you're screwed although it opens the door for CWMF. How to get a WM_DROPFILES message is however completely unclear to me. Using DragAcceptFiles() in a sample Windows Forms app had no discernible effect.