单击网页上显示的按钮时,如何为从CHtmlView派生的类添加例程以响应事件 [英] how to add routines for class derived from CHtmlView to response Event when you click a button showed on a webpage

查看:121
本文介绍了单击网页上显示的按钮时,如何为从CHtmlView派生的类添加例程以响应事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从CHtmlView派生的CSimpleHtmlView类,当我启动该应用程序时,我使它导航到一个带有按钮的本地html文件.我想处理button-click事件.

定义按钮的脚本是这样的:

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>



然后在CTestHtmlview的头文件中添加宏DECLARE_DISPATCH_MAP()和一个用于处理该事件的函数.例如. void OnBackward();

在实现文件中,我添加了其他一些宏,如下所示:



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!

推荐答案

限定符在这里-我没有使用CHtmlView的经验,我通过 SetExternalDispatch [ MFC损坏了 [
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


谢谢,barneyman!

我找到了解决方案. cusory步骤如下:
1.建立一个新的基于项目的对话框,选中自动化"选项.
2.添加一个从CHtmlView派生的新类,同时也检查自动化"选项.
3.为界面添加新方法(在检查自动化时向导将为您创建).例如:void myfunction1(void);
4.重写派生类的"OnGetExternal"虚拟函数,用以下代码填充函数主体
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;


然后,您可以在html中触发该函数,如下所示:
window.external.myfunction();

我的操作系统是win7 Ultimate,而IDE是VS2008!


then, you can fire the function in html, just like this:
window.external.myfunction();

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


这篇关于单击网页上显示的按钮时,如何为从CHtmlView派生的类添加例程以响应事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆