Development of Windows Mobile Applications (Part 1)

Exclusive offer: get 50% off this eBook here
FreePBX 2.5 Powerful Telephony Solutions

FreePBX 2.5 Powerful Telephony Solutions — Save 50%

Configure, deploy, and maintain an enterprise-class VoIP PBX

£14.99    £7.50
by Prashant Thakkar | September 2009 | .NET Microsoft

A Windows Mobile is a Smart Phone with Windows Operating System. Windows OS in Windows Mobiles is the Compact Edition (CE) of the desktop Windows OS. This article will introduce you to writing Windows Mobile Applications using Visual C# and Microsoft Visual Studio 2008. This article by Prashant Thakkar will address:

  • Essential features of Microsoft Visual Studio 2008 IDE that help in writing Windows Mobile Application.
  • Writing your first Windows Mobile "Hello World" application and a "Quote of the Day" Application that uses Internet
  • Packaging, Deploying and running your Windows Mobile Applications

Windows OS for Windows Mobile is available in various versions, but for this article we will be using Windows Mobile 6. Windows Mobile 6 uses .NET Compact Framework v2 SP2, and has 3 different versions:

  • Windows Mobile 6 Standard (phones without Touch Screen)
  • Windows Mobile 6 Professional (with Phone functionality)
  • Windows Mobile 6 Classic (without Phone functionality)

Windows Mobile 6.1 and Windows Mobile 6.5 are other 2 higher versions available with some additional features as compared to Windows Mobile 6. Windows Mobile 7 expected to be released in 2010 and is said to have major updates.

This article concentrates on development on Windows Mobile 6 Professional.

Software Prerequisite

This article will introduce you to the development for Windows Mobile 6 Professional, using Visual C#. Windows Mobile 6 has .NET Compact Framework v2 SP2 preinstalled. .NET Compact Framework is a Compact Edition of .NET Framework, and does not have all the features of the complete .NET Framework.

Following are the software required for development:

  1. Microsoft Visual Studio 2008
  2. Windows Mobile 6 Professional SDK Refresh (SDK contains emulator, used for testing, debugging. To download click here)
  3. ActiveSync (Used for Data Synchronizing between development machine and Windows Mobile, To download click here)

Without making any exception, we will follow the golden rule of learning by writing “Hello World” application.

Hello World

We will assume that you have installed all the prerequisite software mentioned above.

Launch Visual Studio 2008 and select Visual C# (if prompted). Create a new Project (File -> New) as shown below:

FreePBX 2.5 Powerful Telephony Solutions

While creating a new Project, Visual Studio 2008 IDE provides an option to select an installed template, which will create Project with all the basic requirements/structure for development. For Windows Mobile, we will select option Smart Device and template Smart Device Project as shown below.  You can also provide:

  • Name: Name for Project. We will call it as MyFirstApp.
  • Location: Location where this project will be created. Browse and set the desired location. We will use default location for now.
  • Solution Name: Name for referring the Solution. Usually we keep it same as Project Name.

Since Windows Mobile 6 has .NET Compact Framework v2, it will select the .NET Framework 2.0 from the dropdown on the top right. Click OK.

FreePBX 2.5 Powerful Telephony Solutions

Next step is to select the Target platform, .NET Compact Framework Version and Template. For our application we will select:

  • Target platform: Windows Mobile 6 Professional SDK
  • .NET Compact Framework Version: .NET Compact Framework Version 2.0.
  • Template: Device Application

FreePBX 2.5 Powerful Telephony Solutions

Project MyFirstApp is successfully created and IDE will open a Form as shown.

FreePBX 2.5 Powerful Telephony Solutions

Let me introduce you to the various sections on screen.

  1. This is the main section called development section. All the coding and designing of the Form is done here.
  2. This section is called Toolbox and lists all the available components. If this section is not visible click View->Toolbox.
  3. This section is called Solution Explorer and shows all the forms, resources and properties. If this section is not visible click View->Solution Explorer.
  4. This section is Properties and displays all the properties for the component selected. If this section is not visible click View->Properties Window.

FreePBX 2.5 Powerful Telephony Solutions

By default Form is named as Form1. Let us first change the Name of the form. To do so select the form and the properties related to form will be listed in properties window.

FreePBX 2.5 Powerful Telephony Solutions

The entire properties list is in the form of Key Value pair. For changing Name of form, change value of property Name. For this example we will change it to HelloWorldForm. Now this form will be referred as HelloWorldForm throughout the application.

Changing form name doesn’t change form caption (title) it is still showing Form1. To change caption change the value of property name Text. For this example we will change the Text to Hello World.

FreePBX 2.5 Powerful Telephony Solutions

Also the file representing this form in Solution Explorer will still be referred as Form1.cs, again you can either keep the name of the file as it is or can rename it. We will rename it to HelloWorld.cs.

FreePBX 2.5 Powerful Telephony Solutions

FreePBX 2.5 Powerful Telephony Solutions Configure, deploy, and maintain an enterprise-class VoIP PBX
Published: August 2009
eBook Price: £14.99
Book Price: £24.99
See more
Select your format and quantity:

Looking at the top of development section you will find HelloWorld.cs [Design], this represents design of the form. In order to write a code, you need to have a class representation of the designed form. To switch to class representation, right click on development section and select option View Code to view code written for the Form.

FreePBX 2.5 Powerful Telephony Solutions

View Code will open a Source Code editor HelloWorld.cs as shown below.

FreePBX 2.5 Powerful Telephony Solutions

To toggle back to design either you can select HelloWorld.cs [Design] from the tab above or again right click and select option View Designer.

FreePBX 2.5 Powerful Telephony Solutions

In Source Code editor mode no properties of form are available; also no components are shown in the Toolbox.

Now we will toggle back to designer.

FreePBX 2.5 Powerful Telephony Solutions

Now after getting familiar with IDE let us quickly move to our next step. We will now place a button on the form and on the click of that button will display a message. To place button on form, select Button from Toolbox and drag it on to the form.

FreePBX 2.5 Powerful Telephony Solutions

By default button will be referred as button1, we can either change it or leave it as it is. For now we will change it and will provide a meaningful name btnShowMessage for reference.

FreePBX 2.5 Powerful Telephony Solutions

Now this button will be referred as btnShowMessage. But label on button is still referred as button1. And you are right, to change label on the button change the value of the property Text.

FreePBX 2.5 Powerful Telephony Solutions

For showing message on button click we need to register a click event on button. To register click event, double click on the button. Double clicking on button will automatically register click event on the button and will create an abstract method to handle the same. Also view will change from designer to code.

FreePBX 2.5 Powerful Telephony Solutions

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyFirstApp
{
public partial class HelloWorldForm : Form
{
public HelloWorldForm()
{
InitializeComponent();
}

private void btnShowMessage_Click(object sender, EventArgs e)
{

}

}
}

As seen system creates a method btnShowMessage_Click with 2 parameters , one of type object and another one of type EventArgs.

We saw the method that is been created by system for handling the click event, now let us see how and where this method is register for handling click Event. Click FreePBX 2.5 Powerful Telephony Solutions on the Properties window.

FreePBX 2.5 Powerful Telephony Solutions

As seen method btnShowMessage_Click is registered for Click event on button. Apart from Click, button has various other events as shown above.

Method btnShowMessage_Click was auto generated and registered by double clicking the button in designer view.  One can even write a method directly using Source Code editor, but need to make sure to  have 2 parameters, object and EventArgs  in method signature and should return void.

For example we will create a method as follows:

private void showMessage(object sender, EventArgs e)
{

}

FreePBX 2.5 Powerful Telephony Solutions

To register newly created method showMessage on click Event. Click FreePBX 2.5 Powerful Telephony Solutions on Properties windows and then click on the right of the Event for which you want to register this method. A dropdown of all the methods with signature as explained above will be listed. Select appropriate method.

Now let us come back to our application, we have done will most of it now just need to add the code to show message.

We will display message using MessageBox, which will popup on button click. For this we need to add following line to the method btnShowMessage_Click.

MessageBox.Show("Hello World");

After adding the above line to the method, entire source code looks as follows:

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyFirstApp
{
public partial class HelloWorldForm : Form
{
public HelloWorldForm()
{
InitializeComponent();
}
private void btnShowMessage_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World");
}

}
}

Now we have done with basic coding, So next step is to compile and run this code.

We will run this code in Debug mode. To execute click FreePBX 2.5 Powerful Telephony Solutions at the top bar. A popup as shown below will come up asking where to deploy. For now select option "Windows Mobile 6 Classic Emulator" and click Deploy.

FreePBX 2.5 Powerful Telephony Solutions

Windows Mobile Emulator will come up with the default screen as shown in Figure 1. After successful deployment, we can see our HelloWorld Form as shown in Figure 2.

FreePBX 2.5 Powerful Telephony Solutions

Now click on ShowMessage button and we can see the message that we have written on the popup as shown below.

FreePBX 2.5 Powerful Telephony Solutions

Click ok on the top right corner of the MessageBox to close it.

So far we have covered the following:

  • How to Create Project using Visual Studio 2008 for Windows Mobile 6.
  • Developing Hello World application.
  • Running the application on Emulator.

Now let us see how to deploy it on Windows Mobile Device. For deploying the application on device you need to have ActiveSync installed.

>> Continue Reading: Development of Windows Mobile Applications (Part 2)


If you have read this article you may be interested to view :

FreePBX 2.5 Powerful Telephony Solutions Configure, deploy, and maintain an enterprise-class VoIP PBX
Published: August 2009
eBook Price: £14.99
Book Price: £24.99
See more
Select your format and quantity:

About the Author :


Prashant Thakkar is Currently working as Senior Software Engineer at Xoriant Solution, Mumbai. He has over five years of experience of working on Java and Window Mobile Development. He can be contacted by email at prashant.thakkar@xoriant.com. Prashant is also active on Twitter, you can follow him at "ppandhi".

Books From Packt


Funambol Mobile Open Source
Funambol Mobile Open Source

Beginning OpenVPN 2.0.9
Beginning OpenVPN 2.0.9

Entity Framework Tutorial
Entity Framework Tutorial

ASP.NET Data Presentation Controls Essentials
ASP.NET Data Presentation Controls Essentials

Microsoft Dynamics AX 2009 Development Cookbook
Microsoft Dynamics AX 2009 Development Cookbook

Microsoft Dynamics AX 2009 Programming: Getting Started
Microsoft Dynamics AX 2009 Programming: Getting Started

Spring Persistence with Hibernate
Spring Persistence with Hibernate

Blender 3D 2.49 Incredible Machines
Blender 3D 2.49 Incredible Machines


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software