views:

307

answers:

1

I am trying to use this function from a COM API which enables the window to receive drops (as in drag & dop) from another application.

It is pretty straightforward in Windows Forms and works:

public void EnableDropSupport(System.Windows.Forms.Form form)
{
   IntPtr hwnd = form.Handle;
   _comAPI.RegisterDropWindow((int)hwnd);
}

But I have a WPF window where it does not work and I don't understand why. I have tried the following:

public void EnableDropSupport(System.Windows.Window window)
{
   window.AllowDrop = true;
   WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);
   IntPtr hwnd = windowInteropHelper.Handle;
   _comAPI.RegisterDropWindow((int)hwnd);
}

The last two lines are basically identical but it will just not work in WPF. While

window.AllowDrop = true;

will make it appear as if it will accept the drop, the drop event of that COM API is not raised.

Am I missing something or can someone help?

A: 

This is Pavel Minaev's answer (which he posted as a comment to the question) which was correct:

You're not missing anything on WPF side of things. Most likely the problem is with RegisterDropWindow.

Hermann