在MFC里面在BUTTON按钮里,如何编写代码自动打开网页源代码?如题 谢谢了
1个回答
展开全部
void CGetIESrcDlg::NavigateToUrl() { // Import the following files in your stdafx.h // #import // Internet Explorer 5 // #import // Refer to "Connect to Internet Explorer Instances, From your own Process. " in www.codeguru.com SHDocVw::IShellWindowsPtr m_spSHWinds; CoInitialize(NULL); if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK) { IDispatchPtr spDisp; long nCount = m_spSHWinds->GetCount(); for (long i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if (spBrowser != NULL) { IDispatchPtr spDisp; if(spBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 ) { MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp); MSHTML::IHTMLElementPtr spHtmlElement; if(spHtmlDocument==NULL) continue; spHtmlDocument->get_body(&spHtmlElement); if(spHtmlDocument==NULL) continue; HRESULT hr; MSHTML::IHTMLElementCollection* pColl=NULL; hr=spHtmlDocument->get_all(&pColl); if(pColl!=NULL&&SUCCEEDED(hr)) { MSHTML::IHTMLElement* pElem=NULL; _variant_t index; index.vt=VT_I4; index.intVal=0; _variant_t name("Submit"); IDispatchPtr disp; disp=pColl->item(name,index); if(disp==NULL) hr=E_FAIL; else { hr=disp->QueryInterface(&pElem); } if (SUCCEEDED(hr)&& pElem != NULL) { // BSTR bstrhtml; } } } else { AfxMessageBox("Shell Windows interface is not avilable"); } CoUninitialize(); } http://qiupeng501.ys168.com/VC 编程中有个MyCalculator.rar就是了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询