Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ VC Automation
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
Edited 28-Jun-12 21:42pm
v6
Comments
barneyman at 29-Jun-12 1:24am
   
is your OnBackward method being called?
 
I don't understand 'can't break into it'
wmoumou at 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 at 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
0 Sergey Alexandrovich Kryukov 853
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 166
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2014
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