RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Programming Windows Mobile 5.0 Applications Using the .NET Compact Framework : Page 3

Visual Studio 2005 is the premier development platform for Windows Mobile 5.0. This article explores its new capabilities in detail.

Integration with Outlook Mobile
In the past, integrating your application with the PIM functionality on your device was a hair-pulling experience. Windows Mobile 5.0 now exposes the functionality in Outlook Mobile through managed classes found in the Microsoft.WindowsMobile.PocketOutlook namespace. .NET Compact Framework developers can now easily integrate data from Outlook Mobile into their application using these managed classes.

As an example, let's build an application that allows a user to select a contact from Contacts and then send an e-mail to the selected contact.

First, add a reference to the Microsoft.WindowsMobile.Forms and Microsoft.WindowsMobile.PocketOutlook assemblies and import the required namespaces.

From a developer's viewpoint, Windows Mobile 5.0 exposes many of its APIs as managed classes, thereby allowing developers using the .NET Compact Framework to easily build compelling applications that were once only possible to native developers.
   Imports Microsoft.WindowsMobile.Forms
   Imports Microsoft.WindowsMobile. _
To select a contact, use the ChooseContactDialog class.

   Private Sub btnSelectContact_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles btnSelectContact.Click
      Dim contactPicker As New _
      Dim result As DialogResult = _
      If result = Windows.Forms.DialogResult.OK Then
         lblName.Text = contactPicker.SelectedContactName
         lblEmail.Text = contactPicker.SelectedContact.Email1Address
         PictureBox1.Image = contactPicker.SelectedContact.Picture
      End If
   End Sub
Figure 8 shows the flow of the application.

Figure 8: Selecting a contact from the Contact application
To send an e-mail, you use the EmailMessage class.

   Private Sub MenuItem1_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles MenuItem1.Click
      Dim message As New EmailMessage
      message.Subject = "Generated Email"
      message.BodyText = txtMessage.Text
      Dim client As New Recipient(lblEmail.Text)
      Dim currentSession As New OutlookSession
      MsgBox("Message sent!")
   End Sub
Figure 9 shows the flow of the application. Once the e-mail is sent, you can go to Messaging (choose the Outbox folder) to verify that an e-mail has indeed been created.

Figure 9: Sending an e-mail.
Intercepting SMS Messages
For managed developers, Windows Mobile 5.0 can intercept incoming SMS messages. For example, you might write your own custom push-email solution by sending yourself an SMS message whenever a new e-mail is received. When your Windows Mobile 5 device receives the message, your application can intercept the message and then automatically fire up your Web browser to navigate to your Web e-mail.

You can use the MessageInterceptor class to intercept incoming messages and then perform a check on its content so that if it fulfills your criteria, you can perform a specific action. Listing 1 shows how you can intercept incoming SMS messages by checking to see if the message body starts with the word "invoke". If it does, the code launches Pocket Internet Explorer to navigate to http://www.hotmail.com/. (For this example, you need to add a reference to the Microsoft.WindowsMobile and Microsoft.WindowsMobile.PocketOutlook assemblies.)

The MessageInterceptor class is useful for automation purposes. Suppose your device contains confidential information and you are worried that the information may fall into the wrong hands if you lose your device. You could write an application that will wipe out all the sensitive data on the device if it receives a specially-coded SMS message.

Integrating with Calendar
You can now easily integrate your application with the Calendar application. The following code segment shows how easy it is to create an appointment in Calendar. (This example requires you to add a reference to the Microsoft.WindowsMobile.PocketOutlook assembly.)

   Imports Microsoft.WindowsMobile.PocketOutlook
   Dim appt As New Appointment
   appt.Subject = "Meeting with Jeff"
   appt.Start = New DateTime(2006, 7, 15, 9, 0, 0)
   appt.End = New DateTime(2006, 7, 15, 11, 0, 0)
   '---vibrate the device as a reminder
   appt.ReminderVibrate = True
   '---repeat the reminder
   appt.ReminderRepeat = True
   Dim currentSession As New OutlookSession

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date