Click here to Skip to main content
12,450,101 members (46,684 online)
Rate this:
 
Please Sign up or sign in to vote.
I have a Class CSimpleHtmlView derived from CHtmlView, when I launch the application, i make it navigate a local html file which has a button on it.I want to Deal with the button-click event.

the script that define the button is like this:
<div style="font-family:Tahoma;font-size:12px;float:left;"><input onclick="window.external.OnBackward();" type="button" id="backward"  value="backward" /></div>

then I add the macro DECLARE_DISPATCH_MAP() in the CTestHtmlview's header file and a function to deal with the event. eg. void OnBackward();

In the implementing file, I add some other Macro as below:
BEGIN_DISPATCH_MAP(CSimpleHtmlView, CHtmlView)
	DISP_FUNCTION(CSimpleHtmlView, "OnBackward",  OnBackward,  NULL, NULL)
END_DISPATCH_MAP()
and implement the function. the application can't stop at the breakpoint in that function when i debug the application; Is there anything else should be added in the code? what can i do then?
thank you!
Posted 28-Jun-12 17:52pm
wmoumou331
Updated 28-Jun-12 21:42pm
v6
Comments
barneyman 29-Jun-12 1:24am
   
is your OnBackward method being called?

I don't understand 'can't break into it'
wmoumou 29-Jun-12 3:41am
   
I mean that the application can't stop at the breakpoint in that function, In other words the function isn't called.
barneyman 29-Jun-12 3:55am
   
ok
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Qualifier here - I have no experience with CHtmlView, I use the browser through WTL[^] - in that architecture it's necessary to call SetExternalDispatch[^] to glue the browser events into the window

I found this thread that talks about MFC being broken[^] - it does point to an alternative
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

thank you, barneyman!

I have found a resolution. the cusory step is following:
1. establish a new project based dialog, checking the "automation" option.
2. add a new class derived from CHtmlView, checking the "automation" option too.
3. add a new method for the interface(the wizard will create for you when checking the automation). eg.void myfunction1(void);
4.override the "OnGetExternal" virtual function of your derived class, fill the function body with following code
*lppDispatch = GetIDispatch(TRUE);
    return S_OK;
then, you can fire the function in html, just like this:
window.external.myfunction();

my os is win7 ultimate, and the IDE is VS2008!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100