The WebBrowser control supports a CommandStateChange event, which is fired
whenever the Forward or Back buttons need to be enabled or disabled. The
CommandStateChange event is sent with two parameters: a constant indicating
the type of button (CSC_NAVIGATEFORWARD or CSC_NAVIGATEBACK), and a Boolean
flag indicating whether to enable or disable the button.
CSC_NAVIGATEFORWARD and CSC_NAVIGATEBACK are defined in Exdisp.h, which
comes with the Internet Client SDK.
// For an MFC application the CommandStateChange event could be handled
// as follows:
#include <exdisp.h>
void CBrowserDlg::OnCommandStateChangeExplorer1(long Command, BOOL Enable)
{
switch(Command)
{
case CSC_NAVIGATEFORWARD:
// m_ctlForward is a CButton type
m_ctlForward.EnableWindow(Enable);
break;
case CSC_NAVIGATEBACK:
m_ctlBack.EnableWindow(Enable);
break;
default:
break;
}
}
' A Visual Basic application can also implement this
' functionality in this manner:
Private Sub WebBrowser_CommandStateChange(ByVal Command As Long,ByVal Enable As Boolean)
Select Case Command
Case CSC_NAVIGATEBACK
Back.Enabled = Enable
Case CSC_NAVIGATEFORWARD
Forward.Enabled = Enable
End Select
End Sub