Link to home
Start Free TrialLog in
Avatar of catwiz
catwiz

asked on

events in an embedded webbrowser control

I have created a webbrowser control and added it to my MFC app. Everything works well; I can send Navigate2 commands and move to pages.
But I need to get the BeforeNavigate2 event. I added the code for the function but it never gets called. Do I need to add some kind of sink code?
I have an example of a dialog based app and it's easy to trap the event there.
I'm using Visual C++ 5.0

Actual code would be appreciated.

thanks
Catwiz
Avatar of catwiz
catwiz

ASKER

Edited text of question
You need to declare an event sink for your project.

The header file for the class which is the wrapper for the browser should have DECLARE_EVENTSINK_MAP()

and something like this should appear in the cpp file.

BEGIN_EVENTSINK_MAP(CWebBrowser, CView)
      ON_EVENT(CWebBrowser, AFX_IDW_PANE_FIRST, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
END_EVENTSINK_MAP()

This code was based on the CHtmlView class supplied with Microsoft's VC++ 6.0

Then you should be able to use events just like in any other MFC project.

The function called when a BeforeNavigate2 event happens is CWebBrowser::BeforeNavigate2.

I hope this helps.

Avatar of catwiz

ASKER

this makes no difference
Avatar of catwiz

ASKER

Adjusted points to 250
ASKER CERTIFIED SOLUTION
Avatar of cramer091498
cramer091498

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of catwiz

ASKER

Thats excellent. Thanks; you're great!
Thank you thank you thank you thank you thank you!