Solved

How do I trap HTML events from an embedded web control in edit mode?

Posted on 2001-08-18
3
183 Views
Last Modified: 2013-11-20
In my application I have an embedded web control and some buttons that allow the user to enter edit mode and change properties in the html code like font color, bold, italic, etc.
I want to trap the event of the user selecting a piece of text and set these buttons to their appropriate states like in an editor (ie. the "bold" button should be pressed/checked if the selection is bold).
I have already implemented the following relevant classes (aside from the obvious CWebbrowser class):

class CImpIDispatch : public IDispatch
class CCustomControlSite : public COleControlSite
class CCustomOccManager : public COccManager

I want to be able to capture events like
DISPID_HTMLDOCUMENTEVENTS2_ONSELECTIONCHANGE
when in edit mode.
How do I do that?

Thanks in advance.
0
Comment
Question by:DGeomel
3 Comments
 
LVL 7

Accepted Solution

by:
peterchen092700 earned 200 total points
Comment Utility
Hi!

It's much easier if the thingie is embedded in a dialog or form, but even if you use it as view, the following might help you generate the necessary code

(I suggest try this in a helper project first, for playing around, etc....)

Create a dialog resource, right-click, choose "Insert ActiveX control", choose "Microsoft Webbrowser"

in class wizard, member variables, add a member variable for the IDC_EXPLORER1.

You will be asked to import the Webbrowser defiunitions, agree. (Note: you can do this in another project any time using clazz wizard, "Add Class / From type library..")

now, in class view, right click on the dialog, choose "Add Windows Message Handler". Select the doialog resource, add a handler for some other event you might (or might not) be interested in.

Now we can examine the dlg, to see what we would need to take over:

member variable:
CWebBrowser2 m_browser;   // or whatever

// when you want to do this in a view, declare CWebBrowser2 as member of the view class, and call m_browser.Create to create it. See note below)


in .cpp file:
BEGIN_EVENTSINK_MAP(class, baseclass)
     ON_EVENT(CIeDlg, IDC_EXPLORER1, 250 /* BeforeNavigate2 */, OnBeforeNavigate2Explorer1, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
END_EVENTSINK_MAP()


you can now add additional handlers manually. First, check the parameter list of the event. Mostly, it's variants, bools, and a pointer to one of this (as return value)

- declare a message handler function (outside the //{AFX_...}); make sure you use the correct argument list

- add an entry to the event sink map

ON_EVENT( <class where the handler function is in>,
          <ID of the browser control>,
          <event dispatch id>,
          <handler function>,
          <parameter type list>)
note that the parameter type list is a sequence of VTS_.. (like VTS_VARIANT, VTS_BOOL, VTS_PBOOL) WITH NO SEPARATORS!

- add an implementation of the handler

--------------

Note on views:
Unhappily, MFC allows catching COM events only in the parent of the window hosting the actual Control. That's why you need to create the browser control as child of your view. I have some more info on this at
http://buerger.metropolis.de/bitbucket/howto/wndview.html

Good luck!
Peter

0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: peterchen

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
 

Author Comment

by:DGeomel
Comment Utility
This is about an older project and I apologize for letting it linger for
so long. Although I remember Peter's answer had not been very helpful, I have no choice but to award him the points now.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
List out all word 7 219
ffmpeg - "rtsp://...... Operation not permitted" 4 68
scoreUp challenge 14 47
Problem to event 3 48
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

9 Experts available now in Live!

Get 1:1 Help Now