Solved

MSHTML GetDropTarget and RegisterDragDrop

Posted on 2006-07-13
3
965 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
ID: 17098444
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
ID: 17102986
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
ID: 17104608
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

786 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