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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: July 22, 2014 In this WhatWorks analysis, John Pescatore examines a use case where end users had local administrative rights on their PCs and it had gotten out of hand for this Fortune 500 Energy and Utilities company. The compelling event that prompted the company to reexamine this situation was the migration to Windows 7. In Windows XP, a custom tool that allowed users one of three levels of administrative rights to their workstations would need to be replaced during the Windows …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds