views:

55

answers:

1

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?

+4  A: 

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.

Hans Passant