Solved

MSHTML GetDropTarget and RegisterDragDrop

Posted on 2006-07-13
3
976 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

697 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