VC 通过IHTMLINTEFACE 接口实现网页执行自定义js代码
2012-06-17 10:44
411 查看
VC 通过IHTMLINTEFACE 接口实现网页执行自定义js代码 IHTMLDocument2 *pDoc2 ...... IHTMLWindow2 *pWindow; HRESULT hr=pDoc2->get_parentWindow(&pWindow); VARIANT ret; ret.vt=VT_EMPTY; CComBSTR func="alert(document.cookie)"; CComBSTR lang="JAVAScript"; hr=pWindow->execScript(func,lang,&ret); //首先只要得到 ihtmldocument2 接口即可 BOOL CIEop::putValue(CString IDorName,CString put_value,DWORD ChoosePtr){ IHTMLElementCollection *pAllElement=NULL; if (m_pHTMLDocument2==NULL) { OutputDebugString(_T("LTDLL putValue Failed m_pHTMLDocument2==null")); // initcom(); return FALSE; } m_pHTMLDocument2->get_all(&pAllElement); if (pAllElement==NULL) { MessageBox(0,_T("putValue pAllElement is NULL "),_T("错误提示"),MB_OK); return FALSE; } CComPtr<IDispatch> pDispIE; HRESULT hr; switch (ChoosePtr) { case Choose_IHTMLInputTextElment:{ hr= pAllElement->item(CComVariant(IDorName.AllocSysString()),CComVariant((long)0),&pDispIE); if (FAILED(hr)) { MessageBox(0,_T("putValue pDispIE is NULL put_value="+put_value),_T("错误提示"),MB_OK); return FALSE; } CComQIPtr<IHTMLInputTextElement,&IID_IHTMLInputTextElement> pElement; pElement=pDispIE; put_value.ReleaseBuffer(); pElement->put_value(put_value.AllocSysString()); } break; case Choose_JavaScript:{ hr= pAllElement->item(CComVariant(IDorName.AllocSysString()),CComVariant((long)0),&pDispIE); if (FAILED(hr)) { MessageBox(0,_T("putValue pDispIE is NULL put_value="+put_value),_T("错误提示"),MB_OK); return FALSE; } IHTMLWindow2* pIHTMLWindow = NULL; m_pHTMLDocument2->get_parentWindow(&pIHTMLWindow); put_value.ReleaseBuffer(); VARIANT pvarRet; pIHTMLWindow->execScript(CComBSTR(put_value.AllocSysString()), CComBSTR("JavaScript"), &pvarRet); pIHTMLWindow->Release(); } break; case Choose_Click:{ hr= pAllElement->item(CComVariant(IDorName.AllocSysString()),CComVariant((long)0),&pDispIE); if (FAILED(hr)) { //MessageBox(0,_T("putValue pDispIE is NULL put_value="+put_value),_T("错误提示"),MB_OK); return FALSE; } CComQIPtr<IHTMLElement,&IID_IHTMLElement> pElement; if (pDispIE==NULL) { return FALSE; } pElement=pDispIE; pElement->click(); // VARIANT vOnclick; // // pElement->put_onclick(&vOnclick); } break; case Choose_IHTMLFormElement : { hr= pAllElement->item(CComVariant(IDorName.AllocSysString()),CComVariant((long)0),&pDispIE); if (FAILED(hr)) { MessageBox(0,_T("putValue pDispIE is NULL put_value="+put_value),_T("错误提示"),MB_OK); return FALSE; } CComQIPtr<IHTMLFormElement,&IID_IHTMLFormElement> pElement1; pElement1=pDispIE; // pElement1->put_target(CComBSTR("_blank")); pElement1->put_target(CComBSTR(_T("_self"))); pElement1->put_action(CComBSTR(_T("action.php"))); pElement1->submit(); } break; case CHoose_GetText: { hr= pAllElement->item(CComVariant(IDorName.AllocSysString()),CComVariant((long)0),&pDispIE); if (FAILED(hr)) { MessageBox(0,_T("putValue pDispIE is NULL put_value="+put_value),_T("错误提示"),MB_OK); return FALSE; } // CComQIPtr<IHTMLElement,&IID_IHTMLElement> pElement1; // pElement1=pDispIE; // pElement1->get_innerText(&m_strVerify); } break; } return TRUE; }
相关文章推荐
- 通过实现接口ListCellRenderer自定义JList的显示模式
- C#通过IConvertible接口来实现自定义类型转换和计算
- C# 自定义类型通过实现IFormattable接口,来输出指定的格式和语言文化的字符串(例:DateTime)
- PHP实现飞信接口来通过网页免费发短信
- 【干货】如何通过OPC自定义接口来实现客户端数据的读取?
- VC++通过动态生成并加载DLL,实现可执行文件的自删除
- php通过执行CutyCapt命令实现网页截图的方法
- 给记事本添加接口,并通过菜单来执行自定义的功能
- C# 通过IEnumberable接口和IEnumerator接口实现自定义集合类型foreach功能
- 通过自定义注解或拦截器实现APP调用后接口全局权限验证
- VC++通过动态生成并加载DLL,实现可执行文件的自删除
- 通过动态获取资源ID,执行接口回调-----来实现日夜模式切换
- iOS 通过添加线程依赖和信号量结合实现一个复杂界面请求多个接口时按指定顺序执行
- Windows 注册自定义的协议 实现通过网页调用本地程序的功能例如QQ等
- VC++通过动态生成并加载DLL,实现可执行文件的自删除
- 通过自定义的类来实现事件监听器接口的示例
- 通过Tag接口实现自定义标签
- 使用百度地图接口实现自定义网页地图开发实现
- 通过实现HandlerMethodArgumentResolver接口,给springMvc的Controller的方法注入自定义参数
- java中通过接口实现自定义事件,动态设定行为