Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
Complete the form below to send this article, Development of Windows Mobile Applications (Part 2), to a friend (or to yourself). We will never share your details (or your friend's) with anyone. For more information, read our Privacy Policy.
Read Part One of Development of Windows Mobile Applications here.
Now let us see how to deploy it on Windows Mobile Device. For deploying the application on device you need to have ActiveSync installed.
There are two ways in which application can be deployed on to the device. First option is to connect the device to the Development machine via USB. ActiveSync will automatically detect it and you can click on
on the top bar. And this time select option "Windows Mobile 6 Professional Device".

But then this approach is useful when you want to test/deploy and use the application yourself. What if you want to distribute it to others? In that case you need to create an installation program for your Windows mobile application. The installation file in the Windows Mobile world is distributed in the form of a CAB file. So once we have done with application we should opt for option 2 of creating a CAB file (A CAB file is a library of compressed files stored as a single file).
Creating CAB File
Creating a CAB file itself is a new project. To create CAB project right click on the solution and select the option New Project as shown below.

Clicking on New Project option will open Add New Project Wizard. Select option Setup and Deployment under Other Project Types on the left hand menu. Then select option Smart Device CAB Project on right hand side as shown below. We have named this project as MyFirstAppCAB.

Click OK and MyFirstAppCAB project is created under the solution a shown.

Now to add files to the CAB, right click on the Application Folder under File System on Target Machine and select option Add-> Project Output as shown.

On selecting Project Output option, the following screen will popup. Depending upon the requirement, select what all needs to be compressed in CAB file. For this example we require only output, hence will select option Primary output.

Now right click on CAB project MyFirstAppCAB and select option Build.

CAB file with name MyFirstAppCAB will be created at the location MyFirstAppMyFirstAppCABDebug.
Now let us see how we can deploy this CAB file on emulator and run the application. Click on Tools on the top bar and select option Device Emulator Manager.

This will open a Device Emulator Manager as shown below. Select option Windows Mobile 6 Classic Emulator. Right click and select option Connect.

Windows Mobile Emulator will start and on Device Emulator Manager you can see
to left of Windows Mobile 6 Classic Emulator as shown below.

Next step is to Cradle.
If you are attempting to cradle for the 1st time, then you need to setup ActiveSync. To setup ActiveSync, double click on
on right bottom on Task bar. Microsoft ActiveSync will open up, select option File -> Connection Settings as shown in figure below.

Connection Settings window will be open up as shown below. Check the option Allow Connections to one of the followings and then from the drop down select the option DMA.

After connecting Windows Mobile 6 Classic Emulator using Device Emulator Manager, again right click and select option Cradle as shown below. Cradle will start ActiveSync and make Emulator work as device connected using ActiveSync.

On successful connection you can see
on the left of option Windows Mobile 6 Classic Emulator on Device Emulator Manager as shown.

Open Microsoft ActiveSync and click on Explore.

This will open Mobile Device. Select My Windows Mobile-Based Device->Program Files and copy CAB file. On the Emulator, click on Start->Programs->File Explorer as shown below.

On File Explorer, if the View is My Documents then click on arrow next to it and select My Device option as shown below.

Program Files is the folder in which we had copied the CAB file so browse through Program Files and click on MyFirstAppCAB.

Successful installation of CAB file will create folder MyFirstAppCAB. Browse through the folder and click MyFirstApp to execute our Hello World Application.

After Hello World let us quickly try and develop another application which will fetch and display Quotes of the Day from internet via RSS feed on button click. We will fetch RSS feed from http://feeds.feedburner.com/brainyquote/QUOTEBR.
Create a new Project and let us name it as QuotesOfTheDay. Name the form as QuotesOfTheDayForm and set Caption as Quotes Of The Day. From Toolbox drag and drop a button on the form, name the button as btnShowQuotes and set label on the button as Show Quotes. Similarly add one more button, name it as btnClear and set label on the button as Clear.
Click on Show Quotes, will invoke http://feeds.feedburner.com/brainyquote/QUOTEBR and fetch the RSS feed, process it.
To show the list of Quotes for the day we will use TextBox. So drag and drop TextBox from ToolBox. Name TextBox as tbQuotes. By default TextBox allows single line to be entered or displayed. Here we can get multiple Quotes, so set Multiline property as True. Beside TextBox is editable by default, so make it read only by making ReadOnly property as True as shown below.

Similarly click on Clear, will clear the TextBox.
Let us look at the complete source code. And understand how we invoke RSS feed, process the response and display it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Xml;
namespace QuotesOfTheDay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnShowQuotes_Click(object sender, EventArgs e)
{
// URL of RSS Feed for Quotes of the Day
String urlStr = "http://feeds.feedburner.com/brainyquote/QUOTEBR";
try
{
// Set Cursor to Wait Cursor
Cursor.Current = Cursors.WaitCursor;
// Create HttpWebRequest to invoke RSS feed URL.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlStr);
// Get response for the request.
HttpWebResponse responese = (HttpWebResponse)request.GetResponse();
// Check response.
if (responese.StatusCode.ToString().Equals("OK"))
{
// Get Response Stream and convert it StreamReader.
StreamReader responseStream = new StreamReader(responese.GetResponseStream());
// Read entire content from StreamReader
String responesStr = responseStream.ReadToEnd();
// RSS feed returned represents an XML. To extract data from RSS feed, create
XMLDocumnet and Load the XML with the response.
XmlDocument rssFeedXML = new XmlDocument();
rssFeedXML.LoadXml(responesStr);
StringBuilder _quotes = new StringBuilder();
int lineNumber = 1;
// Iterate through all "item" nodes of the RSS feed XML.
foreach (XmlNode item in rssFeedXML.DocumentElement.SelectNodes("channel/item"))
{
// Extract title.
String title = item.SelectSingleNode("title").InnerText;
// Extract description.
String description = item.SelectSingleNode("description").InnerText;
// Format and Append Count and title and description.
_quotes.Append(lineNumber + ". " + title + ": " + description + "rn");
// Increment lineNumber by 1
lineNumber++;
}
// Set Cursor to Default Cursor
Cursor.Current = Cursors.Default;
// Assign content of _quotes StringBuilder to TextBox tbQuotes.
tbQuotes.Text = _quotes.ToString();
}
else
{
// Set Cursor to Default Cursor
Cursor.Current = Cursors.Default;
MessageBox.Show("Response Status Code: " + responese.StatusCode
+ " Description: " + responese.StatusDescription);
}
// Close HttpWebResponse
responese.Close();
}
catch (Exception exception)
{
// Set Cursor to Default Cursor
Cursor.Current = Cursors.Default;
MessageBox.Show("Error while accessing " + urlStr);
}
}
private void btnClear_Click(object sender, EventArgs e)
{
// To clear TextBox we will assign and empty string.
tbQuotes.Text = "";
}
}
}
The entire code of invoking, processing and displaying quotes is in the method btnShowQuotes_Click.
Key Steps:
- Create HttpWebRequest for the URL.
- Get Response, for the request.
- Check whether response is OK. This indicate that response to the request made to the server was ok and server was able to respond to it.
- If response is OK, then read the response string in this case XML string from the response stream.
- Now Process the response. Since we know it is an XML so we will convert the response string into XML Document.
- Iterate through the child node item. Fetch title and description. Format and append it using StringBuilder. Assign content in StringBuilder to TextBox.
Now deploy and run to see the output as below.
Depending upon the way form is designed, output may vary.

Click on Show Quotes to fetch quote of the day. Ensure Internet Connection available.

Click on Clear to clear TextBox.
With this, we conclude our article of taking your first steps in Windows Mobile development.
Summary
Thus we saw the entire development cycle (code, test, deploy) of Windows Mobile applications. This article covered two applications, "Hello World" which helped us to understand basics of Windows Mobile 6.0 Development, while "Quotes of the Day" was a step ahead, where we learnt fetching and displaying data from the Internet. This article should serve as a launch pad for your Windows Mobile Application development journey.
If you have read this article you may be interested to view :
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
|
|



Post new comment