Click here to Skip to main content
15,892,643 members
Articles / Programming Languages / C#

Class for Adding Buttons, Menu Items and Explorer Bars to Internet Explorer

Rate me:
Please Sign up or sign in to vote.
4.51/5 (15 votes)
19 Feb 2007CPOL4 min read 80.6K   1.2K   71  
A simple class that edits the registry to set up toolbar buttons, menu items and explorer bars for Internet Explorer
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CorKat.RegistrySettings;
using Microsoft.Win32;


public partial class _Default : System.Web.UI.Page
{
    InternetExplorerExtender iee = new InternetExplorerExtender();
    int currentStep;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initialise();
        }
        else
        {
            currentStep = int.Parse(hiddenStep.Value);
        }
    }
    private void initialise()
    {
        currentStep = 1;
    }
    private void Next()
    {
        currentStep += 1;
        if (currentStep >= 2)
        {
            //hit the last step so set up the panels depending on what is selected
            DisplayDetailsOptions();
            // no more steps so disable the next button and enable the finish
            cmdNext.Enabled = false;
            cmdFinish.Enabled = CheckValues();
        }
        cmdPrev.Enabled = true;
        MultiView1.ActiveViewIndex = currentStep;
    }
    private bool CheckValues()
    {
        //todo: add catch for when a value isnt entered.
        return true;
    }
    private void DisplayDetailsOptions()
    {
        //hide all panels
        pnlButton.Visible = false;
        pnlApplication.Visible = false;
        pnlTools.Visible = false;
        pnlExplorerBar.Visible = false;

        if (cboCreationType.Items[0].Selected) //button
        {
            pnlButton.Visible = true;
            pnlApplication.Visible = true;
        }
        if (cboCreationType.Items[1].Selected) //menu
        {
            pnlMenu.Visible = true;
            pnlApplication.Visible = true;
            pnlTools.Visible = true;
        }
        if (cboCreationType.Items[2].Selected) // explorer bar
        {
            if (cboCreationType.Items[1].Selected) //menu
                pnlApplication.Visible = true;
            else
                pnlApplication.Visible = false;
            pnlMenu.Visible = true;
            pnlExplorerBar.Visible = true;
        }
    }
    private void Prev()
    {
        currentStep -= 1;
        if (currentStep <= 0)
        {
            cmdPrev.Enabled = false;
        }
        cmdNext.Enabled = true;
        MultiView1.ActiveViewIndex = currentStep;
    }
    protected void cmdPrev_Click(object sender, EventArgs e)
    {
        int intTemp = currentStep - 1;
        hiddenStep.Value = intTemp.ToString();
        Prev();
    }
    protected void cmdNext_Click(object sender, EventArgs e)
    {
        int intTemp = currentStep + 1;
        hiddenStep.Value = intTemp.ToString();
        Next();
    }
    protected void cmdFinish_Click(object sender, EventArgs e)
    {
        //set class properties
        if (cboCreationType.Items[2].Selected) // explorer bar
        {
            iee.MenuText = txtMenuText.Text;
            if (txtDll.PostedFile.FileName != "")
                iee.Dll = txtDll.PostedFile.FileName;
            if (txtURL.Text != "")
                iee.URL = txtURL.Text;
            iee.CreateNewExplorerBar();
        }

        if (cboCreationType.Items[0].Selected) //button
        {
            // set registry paths
            if (cboCreationType.Items[2].Selected) // explorer bar //button for an explorer bar
                iee.TypeOfDetail = IEEenums.DetailType.explorerbar;
            else
            {
                iee.TypeOfDetail = IEEenums.DetailType.executable;
                iee.ApplicationPath = txtApplication.PostedFile.FileName;
            }
            //set the registry paths
            if (optLocalMachine.Checked)
                iee.BaseRegistryKey = Registry.LocalMachine;
            else
                iee.BaseRegistryKey = Registry.CurrentUser;

            iee.ButtonText = txtButtonText.Text;
            iee.HotIcon = txtHotIcon.PostedFile.FileName;
            iee.Icon = txtIcon.PostedFile.FileName;
            // call the registry creation function for a button
            iee.CreateRegistryEntry_Button();
        }
        if (cboCreationType.Items[1].Selected) //menu
        {
            iee.TypeOfDetail = IEEenums.DetailType.executable;
            //set the registry paths
            if (optLocalMachine.Checked)
                iee.BaseRegistryKey = Registry.LocalMachine;
            else
                iee.BaseRegistryKey = Registry.CurrentUser;
            if (optHelp.Checked)
                iee.MenuItem = IEEenums.MenuItem.help;
            else
            {
                // don't need to set to tools as this is the default
            }
                iee.MenuText = txtMenuText.Text;
            iee.ApplicationPath = txtApplication.PostedFile.FileName;
            // call the registry creation function for a menu item
            iee.CreateRegistryEntry_MenuItem();
        }


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions