Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Use Forward and Back Buttons for WebBrowser Control


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.

↑ Back to the top


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.
// 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
				

↑ Back to the top


Keywords: KB163282, kbusage, kbhowto, kbarchive, kbnosurvey

↑ Back to the top

Article Info
Article ID : 163282
Revision : 6
Created on : 6/22/2014
Published on : 6/22/2014
Exists online : False
Views : 259