易截截图软件、单文件、免安装、纯绿色、仅160KB

JavaScript Calls from C++

最近要用到相关技术,先贴在这,有空再翻页。
本文转自:
http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4399
http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/JavaScript-Calls-from-C.htm
http://www.codeproject.com/KB/COM/jscalls.aspx

Introduction
Sometimes, when we are using the IE Browser Control inside of a C++ application, we need to access the HTML elements. We can do it by using standard COM objects such as IWebBrowser2 , IHTMLDocument2 , and so forth. By doing this, we easily can implement features such as click button, click anchor, get input string, get HTML text, and so on. Unfortunately, Microsoft did not provide similar objects for JavaScript. In any case, it is possible to make a control for the JavaScript object inside an HTML page by using a traditional COM approach. This article describes the class CWebPage that allows you to do it and a technique to call a JavaScript function from C++ code.
How to Do This
As the result of using the presented class, it will be easy to call any JavaScript function from C++ code. To implement this feature, we should get a pointer to the IHTMLDocument2 interface. If we are using the CHtmlView class from MFC, we can get one by using member function CHtmlView::GetHtmlDocument() . In the case of using the IWebBrowser or IWebBrowser2 components, the function get_Document will bring us the desired interface. Here is an example:
CComPtr<IDispatch> spDisp = CHtmlView::GetHtmlDocument();
m_webPage.SetDocument(spDisp);

The rest of the things will be done by the CWebPage class. Here is an example of a JavaScript call without parameters.
m_webPage.CallJScript("Welcome");
The example of the JavaScript call with two parameters will look like this:
m_webPage.CallJScript("Miltiply","2.34","3.32");
The Class Implementation
class CWebPage
{
public:
CWebPage();
virtual ~CWebPage();
bool SetDocument(IDispatch* pDisp);
LPDISPATCH GetHtmlDocument() const;
const CString GetLastErr


相关文档:

JavaScript脚本语言描述:document 文挡对象详解

注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写
   否则会提示你一个错误信息 "引用的元素为空或者不是对象"
---------------------------------------------------------------------
对象属性
document.title             ......

ATL与JavaScript交互

原帖地址:http://www.followman.com/bbs/Topic-B11-T262.aspx
JavaScript动态响应ATL事件
相关讨论:http://topic.csdn.net/t/20061012/21/5078729.html

点:脚本传过来的对象是IDispatch接口,应该用IDispatch::Invoke来调用。如果传过来的是个function,那么DISPID
为0,如果是个对象,那么要先用GetIDsOfNames得 ......

javascript技巧

1、字符串转换为数值
常规方法:
JScript code
var a = parseFloat("12");
var b = parseInt("34");
可以用
JScript code
var a = +("12");
var b = +("34");
2、多维数组
常规方法:
JScript code
var A = new Array(2);
A[0] = new Array(2);
A[1] = new Array(2);
A[0][0] = 1;
A[0][1] = 2;
A[1][0] = ......

C/C++单元测试理论精要(八)

第3章 怎样才能高效率测试
3.1 似是而非的高效率
 
    这一节澄清一些流行的误解或误导,一些看起来很不错的高效率,实际上是似是而非的。
全自动生成用例
    全自动生成用例是所有测试人员的期盼,好消息是,这是一种简单的技术,十年前就有了,坏消息是,这种技术作用很小。
......

函数的解析之C/C++

      函数是程序的执行模块,是整个项目的细胞,如何组织好每一个函数的结构,如何提高程序的可读性和运行效率,是程序员们不断品味的主体。有时函数的设计能直接体现出程序员对C/C++的理解和感悟。
      C/C++的函数类型不对外乎以下几种,有些描述可能不太贴切:
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号