Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MSHTML GetDropTarget and RegisterDragDrop

Posted on 2006-07-13
3
Medium Priority
?
1,014 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

618 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