There are several sources explaining the UAC thing that prevents dragging and dropping files from the explorer onto your elevated application, but none of them covers a WPF example.
The problem is that my application NEEDS to be run with administrator rights, but at the same time it clashes with the problem above, so I'm in a deadlock.
For reference, there's this link showing how this would be solved within a MFC application (which is not the case), using the ChangeWindowMessageFilter
API.
Is it possible to achieve the same thing within a WPF application?
- UPDATE -
Things I have tried:
- Calling
ChangeWindowMessageFilter
after my main window's handle was created. The function returns true. - Calling
ChangeWindowMessageFilterEx
after my main window's handle was created, passing it as param. The function returns true and theCHANGEFILTERSTRUCT.ExtStatus
isMSGFLTINFO_NONE
. - Calling
DragAcceptFiles
after my main window's handle was created,DragQueryFile
andDragFinish
, however it looks like theDragAcceptFiles
call isn't allowing dragging events (WM_DROPFILES
) under WndProc, as follows:
.
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;
}
}