JC_Browser ---JCSoft

JC_Browser sample application can be downloaded here. I am using long filename(how can you live without long filename? :-). You need Winzip 6.1 or later to upzip the package. I build it in Visual C++ 4.1 using IE3.0. There is no reason why you can't build it under Visual C++ 4.x or can't use IE3.01. JC_Browse is a dialog base application. To run it, type a URL in the address field and hit return. The HTML page will be displayed in the WebBrowser ActiveX. Please let me know if you have any problems. Also if you have any suggestions send me email at james@jcsoft.com

Following are the FAQs and the annotation of the sample source code.

  1. How to integrate WebBrowser ActiveX in Visual C++
  2. How to get events from WebBrowser ActiveX
  3. How to print the content of WebBrowser ActiveX
  4. How to Copy the content of WebBrowser to Clipboard
  5. How to disable the go back when there is no history
  6. How to show the hyperlink in the status bar when the mouse is over it
  1. How to integrate WebBrowser ActiveX in Visual C++

  2. This step is straight forward. In the developer studio select menu: Insert, Components. In the Component Gallery select the "OLE controls" tag. Double click on the "Microsoft Shell Explorer Control" and hit OK. This will add the proxy class for WebBrowser ActiveX to your project. It also add the "Microsoft Web Browser" to the Dialog Palette. Select the Microsoft Web Browser and put it in the dialog box you are creating.
    [top]
  3. How to get events from WebBrowser ActiveX

  4. Hit Ctrl_W to invoke Class wizard. In the class wizard select Message Maps. In the Class name select the CJCBrowseDlg. Click on the IDC_EXPLORER1. You will see all WebBrowser Events appears in the Messages list box. Select the event you want to handle and choose Add Function.
    [top]
  5. How to print the content of WebBrowser ActiveX

  6. In JC_Browser, click the Print button will print the HTML content inside the WebBrowser Object. Here is the code:
    void CJCbrowseDlg::OnBtPrint() 
    {
        LPDISPATCH lpDispatch = NULL;
        LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
        CWebBrowser* pWeb = (CWebBrowser*)GetDlgItem(IDC_EXPLORER1);
    
        lpDispatch = pWeb->GetDocument();
        ASSERT(lpDispatch);
    
        lpDispatch->QueryInterface(IID_IOleCommandTarget,
    	             (void**)&lpOleCommandTarget);
        ASSERT(lpOleCommandTarget);
    
        lpDispatch->Release();
    
        lpOleCommandTarget->
    	        Exec(NULL,OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL);
    
        lpOleCommandTarget->Release();
    }
    

    [top]

  7. How to Copy the content of WebBrowser ActiveX to Clipboard

  8. After loading a page in JC_Browser, select some HTML content in the JC_Browser then choose system menu(upper left icon) and click on Browser Copy. If you do a paste in notepad you can see that the content you selected in the browser is copied to the clipboard. Here is the code to do it:
    void CJCbrowseDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    	{
    		CAboutDlg dlgAbout;
    		dlgAbout.DoModal();
    	}
    	else if ((nID & 0xFFF0) == IDM_BROWSERCOPY)
    	{
    		LPDISPATCH lpDispatch = NULL;
    		LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
    		CWebBrowser* pWeb = (CWebBrowser*)GetDlgItem(IDC_EXPLORER1);
    
    		lpDispatch = pWeb->GetDocument();
    		ASSERT(lpDispatch);
    
    		lpDispatch->QueryInterface(IID_IOleCommandTarget,
    						(void**)&lpOleCommandTarget);
    		ASSERT(lpOleCommandTarget);
    
    		lpDispatch->Release();
    
    		lpOleCommandTarget->
    				Exec(NULL,OLECMDID_COPY,NULL,NULL,NULL);
    
    		lpOleCommandTarget->Release();
    	}
    	else
    	{
    		CDialog::OnSysCommand(nID, lParam);
    	}
    }
    

    [top]

  9. How to disable the go back when there is no history
  10. WebBrowse Object send CommandStateChange Event when the enabled state of a command changes. There are three commands defined: CSC_UPDATECOMMANDS, CSC_NAVIGATEFORWARD, CSC_NAVIGATEBACK. When there is no history to go back WebBrowser object will send CSC_NAVIAGEBACK EVENT with a False parameter. Following is the sample code:

    void CJCbrowseDlg::OnCommandStateChangeExplorer1(long Command, BOOL Enable) 
    {
    	switch(Command)
    	{
    	case CSC_NAVIGATEFORWARD:
    		{
    		CButton *pButton = (CButton*)g_pDlg->GetDlgItem(IDC_BT_FORWARD);
    		pButton->EnableWindow(Enable);
    		}
    		break;
    	case CSC_NAVIGATEBACK:
    		{
    		CButton *pButton = (CButton*)g_pDlg->GetDlgItem(IDC_BT_BACK);
    		pButton->EnableWindow(Enable);
    		}
    		break;
    	default:
    		break;
    	}
    }
    

    [top]

  11. How to show the hyperlink in the status bar when the mouse is over it
  12. The magic is pulled by the StatusTextChangeEvent. See OnStatusTextChangeExplorer1 in jc_browser for more detail.
    [top]


Home|Services|What's New|Products|Sample codes
Copyright© 1998-1999 by JCSoft. All rights reserved.
consult@jcsoft.com