Solved

MSHTML GetDropTarget and RegisterDragDrop

Posted on 2006-07-13
3
960 Views
Last Modified: 2008-01-09
Hello.

I am deriving a window from CAxWindow and setting up an MSHTML control.

    CWindowImpl<CMyWindow,CAxWindow,CWinTraits<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
0
Comment
Question by:jandrieu
  • 2
3 Comments
 

Author Comment

by:jandrieu
Comment Utility
A bit more information. I also tried the HWND that returns from the Create call to my window in the RegisterDragDrop. That didn't work either.

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,_T("Internet Explorer_Server"),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
0
 

Author Comment

by:jandrieu
Comment Utility
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(hwndCAxWindow,NULL,_T("Shell Embedding"),NULL);
HWND hwndDocView = ::FindWindowEx(hwndShell,NULL,_T("Shell DocObject View"),NULL);
HWND hwndIEServer = ::FindWindowEx(hwndDocView,NULL,_T("Internet Explorer_Server"),NULL);

Second, revoke the MSHTML handler and register our own
hr=RevokeDragDrop(hwndIEServer);
hr=RegisterDragDrop(hwndIEServer, 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
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
Comment Utility
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now