Solved

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

Posted on 2001-08-18
3
186 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
ID: 6403683
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
ID: 9521264
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
ID: 9533906
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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