devxlogo

Creating a Windows Mobile Wireless Remote PowerPoint Clicker

Creating a Windows Mobile Wireless Remote PowerPoint Clicker

f you’ve got a Windows Mobile device with Bluetooth connectivity, why not write your own PowerPoint clicker application so that you can use it in your next company presentation and impress your colleagues and boss? This is the project that I recently set to do when I wanted to buy a wireless remote clicker that I can use for my presentations. Rather spend the money on an additional gadget, I decided that it would be more fun to write my own application. This is what you will learn to do in this article.

There are two components that you will build:

  1. A desktop windows application that controls the PowerPoint slides
  2. A Windows Mobile application that sends commands to the desktop application
  3. Creating the PowerPoint Remote Controller
    First, let’s create the controller on the desktop so that it can launch a PowerPoint slide deck. Using Visual Studio 2005, create a new Windows application and name it RemoteController. Populate the default Form1 with the following controls (see Figure 1):

    1. Label
    2. Button
    3. GroupBox
    Figure 1. The Default Form1: Populated with the various controls.

    In order to interact with Microsoft Office XP applications through your .NET code, you need to download the Primary Interop Assemblies (PIAs).

    Once the PIA package is downloaded, expand them into a folder and add the following libraries (see also Figure 2):

    • office.dll
    • Microsoft.Office.Interop.PowerPoint.dll
    Figure 2. The PIA Package: Importing the relevant libraries to the project.

    Switch to the code-behind of Form1 and import the following namespace:

    Imports Microsoft.Office.Interop.PowerPoint

    Define the following enumerations:

    Public Enum Directions    PrevSlide    NextSlide    FirstSlide    LastSlideEnd Enum

    Declare the following member variables:

    Public Class Form1    Private PowerPTApp As New Application    Private PowerPTPres As Presentation    '---total no. of slides---    Private TotalSlides As Integer = 0    '---serial port for Bluetooth comms---    Private WithEvents serialPort As New IO.Ports.SerialPort

    In the Form1_Load event, code the following:

    Private Sub Form1_Load( _   ByVal sender As System.Object, _   ByVal e As System.EventArgs) _   Handles MyBase.Load        btnSelect.Enabled = False        GroupBox1.Enabled = False    End Sub

    Double-click the "Open Serial Port" button and use the following code to establish a serial connection (through Bluetooth) with the Windows Mobile device (see Listing 1).

    Author's Note: The COM18 is dependent on which COM port you have selected to use on your computer. Refer to the last section of this article to determine which COM port to use.

    Double-click the "Select PowerPoint file to load" button and use the following code to let users choose and load a PowerPoint slide deck (see Listing 2).

    Define the NavigateSlides() subroutine to programmatically manipulate the PowerPoint slides (see Listing 3).

    Define the ShowSlideNo() subroutine to display the current slide number (see Listing 4).

    You need to define a delegate to update the slide number because the ShowSlideNo() subroutine may be called by the DataReceived event (to be defined next) of the SerialPort object when incoming data is received. The delegate and the UpdateLabel() subroutine are defined as follows:

    '---delegate and subroutine to display slide no.---    Public Delegate Sub myDelegate(ByVal str As String)    Public Sub UpdateLabel(ByVal str As String)        lblSlideNo.Text = str    End Sub

    When the user clicks on one of the four navigational buttons, you need to navigate the slides accordingly. This is serviced by the Buttons_Click event, which is defined as follows:

        Private Sub Buttons_Click( _       ByVal sender As System.Object, _       ByVal e As System.EventArgs) Handles _       btnPrev.Click, btnNext.Click, btnLast.Click, btnFirst.Click        Select Case CType(sender, Button).Name            Case "btnPrev"                NavigateSlides(Directions.PrevSlide)            Case "btnNext"                NavigateSlides(Directions.NextSlide)            Case "btnFirst"                NavigateSlides(Directions.FirstSlide)            Case "btnLast"                NavigateSlides(Directions.LastSlide)        End Select    End Sub

    When incoming data is received from the serial port, you need to retrieve the incoming data. The incoming data contains commands sent from the Windows Mobile device instructing your application to navigate the slides. The DataReceived event is defined as follows:

    '---data received from Bluetooth serial port---    Private Sub DataReceived( _       ByVal sender As Object, _       ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _       Handles serialPort.DataReceived        '---retrieve the command sent---        Dim command As String = serialPort.ReadLine()        Select Case command            Case "Prev"                NavigateSlides(Directions.PrevSlide)            Case "Next"                NavigateSlides(Directions.NextSlide)            Case "First"                NavigateSlides(Directions.FirstSlide)            Case "Last"                NavigateSlides(Directions.LastSlide)        End Select    End Sub

    Last, but not least, service the Form1_FormClosing event so that the slide deck can be closed when the application is shut down:

        '---when the app is closed, close the slide deck too---Private Sub Form1_FormClosing( _   ByVal sender As Object, _   ByVal e As System.Windows.Forms.FormClosingEventArgs) _   Handles Me.FormClosing        PowerPTApp.Quit()    End Sub

    That's it! Now, the desktop portion of the application is done!

    Translate the Controller for Windows Mobile Devices
    With the desktop component done, now you'll use Visual Studio 2005 to create a Windows Mobile application. Name the project RemoteController_WM.

    Figure 3. The Default Form1: Populated with the various controls.

    Populate the default Form1 with the following controls (see Figure 3):

    • Button
    • Label
    • MenuItem

    Switch to the code-behind of Form1 and declare the following member variable:

    Public Class Form1    Private WithEvents serialPort As New IO.Ports.SerialPort

    Double-click the Open MenuItem control and use the code in Listing 5.

    Author's Note: The COM6 is dependent on which COM port you have selected to use on your Windows Mobile device. Refer to the last section of this article to determine which COM port to use.

    Double-click on each of the Button controls and use the code in Listing 6.

    Define the DataReceived event so that you can receive messages sent from the desktop application:

         '---receives data from the Bluetooth comms---    Private Sub DataReceived( _      ByVal sender As Object, _      ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _      Handles serialPort.DataReceived        lblSlideNo.BeginInvoke(New _        myDelegate(AddressOf UpdateLabel), _        New Object() {})    End Sub

    The delegate and UpdateLabel() subroutines are defined as follows:

        '---delegate and subroutine to update the slide no.---    Public Delegate Sub myDelegate()    Public Sub UpdateLabel()        Dim response As String = serialPort.ReadLine()        lblSlideNo.Text = response    End Sub

    Finally, service the Form1_Disposed event to close the serial port when the application exits:

        '---when the app exits, close the serial port---Private Sub Form1_Disposed( _   ByVal sender As Object, _   ByVal e As System.EventArgs) _   Handles MyBase.Disposed        serialPort.Close()    End Sub

    Testing the Two Applications
    To test the applications, first pair up your Windows Mobile device with your computer.

    On the Windows Mobile device, go to your Bluetooth settings and in the COM Ports section, tap the New Incoming Port item (see left of Figure 4). Select an available COM port number. This example selects COM6 for its Windows Mobile device.

    src=
    Figure 4: The COM Port Number. This example selects COM6 for its Windows Mobile device.
     
    Figure 5: The SPP Service. Ticking the checkbox shows that COM18 is used for this serial connection.

    On your computer, launch the Bluetooth application (in Windows XP) and select the Windows Mobile device that you have paired and click Properties (see Figure 5). Select the Services tab and you should be able to see the Serial Port (SPP) service offered by your Windows Mobile device. Tick the checkbox and, as shown in Figure 5, you'll see that COM18 is used by my computer for this serial connection.

    Once the serial port connection is established, you can now deploy the RemoteController_WM project onto your Windows Mobile device. At the same time, run the RemoteController project.

    In your Windows Mobile device, tap the Open menu item. This will open the serial connection to the desktop through Bluetooth.

    On the desktop application, click "Open Serial Port" and then "Select PowerPoint file to load" to select a PowerPoint slide deck to view. You will now be able to navigate the PowerPoint slide deck using either your Windows Mobile device or the desktop application (see Figures 6 and 7).


    Figure 6: Navigating the PowerPoint Slide Deck . Using your Windows Mobile device.
     
    Figure 7: Navigating the PowerPoint Slide Deck. Using your desktop application.

    Brighter Horizons
    You have now seen how to programmatically manipulate a PowerPoint slide deck using a Windows Mobile device connected to your PC through Bluetooth. With these concepts, hopefully you can define your own communication protocols and create interesting Bluetooth applications.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist