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.
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();
}
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);
}
}
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]
The magic is pulled by the StatusTextChangeEvent. See
OnStatusTextChangeExplorer1 in jc_browser for more detail.
| Home|Services|What's New|Products|Sample codes |
| Copyright© 1998-1999 by JCSoft. All rights reserved. |
| consult@jcsoft.com |