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: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds