jandrieu
asked on
MSHTML GetDropTarget and RegisterDragDrop
Hello.
I am deriving a window from CAxWindow and setting up an MSHTML control.
CWindowImpl<CMyWindow,CAxW indow,CWin Traits<WS_ CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS> >
I also set up a DocHostUIHander with SetExternalUIHandler. That seems to work... as evidenced by the ShowContextMenu method getting called.
However, GetDropTarget is not getting called.
How do I set it up so that GetDropTarget is in fact called by MSHTML or, alternatively, that my own IDropTarget interface methods are called?
I have tried RegisterDropTarget, but can't seem to find the HWND to make it work. I've used m_spWebBrowser->get_HWND from the MSHTML control, but that always returns NULL. When I try to get the HWND from the host container using CMyWindow.operator HWND, I get NULL.
And if I register the drop to just the frame that is the parent of my container, then the Drop interfaces are called when I am over the frame, but not when over the MSHTML window. And GetDropTarget is never called.
My next attempt will be to scan the window hierarchy manually to find the HWND. But that's gotta be the hard way to do it.
Any help is appreciated.
-j
I am deriving a window from CAxWindow and setting up an MSHTML control.
CWindowImpl<CMyWindow,CAxW
I also set up a DocHostUIHander with SetExternalUIHandler. That seems to work... as evidenced by the ShowContextMenu method getting called.
However, GetDropTarget is not getting called.
How do I set it up so that GetDropTarget is in fact called by MSHTML or, alternatively, that my own IDropTarget interface methods are called?
I have tried RegisterDropTarget, but can't seem to find the HWND to make it work. I've used m_spWebBrowser->get_HWND from the MSHTML control, but that always returns NULL. When I try to get the HWND from the host container using CMyWindow.operator HWND, I get NULL.
And if I register the drop to just the frame that is the parent of my container, then the Drop interfaces are called when I am over the frame, but not when over the MSHTML window. And GetDropTarget is never called.
My next attempt will be to scan the window hierarchy manually to find the HWND. But that's gotta be the hard way to do it.
Any help is appreciated.
-j
ASKER
Ok. I got RegisterDragDrop to work. I'll share it here for any future programmers who might find themselves in similar situation.
I still do not have the DocHostUIHandler getting called for GetDropTarget... but oh well.
The trick was twofold.
First, find the MSHTML window from my CAxWindow by walking down the hierarchy:
HWND hwndShell = ::FindWindowEx(hwndCAxWind ow,NULL,_T ("Shell Embedding"),NULL);
HWND hwndDocView = ::FindWindowEx(hwndShell,N ULL,_T("Sh ell DocObject View"),NULL);
HWND hwndIEServer = ::FindWindowEx(hwndDocView ,NULL,_T(" Internet Explorer_Server"),NULL);
Second, revoke the MSHTML handler and register our own
hr=RevokeDragDrop(hwndIESe rver);
hr=RegisterDragDrop(hwndIE Server, pUIH);
pUIH points to my DocHostUIHandler object, but it could point to any object that correctly implements IDropTarget.
There you go. Now, the IDropTarget methods are correctly called so I can drag & drop into my MSHTML window.
-j
I still do not have the DocHostUIHandler getting called for GetDropTarget... but oh well.
The trick was twofold.
First, find the MSHTML window from my CAxWindow by walking down the hierarchy:
HWND hwndShell = ::FindWindowEx(hwndCAxWind
HWND hwndDocView = ::FindWindowEx(hwndShell,N
HWND hwndIEServer = ::FindWindowEx(hwndDocView
Second, revoke the MSHTML handler and register our own
hr=RevokeDragDrop(hwndIESe
hr=RegisterDragDrop(hwndIE
pUIH points to my DocHostUIHandler object, but it could point to any object that correctly implements IDropTarget.
There you go. Now, the IDropTarget methods are correctly called so I can drag & drop into my MSHTML window.
-j
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Apparently the MSHTML drop target handler is working just fine. If I have a droppable target in the HTML (say a contentEditable SPAN), the interface works as expected, completely bypassing my DocHostUIHandler functions.
I can however get ondragenter called as an element method if I attach it in the HTML:
<div id="content" contentEditable="false" ondragenter="alert('hello'
Sure enough, the MSHTML host calls ondragenter... but it does NOT call my GetDropTarget or the IDropTarget set up with RegisterDragDrop.
Btw, scanning the window hierarchy didn't seem to help. FindWindowEx didn't seem to find the window, and when I set the HWND using the handle ID from SPY++, it still didn't work.
HWND hwndContainer = ::FindWindowEx(webWND,NULL
After a bit of rest, I'll try passing the drop events through from Javascript to C++ tomorrow. Talk about the long way around...
-j