Announcement

Collapse
No announcement yet.

Building the Addin in Visual Studio

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Building the Addin in Visual Studio

    Start up Visual Studio 2005.

    Create a new C# project by going to File | New | Project.

    Choose Class Library from the list of C# projects.

    Type a unique name for the project such as "StreetDeckTestAddin" and click 'Ok'

    Add the following line to the top of the class file to include the COM interop services.

    using System.Runtime.InteropServices;

    Add a reference to the StreetDeck COM server by right clicking on the references folder in the solution explorer for your Addin project and choosing Add Reference then choose the Browse tab.

    Select the StreetDeck.exe file usually located in C:\program files\StreetDeck and click OK

    In the solution explorer, expand the properties folder and double click on AssemblyInfo.cs. Find the line where it says [assembly: ComVisible(false)] and change false to true so that it can register itself as a COM object.

    In the solution explorer, double click on Class1.cs and add the following lines within the name space brackets.

    [
    GuidAttribute(""),
    ProgId(""),
    ComVisible(true)
    ]

    Run the GuidGen tools by going to Tools | Create GUID. Generate a new Registry Format GUID and copy it. Place the generated GUID in the GuidAttribute quotes and add a progid which should be the human readable addin name followed by a . and the class name. i.e. After the changes the lines should look similar, but not exactly like the following, your GUID MUST be unique for each addin you create. Using the GuidGen tool assures the GUID will always be unique.

    [
    GuidAttribute("69CECAE8-7125-4cf4-8026-AF40503CC406"),
    ProgId("StreetDeck.TestAddin"),
    ComVisible(true)
    ]

    For your addin to be loaded by StreetDeck, it must implement the StreetDeck.IDualStreetDeckAddin interface. To do this, change the automatically created Class1 interface to look as follows:
    public class Class1 : StreetDeck.IDualStreetDeckAddin

    Every addin should also implment the OnConnection and OnDisconnect events which are called when the addin is loaded and unloaded by StreetDeck they are the first and last events respectively. In the OnConnection event, you should create all Modules, Overlays, and Media Managers your addin will use and any other initialization your addin needs. NOTE: The methods to create these objects will unconditionally fail outside of the OnConnection event. You should cleanup everything allocated in the OnDisconnect event.

    The following code implements the OnConnection event. On the first line of the event, we save a pointer to the app object given to us in the OnConnection event to a class member. The next line creates a module where we can place other panels (controls). We then create a single button panel in the new module and set the caption to say "Show Overlay". Next we create an overlay panel that will be shown when the button is clicked and sign up for the OnExec module event to process the button click.

    StreetDeck.StreetDeckApp app;
    StreetDeck.ScriptModule module;
    StreetDeck.ScriptOverlay overlay;

    //This OnConnection event is where we create all of the modules and overlay streetdeck needs
    //This example creates one module and one overlay
    void StreetDeck.IDualStreetDeckAddin.OnConnection(objec t o, StreetDeck.enumAddinConnectMode e)
    {
    //Save a pointer to the StreetDeck App object for future reference
    app = (StreetDeck.StreetDeckApp)o;

    //Create a single module that will show and hide an overlay
    module = app.CreateModule("ModuleName");

    //Create a button on our module that will show and hide the overlay
    //We can create the button panel at the start of the client area by using the
    //app.GetSystemMetric call. The width and height are ignored for buttons which take
    //on the width and height of whatever the button class (skin image) is.
    StreetDeck.Panel btnShowOverlay = (StreetDeck.Panel) module.CreatePanel(StreetDeck.enumCreatePanelType. eCPTButton, "BUTTON.LISTITEM_HIGH",
    "ShowOverlay", // This is the function name that will be given back to us in any OnExec
    // call and for all intents and purposes is the name of this panel
    app.GetSystemMetric(StreetDeck.enumSystemMetrics.e SMGenericModuleClientX),
    app.GetSystemMetric(StreetDeck.enumSystemMetrics.e SMGenericModuleClientY),
    200, 200);
    btnShowOverlay.Caption = "Show Overlay";

    //Create an overlay that will contain the other controls. Overlays are global and will be shown
    //above every other module
    overlay = app.CreateOverlay("OverlayTest");

    //Register for the OnExec event where we will process the button click event
    module.OnExec += new StreetDeck.IModuleEvents_OnExecEventHandler(module _OnExec);
    }

    In the OnDisconnect event, we simply unregister for the events we registered for.
    void StreetDeck.IDualStreetDeckAddin.OnDisconnect()
    {
    //Unregister the events
    module.OnExec -= new StreetDeck.IModuleEvents_OnExecEventHandler(module _OnExec);
    }

    Finally, in the OnExec event, we process the button click event. Notice that we check that the Description parameter matches the function name we specified for the button exactly and we are looked for the select event which is sent when the button is pressed.

    //The OnExec event for the module is where events from controls on the module are processed.
    //Some of the events are also recieved by the controls themselves and can be processed in
    //either place. You should return true if you process them here.
    public bool module_OnExec(string Description, StreetDeck.enumExecMessage eEM, int wParam)
    {
    if (Description == "ShowOverlay")
    {
    if (eEM == StreetDeck.enumExecMessage.eEMSelect)
    {
    overlay.Visible = !overlay.Visible;
    overlay.MsgBox("Overlay Visibility Changed!", "Button Clicked");
    return true;
    }
    }

    return false;
    }

    Thats it! Your addin should now compile and be runable. Pressing the "Show Overlay" button may not appear to do anything since no controls have been created on the overlay, but it is hiding and showing the overlay. You should experiment with creating different controls on the Overlay to get a feel for building StreetDeck addins.
Working...
X