This section describes how to use the program method to obtainThe source code of HTML in the WebBrowser control, and the page content can be modified by modifying the source code content (Note: it is not to display a new page ).
First, add the WebBrowser control. There are two methods to obtain source code:
I. Methods1 (strictly speaking, this method is just to call WebBrowser's menu command "view source files", which is not what we want)
Key code:
# Include "mshtmcid. h"
Void CHtmlView: OnMethod1 ()
{
CWnd * pWnd = NULL;
CWnd * pWndShell = m_browser.GetWindow (GW_CHILD); // get the webbrowser window pointer
If (pWndShell)
{
PWnd = pWndShell-> GetWindow (GW_CHILD );// Get the child window pointer
}
If (pWnd! = NULL)
{
WPARAM wParam = MAKEWPARAM (IDM_VIEWSOURCE, 1 );// Convert to unsigned 32 bit value and pass it to wparam
PWnd-> SendMessage (WM_COMMAND, wParam, (LPARAM) this-> m_hWnd); // cool send a message to retreive the source.
}
}
Ii. Method2
The principle is to get the IPersistStreamInit interface pointer and then write the webpage to the IStream stream.
Key code:
# Include "mshtml. h"
// Fill in the source code of the web page in HtmlView in SourceView
Void CMainFrame: OnMethod2 ()
{
IHTMLDocument2 * pHTMLDocument = NULL;
IPersistStreamInit * pPSI = NULL;
IStream * pStream = NULL;
HGLOBALHHTMLText;
If(! (PHTMLDocument = (IHTMLDocument2 *) m_pHtmlView-> m_browser.GetDocument ()))
Return;
If(FAILED (pHTMLDocument-> QueryInterf