Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
4.00/5 (1 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:
HTML
<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:
C++
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
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

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
 
Share this answer
 
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
C#
*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!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900