Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

IDropTarget + elevated process. Msgs for ChangeWindowMessageFilter to make it work?

$
0
0
I'm using the following approach to register an individual control in my MFC/C++ application for a drag-and-drop operation:

Code:

//I have my own class derived from IDropTarget
class CDropTargetSpec :
    public IDropTarget
{
    //IUnknown implementation
    HRESULT __stdcall QueryInterface (REFIID iid, void** ppvObject);
    ULONG  __stdcall AddRef (void);
    ULONG  __stdcall Release (void);

    //IDropTarget implementation
    HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
    HRESULT __stdcall DragOver (DWORD grfKeyState, POINTL pt, DWORD * pdwEffect);
    HRESULT __stdcall DragLeave (void);
    HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);

    //...
};

Then to register it I do:

Code:

//Error checks are omitted for brevity
CDropTargetSpec *pDropTarget = new CDropTargetSpec();
CoLockObjectExternal(pDropTarget, TRUE, FALSE);
RegisterDragDrop(hDragRecepientWnd, pDropTarget));

The drag and drop itself is processed by the CDropTargetSpec class methods.

This approach works fine, except when my app runs elevated. In that case the registration methods succeed, but when I try to drag and drop files into my window, none of the methods from CDropTargetSpec class get called and the mouse shows "Not Available" cursor.

I know that Microsoft added that UIPI thing which prevents messages from lower processes to be dispatched into elevated processes. They also added the ChangeWindowMessageFilter API to bypass it, but I can't seem to figure out what messages I need to allow for my drag-and-drop to work.

I keep finding the following code sequence that I need to call from the WM_INITDIALOG method for my app:

Code:

ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);  //0x0049

but even though it works for a simple drag-and-drop into the app itself, my method above for the IDropTarget doesn't seem to work.

So any ideas what am I missing here?

Viewing all articles
Browse latest Browse all 3021