Show/Hide Toolbars

Therefore Programming Interface 3.0

The following example shows how to customize the ribbon. In the example we insert the entry "On the Web" into the Add-Ins Tab on the Ribbon. When the user clicks our new entry the internet explorer is started and opens the Canon web site.

 

Requirements and Assumptions:

bullet AddIn project configured and registered as described in "AddIn Creation in C#" or "Add In Creation in VB .NET".

bullet Internet connection is necessary to actually open the Canon Europe web site.

Visual Basic

Imports System.Runtime.InteropServices

Imports System.IO

Imports Therefore.API

 

<Guid("14AE7005-8EE8-4e20-B7CB-774E923FAE6B"), ComVisible(True), ClassInterface(ClassInterfaceType.None)> _

Public Class MenuAddIn

    Implements ITheAddIn

 

    Public Sub GetHandledEvents(ByVal clientType As TheClientType, ByVal eventSet As TheEventSet) Implements ITheAddIn.GetHandledEvents

        ' Sign up for the InitMenu and MenuClick events

        eventSet.Add(TheEventType.InitMenu)

        eventSet.Add(TheEventType.MenuClick)

    End Sub

 

    Public Function HandleEvent(ByVal e As TheEvent) As Integer Implements ITheAddIn.HandleEvent

        Dim titles() As String = {"Canon &Europe""Canon &Deutschland""Canon &Italia""Canon &United Kingdom"}

        Dim urls() As String = {"http://www.canon-europe.com/""http://www.canon.de/""http://www.canon.it/""http://www.canon.co.uk/"}

 

        Const offset As Integer = 1

        Select Case (e.EventType)

            Case TheEventType.InitMenu

                ' Insert a new entry into the help menu

                e.Menu.Add("On the Web")

                Dim helpMenu As TheMenu = e.Menu.Find("On the Web")            

                Dim i As Integer = 0

                Do While (i < titles.Length)

                    helpMenu.Add(titles(i), (offset + i))

                    i = (i + 1)

                Loop

                Return 0

            Case TheEventType.MenuClick

                If ((e.Menu.ID >= offset) AndAlso (e.Menu.ID < (offset + urls.Length))) Then

                    ' Start Internet Explorer and open 'www.canon-europe.com'                        

                    Dim p As Process = New Process

                    p.StartInfo.FileName = "iexplore.exe"

                    p.StartInfo.Arguments = urls((e.Menu.ID - offset))

                    p.Start()

                End If

                Return 0

        End Select

        Return -1 ' This should never happen; returning -1 unregisters the incoming event type

    End Function

 

End Class

C#

using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Runtime.InteropServices;

using System.Text;

using Therefore.API;

 

namespace AddInSamples

{

    [Guid("2BB40866-CE28-48d5-97B4-AEB42CB217CC"), ComVisible(true), ClassInterface(ClassInterfaceType.None)]

    public class MenuAddIn : ITheAddIn

    {

        public void GetHandledEvents(TheClientType clientType, TheEventSet eventSet)

        {

            // Sign up for the InitMenu and MenuClick events

            eventSet.Add(TheEventType.InitMenu);

            eventSet.Add(TheEventType.MenuClick);

        }

 

        public int HandleEvent(TheEvent e)

        {

            string titles[] = {"Canon &Europe""Canon &Deutschland""Canon &Italia""Canon &United Kingdom"};

            string urls[] = {"http://www.canon-europe.com/""http://www.canon.de/""http://www.canon.it/""http://www.canon.co.uk/"};

            const int offset = 1;

            switch (e.EventType)

            {

                case TheEventType.InitMenu:

                    // Insert a new entry into the help menu

                    e.Menu.Add("On the Web, 50");

                    TheHelpMenu helpMenu = e.Menu.Find("On the Web");

                    for (int = 0; i < titles.length; i++)

                         helpMenu.Add(titles[i], offset + i);

                    return 0;

 

                case TheEventType.MenuClick:

                    if (e.MenuID >= offset && e.MenuID < offset + urls.length)

                    {

                        // Start Internet Explorer and open "www.canon-europe.com"                        

                        Process p = new Process();

                        p.StartInfo.FileName = "iexplore.exe";

                        p.StartInfo.Arguments = urls[e.MenuID - offset];

                        p.Start();

                    }

                    return 0;

            }

            return -1// This should never happen. Returning -1 unregisters the incoming event type

        }

    }

}

 

 

 

 

© 2024 Therefore Corporation, all rights reserved.