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

  • 10 Rules that Make or Break Enterprise App Development Projects In today's app-driven world, application development is a top priority. Even so, 68% of enterprise application delivery projects fail. Designing and building applications that pay for themselves and adapt to future needs is incredibly difficult. Executing one successful project is lucky, but making it a repeatable process and strategic advantage? That's where the money is. With help from our most experienced project leads and software engineers, …

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming webcast to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds