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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds