HOWTO: Using Forward & Back Buttons for Web Browser Control

Last reviewed: October 31, 1997
Article ID: Q163282
The information in this article applies to:
  • Microsoft ActiveX SDK, version 1.0

SUMMARY

When hosting the Web Browser 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 Web Browser 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.

Sample Code

   #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

Keywords          : AXSDKWebBrowser kbusage
Technology        : kbDSupport
Version           : 1.0
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 31, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.