HOWTO: Using Forward & Back Buttons for WebBrowser Control

ID: Q163282


The information in this article applies to:


SUMMARY

When hosting the WebBrowser control, it may be desirable to implement Forward and Back buttons similar to those that Internet Explorer implements. One common problem that programmers face when doing this is how to know when to enable and disable the buttons.


MORE INFORMATION

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.


   #include <exdisp.h>

   // For an MFC application the CommandStateChange event could be handled
   // as follows:

   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 

Additional query words:


Keywords          : kbusage kbIE300 kbIE500 AXSDKWebBrowser 
Version           : WINDOWS:3.0,5.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 30, 1999