Step by Step: Introduction to the New Managed APIs in Windows Mobile 5.0

 

Microsoft Corporation

June 2006

Applies to:
   Microsoft .NET Compact Framework version 1.0
   Microsoft Visual Studio 2005
   Windows Mobile version 5.0 software for Pocket PCs
   Windows Mobile version 5.0 software for Smartphones

Summary: Learn about the new managed application programming interfaces (APIs) in Windows Mobile 5.0 in this self-paced hands-on lab (HOL). You will improve on an existing application by making use of these new interfaces. Upon completion of this HOL, you will be ready to use these APIs to simplify your existing code or extend your applications to make use of the new capabilities of Windows Mobile 5.0. This HOL will take 1 hour to complete. (40 printed pages)

Download MEDC06_HOL202.msi from the Microsoft Download Center.

Contents

Introduction
Lab 1: Introduction to the New Managed APIs in Windows Mobile 5.0
Summary
Appendix A: Terminating an Application That Is Running on a Device or Emulator
Appendix B: Setting Up Your Computer

The following applications are required to run this HOL:

  • Microsoft Windows XP Professional

  • Internet Information Services (IIS)

    This HOL uses IIS for Windows XP Professional. Be sure that the IIS component is installed. See Appendix B for instruction about how to install the IIS component.

  • Visual Studio 2005

    This HOL requires Visual Studio 2005 Standard, Professional, or Team System Editions. It will not work with any of the Express Editions. If you do not have the correct edition of Visual Studio 2005, find out how you can acquire it from the Visual Studio 2005 Developer Center.

  • Microsoft ActiveSync 4.0 or later

    ActiveSync 4.0 or later allows for connectivity between a Windows Mobile–based device and your computer.

  • Windows Mobile 5.0 SDKs

    The Windows Mobile 5.0 SDKs for Pocket PC and Smartphone enable development for Windows Mobile–based devices in Visual Studio 2005.

    Download and install Windows Mobile 5.0 SDK for Pocket PC.

    Download and install Windows Mobile 5.0 SDK for Smartphone.

  • Set up your computer

    Follow the directions in Appendix A and Appendix B to set up your computer for this HOL.

Credentials Used

The following phone numbers are used in this HOL:

  • (603) 555-9999
  • (306) 555-7619
  • (212) 222-5555
  • (310) 555-3662

Introduction

In this HOL, you will learn about the new managed APIs in Windows Mobile 5.0. You will improve on an existing application by making use of these new interfaces. Upon completion of this HOL, you will be ready to use these APIs to simplify your existing code or extend your applications to make use of the new capabilities of Windows Mobile 5.0.

Lab 1: Introduction to the New Managed APIs in Windows Mobile 5.0

This lab introduces many of the newly available Windows Mobile 5.0–based managed APIs such as Telephony, Messaging, Picture Picker, Contact Picker, and the State and Notifications Broker API. To understand these APIs and how they might fit into an application, you will update an existing .NET Compact Framework application, and you will replace legacy features with more appropriate features provided by these new APIs.

You will then add several new features that more closely integrate the application with the device's capabilities. These new features improve the productivity of the user by automating common tasks.

The application that you will be updating is an existing Smartphone application that field sales representatives use who are from a high-end art and photography dealer. At a high-end dealership, sales representatives spend a large amount of time on the road working closely with individual clients. These sales representatives must have easy access to client information and must be able to work effectively when not in the office.

The existing application is a simple contact manager that keeps track of contact names, work phone numbers, mobile phone numbers, and notes about that client. The application uses a custom data format to track client information because it does not take advantage of the available Microsoft Pocket Outlook features. It also provides no integration with any phone features. The user must manually perform actions such as dialing phone numbers and sending e-mail messages.

In this lab, you will integrate the application with Pocket Outlook and replace the custom data format. You will then use the other APIs to closely integrate the application with the features of the phone, such as automatically dialing a contact and sending e-mail messages. You will also update the application to monitor incoming and manually placed calls, and match the call with the associated client in the Contact list, so that client's information is automatically displayed.

Lab Objective

The objective of this lab is to introduce the managed APIs that are available as part of the Windows Mobile 5.0 platform and to demonstrate their effectiveness in improving user efficiency.

In this HOL, you will perform the following exercises:

  • Using Pocket Outlook to replace a proprietary data store
  • Using Contact Picker to add search capabilities
  • Using Telephony to provide automatic dialing
  • Using Messaging and the Picture Picker to send e-mail messages with attachments
  • Using the State and Notifications Broker API to retrieve system state information
  • Using the State and Notifications Broker API to receive notifications of changes in system state

Exercise 1: Using Pocket Outlook to Replace a Proprietary Data Store

In this exercise, you will update the application so contact information comes from Pocket Outlook rather than relying on a separate, proprietary data store. The Pocket Outlook integration duplicates the existing application behavior and introduces a new Find Contact feature.

Before modifying the application, you should briefly become familiar with its behavior and implementation. To understand the program's current behavior, run it in the Windows Mobile 5.0 Smartphone emulator.

To become familiar with the existing application

  1. If Visual Studio is not already open, click Start | All Programs | Microsoft Visual Studio 2005 | Microsoft Visual Studio 2005.
  2. In Visual Studio 2005, click File | Open | Project/Solution.
  3. In the Open Project dialog box, browse to C:\Program Files\Windows Mobile Developer Samples\HOLs\MEDC06_HOL202\Exercises\.
  4. Select FieldSales.sln, and then click Open. The FieldSales solution opens.

Note After they are opened, the solution, project, and source files should now appear in Solution Explorer in Visual Studio 2005. If Solution Explorer doesn't automatically display, click View | Solution Explorer to make it visible.

  1. Verify that Windows Mobile 5.0 Smartphone Emulator is selected in the drop-down list box in the Connection Manager.

  2. Start the application by clicking Debug | Start Without Debugging.

  3. Do one of the following:

    • If prompted by the Deploy FieldSales dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.
    • If the emulator does not appear, look for a Windows taskbar button, and then click it to bring the emulator to the foreground. Be aware that the first time the emulator starts, it may take several minutes.
  4. On the emulator, click the left soft key under the word Next to scroll through the list of contacts, as shown in Figure 1.

    Figure 1. Viewing contacts in the emulator. Click the thumbnail for a larger image.

  5. After you are comfortable with the behavior of the application, click the right soft key under the word Menu, and then click Exit to close the application.

  6. Learn about the implementation of the existing application by examining the contents of the FormMain.cs source file. (To open this file, right-click FormMain.cs in Solution Explorer, and then click View Code.)

    The key things to notice in this source file are the declarations of the _dataManager variable, _currentItem variable, and the ShowNext method. The _dataManager variable is the object responsible for managing the existing legacy data. The _currentItem variable is the currently selected contact. The ShowNext method is called each time the user clicks the Next command. It is responsible for retrieving the next contact from _dataManager, storing it in _currentItem, and updating the form.

    Although this implementation provides an adequate solution for managing client data, it duplicates the features provided by Pocket Outlook, and in many cases it may duplicate the Pocket Outlook contact data as well.

In the following procedure, you will remove the existing legacy data management implementation from the application and update it to provide the same behavior by using Pocket Outlook. First, you will add an assembly reference to the Pocket Outlook assembly, Microsoft.WindowsMobile.PocketOutlook.

To update the application to use Pocket Outlook

  1. In Solution Explorer, right-click the word References, and then click Add Reference.

  2. In the Add Reference dialog box, click Microsoft.WindowsMobile.PocketOutlook, and then click OK, as shown in Figure 2.

    Figure 2. The Add Reference dialog box

  3. Add a using declaration for the "Microsoft.WindowsMobile.PocketOutlook" namespace by doing the following:

    • If FormMain.cs is not already open in Visual Studio, open it by right-clicking FormMain.cs in Solution Explorer, and then by clicking View Code.

    • Locate the existing using declarations at the top of the FormMain.cs file.

    • Add the following using declaration for "Microsoft.WindowsMobile.PocketOutlook" immediately following the existing using declarations.

      using Microsoft.WindowsMobile.PocketOutlook;
      

    There are two helper methods for displaying details on the form at the bottom of the FormMain class. One, DisplayFieldSalesData, receives a custom FieldSalesData item; and the other, DisplayContact, receives an Outlook Contact and is commented out. At this time, you will reverse which one is commented out.

  4. Locate the DisplayFieldSalesData method near the bottom of the FormMain class, and comment it out by highlighting all of its rows, and then by clicking Edit | Advanced | Comment Selection, so it appears as shown in the following code example.

    //private void DisplayFieldSalesData(FieldSalesData item)
    //{
    //    txtName.Text = item.FileAs;
    //    txtWorkPhone.Text = item.BusinessTelephoneNumber;
    //    txtMobilePhone.Text = item.MobileTelephoneNumber;
    //    lblNotes.Text = item.Body;
    //}
    
  5. Locate the DisplayContact method near the bottom of the FormMain class, which is currently commented out, and uncomment it by highlighting all of its rows, and then by clicking Edit | Advanced | Uncomment Selection, so it appears as shown in the following code example.

    private void DisplayContact(Contact contact)
    {
        txtName.Text = contact.FileAs;
        txtWorkPhone.Text = contact.BusinessTelephoneNumber;
        txtMobilePhone.Text = contact.MobileTelephoneNumber;
        lblNotes.Text = contact.Body;
    }
    

    To communicate with Pocket Outlook, applications must first create a session. The session provides connectivity to Pocket Outlook in much the same way that a database connection provides connectivity to a database, and the session will be used throughout the application to communicate with Pocket Outlook. When the application no longer needs the connection, the session must be disposed of.

  6. To create the Pocket Outlook session, add the following declaration to the FormMain.cs file immediately after the existing _dataManager declaration.

    OutlookSession _outlook = new OutlookSession();
    
  7. Contact items in Pocket Outlook are represented by the Contact class. To keep track of the current Contact displayed by your application, add the following declaration to FormMain.cs immediately after the _currentItem declaration.

    Contact _currentContact = null;
    

    Because you will no longer be using them, you should comment out the variable declarations for _dataManager and _currentItem.

  8. Locate the declaration of _dataManager just after the FormMain constructor, and then comment out the following line.

    //FieldSalesDataManager _dataManager = new FieldSalesDataManager();
    
  9. Locate the following _currentItem declaration a few lines further down, and comment it out as well.

    //FieldSalesData _currentItem;
    
  10. In the FormMain.cs file, locate the menuExit_Click method.

  11. To dispose of the Pocket Outlook session when the application is closed, call the Pocket Outlook session's Dispose method in the menuExit_Click method immediately prior to the existing call to the Close method.

    _outlook.Dispose();
    

    Now update the ShowNext method to scroll through the Pocket Outlook contacts. You are going to modify the implementation so each time ShowNext is called, it asks Pocket Outlook for the index of the currently displayed contact, and then increments that index by 1. Use the modulus operator (%) to loop back to the beginning when the end is reached.

  12. In the FormMain.cs file, locate the ShowNext method to update the ShowNext method.

  13. Declare an int variable named index with an initial value of 0 as the first line of the method.

    int index = 0;
    
  14. The index value needs to be incremented only if a contact is already displayed, so add an if statement to see if the value of _currentContact is not null, as shown in the following code example.

    if (_currentContact != null)
    {
    }
    
  15. In the if statement, ask the Pocket Outlook Contacts folder's ContactsCollection for the index of the currently displayed contact by calling the IndexOf method. Store the result in index, as shown in the following code example.

    index = _outlook.Contacts.Items.IndexOf(_currentContact);
    
  16. In the if statement, increment the index by 1. Use the modulus operator (%) to set the index back to 0 if the index reaches the number of contacts that are contained in the Contacts folder's ContactsCollection, as shown in the following code example.

    index = (index + 1) % _outlook.Contacts.Items.Count;
    
  17. By determining the index of the next contact to retrieve, you can now use the Contacts folder's ContactsCollection indexer to retrieve that contact. Add the following line of code immediately after the if block.

    _currentContact = _outlook.Contacts.Items[index];
    
  18. After the line that assigns _currentContact, call the DisplayContact helper method, passing it**_currentContact**, as shown in the following code example.

    DisplayContact(_currentContact);
    
  19. Comment out the lines in the ShowNext method where _currentItem is assigned the value of _dataManager.Next and where it is subsequently passed to the DisplayFieldSalesData helper method, as shown in the following code example.

    //_currentItem = _dataManager.Next;
    //DisplayFieldSalesData(_currentItem);
    
  20. Verify that the complete ShowNext method looks like the following code example.

    private void ShowNext()
    {
        int index = 0;
        if (_currentContact != null)
        {
            index = _outlook.Contacts.Items.IndexOf(_currentContact);
            index = (index + 1) % _outlook.Contacts.Items.Count;
        }
        _currentContact = _outlook.Contacts.Items[index];
        DisplayContact(_currentContact);
        //_currentItem = _dataManager.Next;
        //DisplayFieldSalesData(_currentItem);
    }
    

You are now ready to test the new version of the application.

To test the application

  1. In Visual Studio, click Build | Build Solution. Correct any compilation errors before you proceed.
  2. Verify that Windows Mobile 5.0 Smartphone Emulator is still selected in the drop-down list box.
  3. Start the application by clicking Debug | Start Without Debugging.
  4. If prompted by the Deploy FieldSales dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.
  5. Click the left soft key located under the word Next, and scroll through the contact list. Notice that there are now several more contacts available than before. These additional contacts are available because the application is now reading directly from the Pocket Outlook contact list rather than a separate proprietary data store.
  6. After you are comfortable with the behavior of the application, click the right soft key under the word Menu, and then click Exit to close the application.

Exercise 2: Using Contact Picker to Add Search Capabilities

In this exercise, you will add a search feature that users can use to look up specific contacts, rather than only being able to scroll through the contacts as they do now. To implement this capability, you will use the Contact Picker class, ChooseContactDialog.

Before you can use the ChooseContactDialog class, you must add a reference for the Microsoft.WindowsMobile.Forms assembly to the project and add a using declaration for the corresponding namespace to the source code.

To add assembly references and namespace declarations

  1. In Solution Explorer, right-click References, and then click Add Reference.

  2. In the Add Reference dialog box, select Microsoft.WindowsMobile.Forms.

    Note There are several assemblies visible in the Add Reference dialog box that contain the word Forms. Be sure to choose the assembly named Microsoft.WindowsMobile.Forms, as shown in Figure 3.

    Figure 3. The Add Reference dialog box with the Microsoft.WindowsMobile.Forms assembly selected

  3. Click OK.

  4. If FormMain.cs is not already open in Visual Studio, open it by right-clicking FormMain.cs in Solution Explorer, and then by clicking View Code.

  5. Locate the existing using declarations at the top of the FormMain.cs file.

  6. Add the following using declaration for Microsoft.WindowsMobile.Forms immediately following the existing using declarations.

    using Microsoft.WindowsMobile.Forms;
    

You need to modify the application menu to provide additional options by enabling the existing Find command and by implementing an event handler that provides commands to find a contact.

To enable the Find command

  1. In Solution Explorer, double-click FormMain.cs to open FormMain.cs in the form designer.

  2. Click the Menu menu on the form designer.

  3. Right-click the currently unavailable Find command, and then click Properties.

  4. In the Properties pane, double-click the Enabled property to toggle its value to True. The commands should now appear as shown in Figure 4.

    Figure 4. Enabling the Find command in the form designer. Click the thumbnail for a larger image.

You are now ready to add the functionality to let the user choose a contact.

To add the Find functionality

  1. In the form designer, double-click the Find command.

    This step opens the FormMain.cs code and creates a menuFind_Click method.

  2. In the menuFind_Click method, declare and create an instance of the ChooseContactDialog class. Name the variable contactDialog, as shown in the following code example.

    ChooseContactDialog contactDialog = new ChooseContactDialog();
    

    The ChooseContactDialog class provides the ability to select either a contact or specific contact properties, such as an e-mail address or phone number. In this example, the user should select the actual contact—not individual properties.

  3. Set the ChooseContactDialog class's ChooseContactOnly property to true to indicate that only the contact names are to be displayed, as shown in the following code example.

    contactDialog.ChooseContactOnly = true;
    
  4. Display the ChooseContactDialog class by calling the ShowDialog method. The ShowDialog method returns DialogResult, which indicates whether the user made a selection or canceled the dialog box. Store the result of the call to ShowDialog in a DialogResult variable named result, as shown in the following code example.

    DialogResult result = contactDialog.ShowDialog();
    
  5. When the call to ShowDialog is returned, you need to check whether the user actually made a selection by adding an if statement to check whether the result variable contains the enumeration DialogResult.OK, as shown in the following code example. If the user had closed the dialog box without making a selection, the result variable would contain DialogResult.Cancel.

    if (result == DialogResult.OK)
    {
    }
    
  6. If the user makes a selection, the application should now display the selected contact. In the if statement, assign the contactDialog.SelectedContact property to _currentContact, as shown in the following code example.

    _currentContact = contactDialog.SelectedContact;
    
  7. Update the text boxes with this contact's information. In the if statement, call the DisplayContact method, passing it _currentContact, as shown in the following code example.

    DisplayContact(_currentContact);
    
  8. Verify that the menuNext_Click method looks like the following code example.

    private void menuFind_Click(object sender, EventArgs e)
    {
        ChooseContactDialog contactDialog = new ChooseContactDialog();
        contactDialog.ChooseContactOnly = true;
        DialogResult result = contactDialog.ShowDialog();
        if (result == DialogResult.OK)
        {
            _currentContact = contactDialog.SelectedContact;
            DisplayContact(_currentContact);
        }
    }
    

You are now ready to test the new application functionality.

To test the new functionality

  1. In Visual Studio, click Build | Build Solution. Correct any compilation errors before you proceed.

  2. Verify that Windows Mobile 5.0 Smartphone Emulator is still selected in the drop-down list box.

  3. Start the application by clicking Debug | Start Without Debugging.

  4. If prompted by the Deploy FieldSales dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.

  5. Click the right soft key under the word Menu to display the pop-up menu.

  6. Choose the Find command by either clicking it with your mouse or by using your mouse to select the number 2 on the emulator's keypad.

  7. Select one of the contacts. The application then displays the appropriate contact information, as shown in Figure 5.

    Figure 5. Display of contact information

  8. Click the Find command again.

  9. When the Contact Picker opens, start typing a portion of one of the contacts' names. Notice that the list is automatically filtered based on the entered text.

  10. Select one of the contacts.

  11. Click the left soft key under the word Next. Notice that the scrolling continues from the point of the most recent selection.

    This feature works correctly because, in the previous procedure, you implemented the ShowNext method, which uses the ContactCollection.IndexOf method to determine which index to use when scrolling rather than incrementing a simple index managed by the application.

  12. After you are comfortable that the new feature works correctly, close the application by clicking the right soft key, and then by clicking Exit.

Exercise 3: Using Telephony to Provide Automatic Dialing

In this exercise, you will use the new managed Telephony API to provide automatic phone dialing as part of your application. You will do this by enabling two commands, Dial Work Phone and Dial Mobile Phone, and by implementing event handlers for them, which will automatically dial the appropriate number for the contact that is currently displayed. Adding dialing support to your application allows the user to place a phone call without needing to dial it manually or having to leave the application.

Before you can use the Telephony API, you must add a reference for the Microsoft.WindowsMobile.Telephony assembly to the project, and add a using declaration for the corresponding namespace to the source code.

To add assembly references and namespace declarations

  1. In Solution Explorer, right-click References, and then click Add Reference.

  2. In the Add Reference dialog box, select Microsoft.WindowsMobile.Telephony, and then click OK.

  3. If FormMain.cs is Visual Studio, open it by right-clicking FormMain.cs in Solution Explorer, and then by clicking View Code.

  4. Locate the existing using declarations at the top of the FormMain.cs file.

  5. Add the following using declaration for Microsoft.WindowsMobile.Telephony immediately following the existing using declarations.

    using Microsoft.WindowsMobile.Telephony;
    

Now, you need to modify the application menu to provide the two commands.

To update the menu

  1. In Solution Explorer, double click FormMain.cs to open FormMain.cs in the form designer.
  2. If the menu is not already expanded, click the Menu menu on the form designer.
  3. Right-click the currently unavailable Dial Work Phone command, and then click Properties.
  4. In the Properties pane, double-click the Enabled property to toggle its value to True.
  5. Click the Dial Mobile Phone command.
  6. In the Properties pane, double-click the Enabled property to toggle its value to True.

In the following procedure, you will use the Phone class to initiate a phone call to the current client by using the information that is stored in the _currentContact variable.

First, you need to add the code to place a call to the client's work phone number.

To add automatic dialing

  1. In the form designer, double-click the Dial Work Phone command. This step opens the FormMain.cs code and creates a menuDialWorkPhone_Click method.

  2. In the menuDialWorkPhone _Click method, declare and create an instance of the Phone class. Name the variable telephone, as shown in the following code example.

    Phone telephone = new Phone();
    
  3. Use the Phone class's Talk method to place a call to the current contact's BusinessTelephoneNumber, as shown in the following code example.

    telephone.Talk(_currentContact.BusinessTelephoneNumber + "\0");
    

    Note The null character ("\0") must be added to the end of the phone number string due to a bug in the current implementation of the Phone.Talk method. The Phone.Talk method passes the string containing the phone number to the native PhoneMakeCall function without adding null termination. As a result, similar when passing a non-null terminated string in C or C++, you will get random results when calling the Talk method. Sometimes it will work properly, sometimes it will add random characters to the end of the phone number, and sometimes it may even crash the application. A simple solution is to explicitly include the null termination when calling the Talk method. Fortunately, this bug will be fixed in a future release of Windows Mobile 5.0, and the manual solution used in this lab will still continue to work because native code will simply consider the string terminated when it encounters the first null character.

    Now, you need to add the code to place a call to the client's mobile phone number.

  4. In Solution Explorer, double-click FormMain.cs to open FormMain.cs in the form designer.

  5. In the form designer, double-click the Dial Mobile Phone command. This step opens the FormMain.cs code and creates a menuDialMobilePhone_Click method.

  6. In the menuDialMobilePhone_Click method, add the following code to declare an instance of the Phone class and place a call by using the current client's MobileTelephoneNumber.

    Phone telephone = new Phone();
    telephone.Talk(_currentContact.MobileTelephoneNumber + "\0");
    
  7. Verify that the menuDialWorkPhone_Click and menuDialMobilePhone_Click methods look like the following code example.

    private void menuDialWorkPhone_Click(object sender, EventArgs e)
    {
        Phone telephone = new Phone();
        telephone.Talk(_currentContact.BusinessTelephoneNumber + "\0");
    }
    
    private void menuDialMobilePhone_Click(object sender, EventArgs e)
    {
        Phone telephone = new Phone();
        telephone.Talk(_currentContact.MobileTelephoneNumber + "\0");
    }
    

You are now ready to test the new application functionality.

To test the new functionality

  1. In Visual Studio, click Build | Build Solution. Correct any compilation errors before you proceed.

  2. Verify that Windows Mobile 5.0 Smartphone Emulator is still selected in the drop-down list box.

  3. Start the application by clicking Debug | Start Without Debugging.

  4. If prompted by the Deploy FieldSales dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.

  5. Click the right soft key under the word Menu to display the pop-up menu.

  6. Choose the Dial Work Phone command to initiate the phone call. The emulator display switches to the Phone screen. The Phone screen first indicates that the phone is dialing and then is connected, as shown in Figure 6.

    Note There may be a delay of a few seconds between the time you select the Dial Work Phone command and when the emulator updates the display to show the Phone screen.

    Figure 6. The emulator display when dialing and connecting a phone call

  7. To end the phone call, click the emulator's End button (the button that has a red telephone on it). After a few seconds, your application reappears.

  8. Click the left soft key to scroll through different contacts, and then test both the Dial Work Phone and Dial Mobile Phone commands. Verify that a call is placed to the correct phone number in each case.

  9. After you are comfortable that the new feature works correctly, close the application by clicking the right soft key, and then by clicking Exit.

Exercise 4: Using Messaging and the Picture Picker to Send E-Mail Messages with Attachments

In this exercise, you will use the new Picture Picker and Messaging API to provide the user with the capability to send a contact an e-mail message with a picture as an attachment. You will add this feature by enabling the Send Picture command and by adding an event handler for the command.

Now, you need to modify the application menu to provide the new command.

To update the menu

  1. In Solution Explorer, double click FormMain.cs to open FormMain.cs in the form designer.
  2. If the menu is not already expanded, click the Menu menu on the form designer.
  3. Right-click the currently unavailable Send Picture command, and then click Properties.
  4. In the Properties pane, double-click the Enabled property to toggle its value to True.

In the following procedure, you will use the Picture Picker to allow the user to select which photo the user wants to send to the client.

To use Picture Picker

  1. In the form designer, double-click the Send Picture command. This step opens the FormMain.cs code and creates a menuSendPicture_Click method.

  2. In the menuSendPicture_click method, declare and create an instance of the Picture Picker class, SelectPictureDialog. Name the variable picturePicker, as shown in the following code example.

    SelectPictureDialog picturePicker = new SelectPictureDialog();
    

    To save time typing, you will use a code example to insert the following code.

  3. Place the cursor on the line immediately following the line of code that you just typed.

  4. In Visual Studio, click Edit | IntelliSense | Insert Snippet.

  5. Double-click My Code Snippets, and then double-click SnippetSendPicture1. Visual Studio inserts the following code.

    picturePicker.InitialDirectory = @"\Images";
    picturePicker.CameraAccess = false;
    picturePicker.ShowDrmContent = true;
    picturePicker.ShowForwardLockedContent = false;
    

    This code sets the SelectPictureDialog class to initially display pictures in the \Images folder. Because the user will only be showing professional photos, the application should not allow the user to select pictures that might be stored on an attached camera, so the CameraAccess property is set to false. You must also consider how Digital Rights Management (DRM) issues are to be handled. Assuming that the users of this application have properly purchased photos or artwork being sold, the application should allow the user to select DRM protected files, so the ShowDrmContent property is set to true. Images that have been specifically protected against being forwarded should not be displayed because the attempt to send them by e-mail will fail, so the ShowForwardLockedContent property is set to false.

  6. Display the SelectPictureDialog class by using the ShowDialog method, and then assign the returned DialogResult to a variable named result, as shown in the following code example.

    DialogResult result = picturePicker.ShowDialog();
    
  7. Verify that the menuSendPicture_Click method looks like the following code example.

    private void menuSendPicture_Click(object sender, EventArgs e)
    {
        SelectPictureDialog picturePicker = new SelectPictureDialog();
    
        picturePicker.InitialDirectory = @"\Images";
        picturePicker.CameraAccess = false;
        picturePicker.ShowDrmContent = true;
        picturePicker.ShowForwardLockedContent = false;
    
        DialogResult result = picturePicker.ShowDialog();
    }
    

In the following procedure, you will use the Messaging API to create an e-mail message, attach the selected picture, and display the message to the user before sending.

To use the Messaging API to send a picture in an e-mail message

  1. The application should create an e-mail message only if the user selects a picture, so add an if statement verifying that the user made a selection in SelectPictureDialog, as shown in the following code example. Add this statement immediately after the call to ShowDialog in the menuSendPicture_Click method.

    if (result == DialogResult.OK)
    {
    }
    
  2. In the if statement, declare and create an instance of the EmailMessage class. Name the variable message, as shown in the following code example.

    EmailMessage message = new EmailMessage();
    

    To save time typing, you will use a code example to insert the following code.

  3. Place the cursor on the line immediately following the line of code that you just typed.

  4. In Visual Studio, click Edit | IntelliSense | Insert Snippet.

  5. Double-click My Code Snippets, and then double-click SnippetSendPicture2. Visual Studio inserts the following code.

    message.Subject = "The picture we discussed";
    message.BodyText = "Attached please find the picture we discussed. " 
        + "Please feel free to contact me with any questions";
    Recipient addressee = new Recipient(_currentContact.Email1Address);
    message.To.Add(addressee);
    

    This code declares and creates an instance of the EmailMessage class named message. To make communicating with clients as easy as possible, the application populates the e-mail message, setting the Subject and BodyText properties. The e-mail message is addressed by declaring and creating an instance of the Recipient class, named addressee. The current client's Email1Address is passed to the constructor, and the addressee is added to the message.To collection.

  6. In the if statement, attach the picture the user selected to the message. This step requires creating an instance of the Attachment class that passes the selected picture's file name to the Attachment constructor. SelectPictureDialog exposes the selected file name as the FileName property. After it's created, the attachment is added to the message.Attachments collection, as shown in the following code example.

    Attachment picture = new Attachment(picturePicker.FileName);
    message.Attachments.Add(picture);
    

    The message is now ready to send. Although the application could send the message, it is probably better to give the user a chance to review and, if desired, modify the message before it's sent. The MessagingApplication.DisplayComposeForm method is a static method that provides this capability because it uses the standard compose form of the device-messaging application to display an e-mail message. After the message is displayed, the user can review, modify, and send the message just as the user would if the user was using the messaging application directly.

    Because it is common for a device to contain several messaging accounts, you should identify which account to use to display the message. If you do not do this step, the DisplayComposeForm method prompts the user to select the account. In this lab, assume that the first e-mail account exposed by the Pocket Outlook EmailAccounts collection is the default account.

  7. In the if statement, declare an EmailAccount variable named defaultAccount, and then assign it the first account in the EmailAccounts collection, as shown in the following code example.

    EmailAccount defaultAccount = _outlook.EmailAccounts[0];
    
  8. To display the message to the user, call the MessagingApplication.DisplayComposeForm method, and then pass defaultAccount as the first argument and pass message as the second argument, as shown in the following code example.

    MessagingApplication.DisplayComposeForm(defaultAccount, message);
    
  9. Verify that the menuSendPicture_Click method looks like the following code example.

    private void menuSendPicture_Click(object sender, EventArgs e)
    {
        SelectPictureDialog picturePicker = new SelectPictureDialog();
    
        picturePicker.InitialDirectory = @"\Images";
        picturePicker.CameraAccess = false;
        picturePicker.ShowDrmContent = true;
        picturePicker.ShowForwardLockedContent = false;
    
        DialogResult result = picturePicker.ShowDialog();
    
        if (result == DialogResult.OK)
        {
            EmailMessage message = new EmailMessage();
            message.Subject = "The picture we discussed";
            message.BodyText = "Attached is the picture we discussed. " 
                + "Please feel free to contact me with any questions";
            Recipient addressee = new         Recipient(_currentContact.Email1Address);
            message.To.Add(addressee);
            Attachment picture = new Attachment(picturePicker.FileName);
            message.Attachments.Add(picture);
    
            EmailAccount defaultAccount = _outlook.EmailAccounts[0];
            MessagingApplication.DisplayComposeForm(defaultAccount,         message);
        }
    }
    

You are now ready to test the new application's functionality.

To test the new functionality

  1. In Visual Studio, click Build | Build Solution. Correct any compilation errors before you proceed.

  2. Verify that Windows Mobile 5.0 Smartphone Emulator is still selected in the drop-down list box.

  3. Start the application by clicking Debug | Start Without Debugging.

  4. If prompted by the Deploy FieldSales dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.

  5. Click the right soft key under the word Menu to display the pop-up menu.

  6. Choose the Send Picture command. The Picture Picker is displayed, as shown in Figure 7.

    Figure 7. The Picture Picker. Click the thumbnail for a larger image.

  7. By using the navigational pad, browse to a picture.

  8. Click the left soft key under the word Select to select the picture. The e-mail message form appears and is fully populated with the e-mail address, subject, body text, and attachment, as shown in Figure 8.

    Figure 8. E-mail message form with a picture as an attachment

    You can send the message by clicking the left soft key under the word Send, or you can modify any portion of the message before you send the message.

  9. Close the application by clicking the right soft key under the word Menu, and then by clicking Exit.

    To verify that the message was actually submitted to the e-mail system, check the Pocket Outlook Outbox folder.

  10. Display the Home screen by clicking the Home button (the button below the left soft key and it has a picture of a house).

  11. Click the left soft key under the word Start.

  12. Browse to and select the Messaging icon.

  13. Choose Outlook E-mail.

  14. Click the right soft key under the word Menu.

  15. Select Folders, and then click the Action key (in the center of the emulator's navigational pad).

  16. Select Outbox, and then click the Action key. You should see a message with the subject "The picture we discussed." This is the message that the application sent.

Exercise 5: Using the State and Notifications Broker API to Retrieve System State Information

In this exercise, you will use the new State and Notifications Broker API to retrieve state information from the phone, and be notified of changes to the phone's state.The State and Notifications Broker API is a comprehensive API that provides access to more than 100 device state values, and state value change notifications.

Before you can use the State and Notification Broker API, you must add a reference for the Microsoft.WindowsMobile.Status and Microsoft.WindowsMobile assemblies to the project. You also must add a using declaration for the "Microsoft.WindowsMobile.Status" namespace to the source code.

To add assembly references and namespace declarations

  1. In Solution Explorer, right-click References, and then click Add Reference.

  2. In the Add Reference dialog box, click Microsoft.WindowsMobile.Status, and then click OK.

  3. Right-click References again. Click Add Reference, click Microsoft.WindowsMobile, and then click OK.

    Note You will not be using any classes from the Microsoft.WindowsMobile assembly. However, you must add a reference to it because the SystemState class (which is defined in the Microsoft.WindowsMobile.Status assembly) implements an interface that is defined in the Microsoft.WindowsMobile assembly.

  4. If FormMain.cs is not already open in Visual Studio, open it by right-clicking FormMain.cs in Solution Explorer, and then by clicking View Code.

  5. Locate the existing using declarations at the top of the FormMain.cs file.

  6. Add the following using declaration for Microsoft.WindowsMobile.Status immediately following the existing using declarations.

    using Microsoft.WindowsMobile.Status;
    

In the following procedure, you will use the State and Notifications Broker API to retrieve the device owner's name and phone number. You will then use this information to update the e-mail message you sent in the last exercise to provide a more professional closing.

Much of the functionally of the State and Notifications Broker API is made available through the SystemState class. You will use the SystemState.OwnerName and SystemState.OwnerPhoneNumber static properties to create the message's closing phrase.

To use State and Notifications Broker API to retrieve device information

  1. Verify that the owner information has been properly set on your emulator. Click the Home button. You should see the owner name of Judy Lew, as shown in Figure 9. The device owner information provides a standard way to access personalized information about the device owner and is easily customized for each individual user's device.

    Figure 9. The Home screen on a Smartphone emulator that displays the owner's name. Click the thumbnail for a larger image.

  2. In Visual Studio, open FormMain.cs in Code view if it is not already open, and then locate the menuSendPicture_Click method that you added in the last exercise.

  3. In the menuSendPicture_Click method, locate the line of code where message.BodyText is assigned to.

  4. Before this line of code, declare a string variable named ownerName, and then assign it the value of SystemState.OwnerName, as shown in the following code example.

    string ownerName = SystemState.OwnerName;
    
  5. On the next line, declare a string variable named ownerPhoneNumber, and then assign it the value of SystemState.OwnerPhoneNumber, as shown in the following code example.

    string ownerPhoneNumber = SystemState.OwnerPhoneNumber;
    
  6. Generate a closing phrase for the e-mail message that contains the owner's name and phone number. On the next line, create the closing phrase by using string.Format and the format string \nSincerely {0}\n{1}. Assign the result to a string variable named closing, as shown in the following code example.

    string closing = string.Format("\nSincerely {0}\n{1}", 
        ownerName, ownerPhoneNumber);
    
  7. Concatenate the closing to the end of message.BodyText. Replace the line that assigns message.BodyText with the following code example.

    message.BodyText = "Attached please find the picture we discussed. " 
        + "Please feel free to contact me with any questions" 
        + closing;
    
  8. Verify that the menuSendPicture_Click method looks like the following code example.

    private void menuSendPicture_Click(object sender, EventArgs e)
    {
        SelectPictureDialog picturePicker = new SelectPictureDialog();
        picturePicker.InitialDirectory = @"\Images";
        picturePicker.CameraAccess = false;
        picturePicker.ShowDrmContent = true;
        picturePicker.ShowForwardLockedContent = false;
        DialogResult result = picturePicker.ShowDialog();
    
        if (result == DialogResult.OK)
        {
            EmailMessage message = new EmailMessage();
            message.Subject = "The picture we discussed";
            string ownerName = SystemState.OwnerName;
            string ownerPhoneNumber = SystemState.OwnerPhoneNumber;
            string closing = string.Format("\nSincerely {0}\n{1}", 
                ownerName, ownerPhoneNumber);
            message.BodyText = "Attached please find the picture we         discussed." 
                + "Please feel free to contact me with any questions" 
                + closing;
            Recipient addressee = new         Recipient(_currentContact.Email1Address);
            message.To.Add(addressee);
            Attachment picture = new Attachment(picturePicker.FileName);
            message.Attachments.Add(picture);
    
            EmailAccount defaultAccount = _outlook.EmailAccounts[0];
            MessagingApplication.DisplayComposeForm(defaultAccount,         message);
        }
    }
    

    You can verify whether the program works by following the step in the procedure titled, "To test the new functionality" in Exercise 4. You should see that the e-mail message now contains a proper closing with Sincerely Judy Lew on the second line from the bottom of the message, which is followed by 603.555.9999 on the next line, as shown in Figure 10.

    Figure 10. The owner's name and phone number have been added to the message

Exercise 6: Using the State and Notifications Broker API to Receive Notifications of Changes in System State

In addition to providing access to the many state values on the device, the State and Notifications Broker API also supports notifying an application about changes to a value.

In this exercise, you will update the application to automatically show a contact's information when the contact calls the user and when the user initiates the call from outside the application. You will do this by creating an instance of the SystemState class and by using the SystemProperty enumeration to indicate that the application should be notified any time the user talks to someone who is in the contact list. After the SystemState instance is created, the application can handle SystemState Changed event.

To monitor for state changes, you must first create an instance of the SystemState class and use the SystemProperty enumeration to indicate which value should be monitored.

To create the SystemState instance

  1. In FormMain.cs, locate the declaration of the FormMain constructor.

  2. Immediately after the constructor body, declare a SystemState variable named _phoneCallContactState, as shown in the following code example.

    SystemState _phoneCallContactState;
    
  3. In the body of the FormMain constructor, immediately after the call to InitializeComponent, construct a new instance of the SystemState class, and then pass the SystemProperty.PhoneTalkingCallerContact to the constructor. Assign the result to _phoneCallContactState, as shown in the following code example.

    _phoneCallContactState = new SystemState(SystemProperty.PhoneTalkingCallerContact);
    

    The _phoneCallContactState instance now monitors SystemState.PhoneTalkingCallerContact for changes during execution of the application.

    Now you need to add the code necessary for _phoneCallContactState to notify your application when the value of SystemState.PhoneTalkingCallerContact changes. You will do this by handling the _phoneCallContactState.Changed event.

To handle SystemState change notifications

  1. On the next line (the line immediately following the construction of the SystemState instance), type the following code.

    _phoneCallContactState.Changed += 
    

    After you type the equal sign (=), Visual Studio prompts you to press TAB.

    Note   If Visual Studio does not prompt you to press TAB, you need to add the following code manually.

      new ChangeEventHandler(_phoneCallContactState_Changed);
    
  2. Press TAB. The line automatically completes to look similar to the following code example.

    _phoneCallContactState.Changed += 
        new ChangeEventHandler(_phoneCallContactState_Changed);
    
  3. When Visual Studio prompts you a second time to press TAB, press TAB. Visual Studio generates a default implementation of the phoneCallContactState_Changed method to handle notifications of changes to the SystemState.PhoneTalkingCallerContact value.

    Note   If Visual Studio does not prompt you to press TAB, you need to add the following code manually.

    void _phoneCallContactState_Changed(object sender, 
        ChangeEventArgs args)
    {
        throw new Exception("The method or operation is not     implemented.");
    }
    

    The application now contains all of the code necessary to handle changes to the value of the SystemState.PhoneTalkingCallerContact value.

  4. Verify that the FormMain constructor, phoneCallContactState_Changed method, and _phoneCallContactState declaration look like the following code example.

    public FormMain()
    {
        InitializeComponent();
    
        _phoneCallContactState = new
            SystemState(SystemProperty.PhoneTalkingCallerContact);
        _phoneCallContactState.Changed += new
            ChangeEventHandler(_phoneCallContactState_Changed);
    
        ShowNext();
    }
    
    void _phoneCallContactState_Changed(object sender, 
        ChangeEventArgs args)
    {
        throw new Exception("The method or operation is not     implemented.");
    }
    
    SystemState _phoneCallContactState;
    

    The _phoneCallContactState_Changed method is automatically called when the user has a phone conversation with someone in the Contacts list. You need is to modify the _phoneCallContactState_Changed method so the correct contact information is displayed.

To display the caller's contact information

  1. In the body of the _phoneCallContactState_Changed method, delete the line of code that throws the exception, as shown in the following code example.

    throw new Exception("The method or operation is not implemented.");
    
  2. Add an if statement that checks that the value of SystemState.PhoneTalkingCallerContact is not null, as shown in the following code example. This step is necessary because the value is null any time the user is not involved in a phone call, or if the phone call is with someone who is not in the Contacts list.

    if (SystemState.PhoneTalkingCallerContact != null)
    {
    }
    
  3. In the if statement, assign the value of SystemState.PhoneTalkingCallerContact to _currentContact, as shown in the following code example.

    _currentContact = SystemState.PhoneTalkingCallerContact;
    

    The _currentContact contains a reference to the Contact that the user is talking to.

  4. Update the text boxes with the contact's information by calling DisplayContact, which passes it _currentContact, as shown in the following code example.

    DisplayContact(_currentContact);
    
  5. There is a strong chance that your application may be running in the background at the time a phone call occurs. To give your application focus, call the Activate method, as shown in the following code example.

    this.Activate();
    
  6. Verify that the complete _phoneCallContactState_Changed method looks like the following code example.

    void _phoneCallContactState_Changed(object sender, 
        ChangeEventArgs args)
    {
        if (SystemState.PhoneTalkingCallerContact != null)
        {
            _currentContact = SystemState.PhoneTalkingCallerContact;
            DisplayContact(_currentContact);
            this.Activate();
        }
    }
    

You are now ready to test the new application functionality. The new feature automatically displays a contact's information if a contact calls the Smartphone or if the user manually calls a contact. There is no support for receiving calls to the emulator, so you'll test the feature by manually placing a phone call to one of the contacts.

To test the new application functionality

  1. In Visual Studio, click Build | Build Solution. Correct any compilation errors before you proceed.

  2. Verify that Windows Mobile 5.0 Smartphone Emulator is still selected in the drop-down list box.

  3. Start the application by clicking Debug | Start Without Debugging.

  4. If prompted by the FieldSales dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.

  5. Click the Home button to display the Home screen. The application is still running in the background.

  6. On the emulator's keypad, dial the phone number 6035557619.

  7. Click the Talk button (the button below the Home button, and it has a picture of a green phone receiver on it). The phone dials and then connects the call. Just after the phone call connects, the contact information for Jim Wilson automatically appears, as shown in Figure 11.

    Figure 11. The contact that you dialed is displayed in the applicaiton. Click the thumbnail for a larger image.

  8. End the call by clicking the End button (the button with a picture of a red phone receiver on it.) Try repeating Steps 6-8 by using a phone number that does not correspond to a contact, such as 2122225555. The application remains in the background.

  9. End the call, and then try another phone number that corresponds to a contact, such as 3105553662. Just after the phone call connects, the contact information for Jane Clayton automatically appears. End the call.

  10. When you are satisfied that the application is working as you expect, close the application by clicking the right soft key under the word Menu, and then by clicking Exit.

Summary

In this lab, you performed the following exercises:

  • Using Pocket Outlook to replace a proprietary data store
  • Using Contact Picker to add search capabilities
  • Using Telephony to provide automatic dialing
  • Using Messaging and the Picture Picker to send e-mail messages with attachments
  • Using the State and Notifications Broker API to retrieve system state information
  • Using the State and Notifications Broker API to receive notifications of changes in system state

In this lab, you used the Windows Mobile 5.0 managed APIs to update an existing .NET Compact Framework application to be more closely integrated with the supported features of the phone, and you improved user productivity by automating common tasks.

Appendix A: Terminating an Application That Is Running on a Device or Emulator

This appendix describes how to terminate an application that is running on a device or emulator. This is useful for cases where an application has been started without having the debugger attached and the application needs to be terminated so a new copy of the application can be deployed. You will terminate the application by using the Remote Process Viewer remote tool in Visual Studio.

Before you can terminate a process, you need to know the name of the executable file. In most cases, this is the same name as the Visual Studio project. If you are uncertain about the name of the executable file, you can find it in the project's properties.

To terminate an application that is running on a device or emulator by using the Remote Process Viewer remote tool

  1. In Visual Studio, click Project | xxx Properties, where xxx represents the name of the current project.

  2. In the Project Properties dialog box, note the value in the Assembly Name field. This is the name that the executable file will be running on the device or emulator.

  3. Close the Properties dialog box.

    Now, you can terminate the process.

  4. On the desktop computer, click Start | Microsoft Visual Studio 2005 | Visual Studio Remote Tools | Remote Process Viewer.

  5. When prompted by the Select a Windows CE Device dialog box, select the emulator or device where the application is running, as shown in Figure 12, and then click OK.

    Figure 12. Select a Windows CE Device dialog box

  6. After the connection to the emulator or device completes, select the application that you want to terminate in the top pane of the Remote Process Viewer, as shown in Figure 13.

    Figure 13. Selecting the application to terminate. Click the thumbnail for a larger image.

    You may need to widen the Process column (the leftmost column) to fully view the process names.

  7. In Windows CE Remote Process Viewer, click File | Terminate Process to terminate the process.

    Note Be certain that the correct process is selected before you click Terminate Process. Terminating the incorrect process may render the device or emulator unusable, requiring it to be reset before you can use it again.

  8. Verify that the process is terminated by selecting Target | Refresh. Scroll to the top pane of Windows CE Remote Process Viewer again. If the application name still appears, the process was not terminated, and you need to repeat these steps.

Note   Most processes terminate in one try; however, depending on the state of the application, terminating a process occasionally takes two attempts.

Appendix B: Setting Up Your Computer

Before you start this HOL, you need to install Internet Information Services (IIS), as described in the HOL Requirements section.

To install Internet Information Services

  1. Click Start | Control Panel | Add or Remove Programs.
  2. On the Add or Remove Programs window, click Add/Remove Windows Components.
  3. In the Windows Components list, select Internet Information Services (IIS) if it is not already complete.
  4. Continue clicking Next until the Windows Components wizard is complete.
  5. Close the Add or Remove Programs window.

Also before you start this HOL, you need to run an application to add the necessary Pocket Outlook contacts and image files to the emulator.

To populate the emulator with test data

  1. Download and install MEDC06_HOL202.msi.

    Note   If you used the Windows Mobile 5.0 Smartphone emulator in a previous HOL, you should do a hard reset on the emulator before starting this HOL. (On the emulator, click File | Reset | Hard.)

    Note   If you receive an error during deployment that indicates that the process or file is in use, this means that the program is still running on the emulator and must be closed before a new copy can be deployed and run. This error may appear any time in the HOL that you deploy to the emulator. See Appendix A in this HOL for instructions about exiting a running application.

  2. If Visual Studio 2005 is not already open, open it by clicking Start | All Programs | Microsoft Visual Studio 2005 | Microsoft Visual Studio 2005.

  3. In Visual Studio 2005, click File | Open | Project/Solution.

  4. In the Open Project dialog box, browse to C:\Program Files\Windows Mobile Developer Samples\HOLs\MEDC06_HOL202\Setup Files\.

  5. Select InitializeLab.sln.

  6. Click the Open button. The InitializeLab solution opens.

  7. In the Configuration Manager, verify that Windows Mobile 5.0 Smartphone Emulator is selected as the targeted device, as shown in Figure 14.

    Figure 14. Emulator selection

  8. Clicking Debug | Start Without Debugging to start the application.

  9. If prompted by the Deploy InitializeLab dialog box, verify that Windows Mobile 5.0 Smartphone Emulator is selected, and then click Deploy.

    Note If the emulator does not appear, look for a Windows taskbar button, and click it to bring the emulator to the foreground. Be aware that the first time the emulator starts, it may take several minutes.

    Note   If you receive an error during deployment that indicates that the process or file is in use, this means that the program is still running on the emulator and must be exited before a new copy can be deployed and run. This error may appear any time in the HOL that you deploy the emulator. See Appendix A in this HOL for instructions about exiting a running application.

  10. When the application appears on the emulator, click the left soft key, which is the grey button located under the word Start, as shown in Figure 15. The application displays a wait cursor and indicates that contacts and then images are being added.

    Figure 15. Initializing the device for the HOL. Click the thumbnail for a larger image.

  11. When the application displays Initialization Complete, click the right soft key, which is the grey button located under the word Exit to close the application.

  12. In Visual Studio, click File | Close Solution.

  13. If Visual Studio prompts you to save, click Yes.

Note   If you close the emulator, be sure to save the emulator state.

This HOL uses code examples to help save time when typing certain code. Therefore, you need to import the provided code examples before you start the HOL.

To import the code examples

  1. In Visual Studio, click Tools | Code Snippets Manager to open the Code Snippets Manager.
  2. On the Code Snippets Manager dialog box, click Import.
  3. In the Code Snippets Directory dialog box, browse to C:\Program Files\Windows Mobile Developer Samples\HOLs\MEDC06_HOL202\Setup Files\.
  4. Select the WindowsMobileDemo.snippet file, and then click Open.
  5. On the Import Code Snippet dialog box, select My Code Snippets, and then click Finish.
  6. Click OK to close the Code Snippets Manager dialog box.

Before starting this HOL, you need to populate the device owner information.

To populate the device owner information

  1. On the emulator, display the Home screen by pressing the Home button.

  2. Press the left soft key under the word Start.

  3. Browse to, and then select the Settings icon by using the emulator's navigational pad and ENTER key.

  4. Choose option 9 More.

  5. Choose option 4 Owner Information.

  6. Type Judy Lew for the value of Name.

  7. Type 603.555.9999 for the value of Telephone Number.

  8. Click the left soft key under the word Done.

  9. Click the left soft key again under the word Done.

  10. Choose the Settings icon by using the emulator's ENTER key.

  11. Choose option 4 Home Screen.

  12. Click the ENTER key to view the Home screen layout options.

  13. Use the direction keys to scroll to Windows Simple, and then click the ENTER key. This setting causes the owner's name to appear on the Home screen, which is not necessary to complete this HOL, but it allows you to see that the State and Notifications Broker uses the owner information.

  14. Click the left soft key under the word Done.

  15. Again, click the left soft key under the word Done.

  16. Press the Home button, and then verify that the owner's name is displayed, as shown in Figure 16.

    Figure 16. The Home screen displays the owner's name. Click the thumbnail for a larger image.