CHtmlView:如何获取点击数据?
我有一个使用 CHtmlView
的 MFC 应用程序。它显示一些临时 html 文件中的 html 格式的文本。是否可以处理鼠标单击段落以将一些数据发送到程序?我知道javascript可以用来处理点击,但是如何将数据从javascript函数传递到应用程序? 谢谢。
I have an MFC application that uses CHtmlView
. It displays some text in html format from some temp html file. Is it possible to handle mouse click on a paragraph to send some data to the program? I understand that javascript can be used to handle click, but how to pass the data from javascript function to the application??
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以从 HTML 页面的 Javascript 中干净地调用包含的应用程序。在 Javascript 级别,执行 CHtmlView 实际工作的 MSHTML 接口提供了一个“外部”对象,该对象充当返回调用应用程序的方式。
假设我们要添加一个可以从 Javascript 调用的方法“someCall()”,并且该方法采用字符串作为参数。在 JavaScript 中,我们会使用类似的方式来调用它。
在 MFC 应用程序中,我们需要编写一个 CCmdTarget 派生对象来充当“外部”对象的实现(作为基于调度的 COM 对象),例如:
要绑定“的此实现” external”与 HTML 视图,在从 CHtmlView 派生的类中,您需要重写 OnGetExternal() 并将其指向至少与 CHtmlView 一样长的 TestExternal 实例:
请注意,我实际上并没有对此进行了测试,但它似乎是凭记忆而来的......
It is possible to cleanly call the containing application from within the Javascript of the HTML page. At the Javascript level the MSHTML interface that is doing the actual work of the CHtmlView provides an "external" object that acts as a way back to the calling application.
Suppose we want to add a method "someCall()" that can be called from Javascript, and that the method takes a string as an argument. In JavaScript we would call it with something like
In the MFC application, we need to write a CCmdTarget derived object to act as the implementation of the "external" object as a dispatch-based COM object, something like:
To tie this implementation of "external" with the HTML view, in a class derived from CHtmlView you need to over-ride OnGetExternal() and to point it to an instance of TestExternal that lives at least as long as the CHtmlView:
Note that I haven't actually tested this, but it seems about right from memory ...