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):
- Label
- Button
- 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
LastSlide
End 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!