Implementing the "View Source" option in Internet Explorer

.

This is the code for implementing the "View Source" option in Internet Explorer

void CMyBrowser::OnViewSource() 
{
	CWnd* pWnd = NULL; 

	CWnd* pwndShell = m_WebBrowser2.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 = MAKELONG(IDM_VIEWSOURCE, 1);  //convert to unsigned 32 bit value and pass it to WPARAM
		pWnd->SendMessage(WM_COMMAND, wParam, (LPARAM)pWndHTML->m_hWnd); //cool send a message to retreive the source.
	} 	
}

Updated on May 23 1998



Comments

  • Under CHtmlView,which window is pWndHTML?

    Posted by Legacy on 10/10/2001 12:00am

    Originally posted by: aaa

    Under CHtmlView,which window is pWndHTML?

    Reply
  • where you get the pointer - pWndHTML from?

    Posted by Legacy on 08/23/2000 12:00am

    Originally posted by: Ron bar yosef

    Hello my name is Ron , i'm developer in c++ .

    i have a question about WebBrowser control

    are you know how to read the control WebBrowser Page content after you make
    a navigation to a specified URL .

    The problem:

    i want to navigate to yahoo finance and make a quote of a stock value .

    // after navigate to URL with the WebBrowser control and ask for microsoft (MSFT ) stock value ,
    for example: http://quote.yahoo.com/q?s=MSFT&d=1y

    pWebBrowser ->Navigate( " http://quote.yahoo.com/q?s=MSFT&d=1y";)

    // now i want to read the stock LAST TRAD value .

    // to do this i need to read the HTML content of the WebBrowser control ,
    // it's the same if you do "View Source" in Internet Explorer , then you can see the LAST TRAD value in the
    // content of the HTML page .

    so if you have any idea how to read the content of an HTML page after navigate to this page , ? please help me !


    thanks is advance !

    Ron bar yosef .


    Reply
  • View Source

    Posted by Legacy on 07/28/2000 12:00am

    Originally posted by: Jade

    Is there a way to disable the menu that appears when you right-click the mouse button on a webpage?

    Thanks,
    Jade

    Reply
  • Where'd you get the reference to IDM_VIEWSOURCE

    Posted by Legacy on 09/17/1999 12:00am

    Originally posted by: Mark Johnson

    How did you get the value for IDM_VIEWSOURCE, what header is it located in or did you just know what it was?

    Could this technique be used to invoke any context menu item?

    Reply
  • Another way...

    Posted by Legacy on 04/29/1999 12:00am

    Originally posted by: LJP

    Probably slower, since it downloads the file...
    
    

    void CWebBrowseView::OnViewSource()
    {
    HANDLE heMail;
    DWORD dwWritten;

    CString url = GetLocationURL();
    HINTERNET hSession;
    hSession = InternetOpen("Name of your browser", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (hSession)
    {
    HINTERNET hService;
    hService = InternetOpenUrl(hSession, url, NULL,
    0, 0, 0);
    if (hService)
    {
    DWORD dwBytesAvailable, dwBytesRead;
    InternetQueryDataAvailable(hService, &dwBytesAvailable, 0, 0);
    char *lpBuffer = (char*)malloc(dwBytesAvailable+1);
    InternetReadFile(hService, lpBuffer, dwBytesAvailable, &dwBytesRead);
    lpBuffer[dwBytesRead]=NULL;
    CString name = lpBuffer;
    try
    {
    heMail = CreateFile ("C:\\windows\\temp\\tmp.txt",GENERIC_WRITE,
    FILE_SHARE_READ,NULL,
    CREATE_NEW,
    FILE_ATTRIBUTE_NORMAL,
    NULL);

    WriteFile (heMail,name,strlen(name),&dwWritten, NULL);
    CloseHandle(heMail);
    }
    catch(...)
    {
    }


    ShellExecute(m_hWnd,
    "open",
    "C:\\windows\\temp\\tmp.txt",
    NULL,
    NULL,
    SW_SHOWNORMAL);

    // AfxMessageBox(lpBuffer);
    free(lpBuffer);
    }
    }
    InternetCloseHandle(hSession);

    }

    Reply
  • Re:Code for "View Source" option in Internet Explorer

    Posted by Legacy on 11/10/1998 12:00am

    Originally posted by: Semaru

    Very nice.
    Can you specify what is GW_CHILD and where you define it.

    Semaru
    A student learning MFC

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds