VC + + Get current use of IE URL path and automatically print out the corresponding URL

Source: Internet
Author: User
Tags assert continue

This is about getting the URL address (VC + +) that is opened when IE, and automatically printing out the corresponding URL source code content:

Put this in your header file stdafx.h #import <mshtml.tlb> #import <shdocvw.dll> void CGETIESRCDLG::GETRUNNINGIESR  
C () {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 S  
Phtmldocument (SPDISP);  
Mshtml::ihtmlelementptr sphtmlelement;  
if (sphtmldocument==null) continue;  
Sphtmldocument->get_body (&sphtmlelement);  
if (sphtmldocument==null) continue;  
_bstr_t str;  
Str=spbrowser->getlocationurl ();//url of IE window (); AfXmessagebox (str);  
mshtml::ihtmldocument3* pHTMLDoc3;  
HRESULT hr = Sphtmldocument->queryinterface (__uuidof (Mshtml::ihtmldocument3), (lpvoid*) &phtmldoc3);  
ASSERT (SUCCEEDED (HR));  
mshtml::ihtmlelement* Pdocelem;  
hr = Phtmldoc3->get_documentelement (&pdocelem);  
Phtmldoc3->release ();  
ASSERT (SUCCEEDED (HR));  
BSTR bstrhtml;  
Pdocelem->get_outerhtml (&bstrhtml);  
Pdocelem->release ();  
AfxMessageBox (CString (bstrhtml));  
SysFreeString (bstrhtml);  
} break;  
}} else {AfxMessageBox ("Shell Windows interface is not avilable");  
} couninitialize (); }

Description: Simply traverse all the nodes of the entire Web page, find the first page in the container (the first page of multiple IE pages), and then traverse to remove all child nodes and print. We can test it, because sometimes the Web page of the General Assembly of suspended animation phenomenon, this code this studio test, you can use, but the use of IE7,IE8 so many tabs page of the browser to find the contents of each tab may also need to change, interested friends to try it yourself!

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/vc/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.