Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-08-18
3
Medium Priority
?
192 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
[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
3 Comments
 
LVL 7

Accepted Solution

by:
peterchen092700 earned 400 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

715 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