有几个来源解释了防止将文件从资源管理器拖放到提升的应用程序的 UAC 事物,但它们都没有涵盖 WPF 示例。
问题是我的应用程序需要以管理员权限运行,但同时它与上述问题发生冲突,所以我陷入了僵局。
作为参考,有这个链接显示如何在 MFC 应用程序中解决这个问题(不是这种情况),使用ChangeWindowMessageFilterAPI。
是否有可能在 WPF 应用程序中实现相同的目标?
- 更新 -
我尝试过的事情:
ChangeWindowMessageFilter在我的主窗口句柄创建后调用。该函数返回真。ChangeWindowMessageFilterEx在创建主窗口句柄后调用,将其作为参数传递。该函数返回 true 并且CHANGEFILTERSTRUCT.ExtStatusisMSGFLTINFO_NONE。DragAcceptFiles在创建我的主窗口句柄之后调用DragQueryFile,DragFinish但是看起来DragAcceptFiles调用不允许WM_DROPFILES在 WndProc 下拖动事件(),如下所示:
.
public partial class MainWindow : Window
{
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
WinAPI.DragAcceptFiles(new WindowInteropHelper(this).Handle, true);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WinAPI.WM_DROPFILES)
{
// Not reaching here
}
return IntPtr.Zero;
}
}