I have had a project for quite a while using C# winforms. I implemented a drag-drop function before windows 7 was released. Worked like a charm. However, when using windows 7 it does not work. The event doesn't even get triggered.
我使用c# winforms已经有一段时间了。在windows 7发布之前,我实现了拖放功能。工作就像一个魅力。然而,在使用windows 7时,它不能工作。事件甚至没有被触发。
AllowDrop
is set to true. When subscribing to DragEnter
it does not get called in windows 7 (not sure about vista). But on XP it works all the way. The program is run with administritave priviliges.
AllowDrop设置为true。当订阅DragEnter时,它在windows 7中不会被调用(不知道vista如何)。但在XP上,它一直都是有效的。程序由管理员特权运行。
Is there any difference in the drag drop in windows 7 vs xp? Don't know if it's relevant, but I'm using x64
windows 7和xp的拖拽有什么区别吗?不知道是否相关,我用的是x64
6 个解决方案
#1
71
The source and target processes need to have compatible security levels\ privileges. For example, if your source is Explorer and it is running with user level privileges, but your target application is running with administrator (elevated) level permission, you will not be able to drag&drop as this is seen as a security issue as the target is running with a higher level of privileges.
源进程和目标进程需要具有兼容的安全级别特权。例如,如果您的来源是探险家和用户级权限运行,但你的目标应用程序使用管理员(高架)级别权限运行,你将无法进行拖拽,因为这被视为安全问题作为目标与更高层次的权限运行。
#2
17
It is called UIPI, User Interface Privilege Isolation. Designed to prevent input injection exploits from programs that run with restricted privileges. It can be disabled, you'll need to do this:
它被称为UIPI,用户界面特权隔离。设计的目的是防止输入注入利用受限制特权运行的程序。它可以被禁用,你需要这样做:
- Modify the manifest, set the uiAccess attribute for the
<requestedExecutionLevel>
element to true. -
修改清单,将
元素的uiAccess属性设置为true。 - Store your program's EXE in a subdirectory of c:\windows or c:\program files
- 将程序的EXE存储在c:\windows或c:\程序文件的子目录中
- Sign your EXE with a certificate from an valid code signing authority
- 使用来自有效代码签名机构的证书对您的EXE进行签名
Never actually tried this, ymmv.
从来没试过,ymmv。
#3
2
From your application, call ChangeWindowMessageFilter with the following values to allow dragging and dropping to/from your elevated application and non-elevated applications like Explorer:
在您的应用程序中,使用以下值调用ChangeWindowMessageFilter,以允许从提升的应用程序和非提升的应用程序(如Explorer)拖拽或删除:
ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter (WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter (0x0049, MSGFLT_ADD);
#4
1
A Minor addition to dmex's post. The following defines the variables and the constant.
dmex的一个小插曲。下面定义了变量和常数。
private const uint WM_DROPFILES = 0x233;
private const uint WM_COPYDATA = 0x004A;
private const uint WM_COPYGLOBALDATA = 0x0049;
private const uint MSGFLT_ADD = 1;
Also, you may want to consider using ChangeWindowMessageFilterEx
if you're application is on Windows 7. I also believe that OLE drag and drop may not use Windows messaging. So it wouldn't effect that at all.
另外,如果您的应用程序在Windows 7上,您可能需要考虑使用ChangeWindowMessageFilterEx。我也相信OLE拖放可能不会使用Windows消息传递。所以它根本不影响。
#5
1
It may be unrelated, but I was having whacky Drag-n-Drop issues with Windows 8. It would work for a while and then stop working. I couldn't drag-n-drop between Explorer, in an editor, etc. It turns out that when I interacted with a Hyper-V VM running windows 7, my drag-n-drop ability was altered (or perhaps it was the ctrl-alt-end keystroke to simulate crtl-alt-delete to Hyper-V). In any event, one the issue occurred, the following resolved it:
这可能是无关的,但我在Windows 8上遇到了奇怪的拖放问题。它会工作一段时间,然后停止工作。我不能在浏览器、编辑器等之间拖放。事实证明,当我与运行windows 7的Hyper-V VM进行交互时,我的拖放能力被改变了(或者可能是ctrl-alt-end键击将crtl-alt-delete模拟为Hyper-V)。无论如何,一旦问题发生,下列问题就解决了:
I found the resolution to my problem here: Fix Drag Drop Functionality Not Working In Windows 7 Vista XP
我在这里找到了解决问题的方法:修复拖放功能在windows7 Vista XP中不能使用
Basically the solution was:
基本的解决方案是:
Left-Click on a file in explorer, and while holding down the mouse button, press [Esc] then [Ctrl], then release the mouse button. I have to assume that this is resetting some accessibility setting or something.
在资源管理器中左键单击一个文件,按住鼠标按钮时,按[Esc]然后按[Ctrl],然后释放鼠标按钮。我必须假设这是在重置一些可访问性设置。
#6
0
I had same problem when debugging a desktop C# application from VS 2015 and Windows 7 x64 as S.O. It was due to the administrator permission applied over the shortcut of my VS IDE in the desktop (see screenshot). Unchecking this option Drag & Drop events raise properly.
我在调试一个从VS 2015和Windows 7 x64上的桌面c#应用程序时遇到了同样的问题,这是由于在我的桌面VS IDE的快捷方式上应用了管理员权限(见屏幕截图)。取消选中此选项,拖放事件会正常上升。
Thanks to TimLloyd for his help.
感谢TimLloyd的帮助。
#1
71
The source and target processes need to have compatible security levels\ privileges. For example, if your source is Explorer and it is running with user level privileges, but your target application is running with administrator (elevated) level permission, you will not be able to drag&drop as this is seen as a security issue as the target is running with a higher level of privileges.
源进程和目标进程需要具有兼容的安全级别特权。例如,如果您的来源是探险家和用户级权限运行,但你的目标应用程序使用管理员(高架)级别权限运行,你将无法进行拖拽,因为这被视为安全问题作为目标与更高层次的权限运行。
#2
17
It is called UIPI, User Interface Privilege Isolation. Designed to prevent input injection exploits from programs that run with restricted privileges. It can be disabled, you'll need to do this:
它被称为UIPI,用户界面特权隔离。设计的目的是防止输入注入利用受限制特权运行的程序。它可以被禁用,你需要这样做:
- Modify the manifest, set the uiAccess attribute for the
<requestedExecutionLevel>
element to true. -
修改清单,将
元素的uiAccess属性设置为true。 - Store your program's EXE in a subdirectory of c:\windows or c:\program files
- 将程序的EXE存储在c:\windows或c:\程序文件的子目录中
- Sign your EXE with a certificate from an valid code signing authority
- 使用来自有效代码签名机构的证书对您的EXE进行签名
Never actually tried this, ymmv.
从来没试过,ymmv。
#3
2
From your application, call ChangeWindowMessageFilter with the following values to allow dragging and dropping to/from your elevated application and non-elevated applications like Explorer:
在您的应用程序中,使用以下值调用ChangeWindowMessageFilter,以允许从提升的应用程序和非提升的应用程序(如Explorer)拖拽或删除:
ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter (WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter (0x0049, MSGFLT_ADD);
#4
1
A Minor addition to dmex's post. The following defines the variables and the constant.
dmex的一个小插曲。下面定义了变量和常数。
private const uint WM_DROPFILES = 0x233;
private const uint WM_COPYDATA = 0x004A;
private const uint WM_COPYGLOBALDATA = 0x0049;
private const uint MSGFLT_ADD = 1;
Also, you may want to consider using ChangeWindowMessageFilterEx
if you're application is on Windows 7. I also believe that OLE drag and drop may not use Windows messaging. So it wouldn't effect that at all.
另外,如果您的应用程序在Windows 7上,您可能需要考虑使用ChangeWindowMessageFilterEx。我也相信OLE拖放可能不会使用Windows消息传递。所以它根本不影响。
#5
1
It may be unrelated, but I was having whacky Drag-n-Drop issues with Windows 8. It would work for a while and then stop working. I couldn't drag-n-drop between Explorer, in an editor, etc. It turns out that when I interacted with a Hyper-V VM running windows 7, my drag-n-drop ability was altered (or perhaps it was the ctrl-alt-end keystroke to simulate crtl-alt-delete to Hyper-V). In any event, one the issue occurred, the following resolved it:
这可能是无关的,但我在Windows 8上遇到了奇怪的拖放问题。它会工作一段时间,然后停止工作。我不能在浏览器、编辑器等之间拖放。事实证明,当我与运行windows 7的Hyper-V VM进行交互时,我的拖放能力被改变了(或者可能是ctrl-alt-end键击将crtl-alt-delete模拟为Hyper-V)。无论如何,一旦问题发生,下列问题就解决了:
I found the resolution to my problem here: Fix Drag Drop Functionality Not Working In Windows 7 Vista XP
我在这里找到了解决问题的方法:修复拖放功能在windows7 Vista XP中不能使用
Basically the solution was:
基本的解决方案是:
Left-Click on a file in explorer, and while holding down the mouse button, press [Esc] then [Ctrl], then release the mouse button. I have to assume that this is resetting some accessibility setting or something.
在资源管理器中左键单击一个文件,按住鼠标按钮时,按[Esc]然后按[Ctrl],然后释放鼠标按钮。我必须假设这是在重置一些可访问性设置。
#6
0
I had same problem when debugging a desktop C# application from VS 2015 and Windows 7 x64 as S.O. It was due to the administrator permission applied over the shortcut of my VS IDE in the desktop (see screenshot). Unchecking this option Drag & Drop events raise properly.
我在调试一个从VS 2015和Windows 7 x64上的桌面c#应用程序时遇到了同样的问题,这是由于在我的桌面VS IDE的快捷方式上应用了管理员权限(见屏幕截图)。取消选中此选项,拖放事件会正常上升。
Thanks to TimLloyd for his help.
感谢TimLloyd的帮助。