No announcement yet.

Integrate a windows application into a DigitalMod Addin

  • Filter
  • Time
  • Show
Clear All
new posts

  • Integrate a windows application into a DigitalMod Addin

    The following tutorial discusses how to embed a typical window (HWND) into StreetDeck. It applies only to version of StreetDeck and later.

    This is NOT the preferred way of integrating with StreetDeck. Ideally you should create a module or overlay and place controls on it using the StreetDeck development enviornment. This will ensure your DigitalMod matches the look and feel of whatever the current skin is and can take advantage of all of StreetDeck's functionality including gesturing.

    In cases where certain functionality can not be duplicated in the StreetDeck development envoirnment or where you are integrating an exsiting application, it may be required to embed a window as is into StreetDeck. This is possible with the module method "HWND CreateHostWindow()." This method will create a window the size of the current module that will have portions cut out of it where overlays are visible and will show through the host window on top of it.

    Starting a New Addin Project in StreetDeck
    This project will build upon the basic tutorial of [WIKI]Building a .Net Addin for StreetDeck[/WIKI]. Please complete or download this project before continuing.

    Creating the Host Window
    After you have created a module in your addin, to embedd a window, you first need to create a host window in StreetDeck that will contain and be the parent window for the window or form in your addin.

    Add the following code after the CreateModule call in the OnConnection event in your addin.

    //Create a host window to put in general windows inside the program
    int hWndHost = (int) module.CreateHostWindow();

    Embedding your window
    Create a new windows form in your visual studio project by right clicking on your project and going to "Add | Add Windows Form..."

    Type a unique name for your new form, i.e. "EmbeddedForm" and click "Open"

    Double click on your form and edit its properties. Set ShowInTaskBar=False, ControlBox=False, FormBorderStyle=None

    Add a single button to the form and set the caption to "Go Back"

    Double click on the button to add a button1_Click to your form.

    Now go back to the class where you create the StreetDeck module and inside the class declaration right above the Constructor, add the following windows API declarations.

    [DllImport("user32")] public static extern int SetParent(int hWndChild, int hWndNewParent) ;
    [DllImport("user32")] public static extern bool EnableWindow(int hWnd, bool bEnable);

    Finally, below the CreateHostWindow call, add the following call to create and embed the form we just added to our project into our host window.

    //Create our embedded form and embed it inside of our host window
    EmbeddedForm embeddedForm = new EmbeddedForm();
    embeddedForm.TopLevel = false;
    SetParent((int) embeddedForm.Handle, hWndHost);

    Communicating between your form and StreetDeck
    The easiest way to allow your form to send functions to StreetDeck is simply to expose the app and module members of your main class as public. To do this, just add public to the StreetDeckApp and ScriptModule declarations in your Class1 class as follows:

    public StreetDeck.StreetDeckApp app;
    public StreetDeck.ScriptModule module;

    Now add a varible to store a pointer to your main class from your form as follows:

    public Class1 m_Parent;

    In your main class, before the embeddedForm.Show(); call add the following line to set the pointer back to main class from your form.

    embeddedForm.m_Parent = this;

    Finally, add the following line to the button1_Click function in your form that you created earlier to tell StreetDeck to go back to the previous module when it is clicked:


    Additional Notes
    Note, gesturing will generally not work within your module with a form embedded since all mouse inputs will go to your host window first. You can enable gesturing in StreetDeck by disabling your host window by adding the following call after you call CreateHostWindow(); This will prevent all mouse inputs from getting to your form so you will no longer be able to click buttons on it, however, you will receive events from StreetDeck in the module.OnMouse... events when your host window is disabled.

    EnableWindow(hWndHost, false);

    Example Project

    This project is a Visual Studio 2003 C# projects.

    To use this project, both the sdz project must be installed and the source code downloaded. To install the sdz file, simply double click on it, or drag and drop it onto a running instance of StreetDeck. For the c# project, you will have to change the output location and debugging options in the visual studio project properties for the dll after downloading to match the installed locations on your computer.

    This project uses the same sdz as Example1. You should just simply replace the StreetDeck.TestAddin.dll in the Addins sub folder with the one you compile for this project.

    [Example 1 SDZ] [Media Manager C# Project]