There are no comments yet...Kick things off by posting your opinion.
How to start developing for Windows Mobile (part 2)
In part 1 I was writing what we need for development, what are differences and some basic stuff about .NET Compact Framework.
Now let’s take a look at developing our application. As mentioned, we will use Visual Studio 2008 (current release in time of writing) with already installed Windows Mobile SDKs. So, you start with crating new project (File>New Project, choose Smart Device and than Smart Device Project), name it eg. MyWinMobileAppDemo. After clicking OK, you’ll get new window, where you choose for which platform you wish to develop.
This is important step, but you can still change those settings after creation of project (we’ll cover that in part 3). As you can see, we can create a lot of different styles of applications (application, class library, console application, etc.), just like in normal Windows environment. But we’ll focus on creating Device Application.
What you need to consider here is your target platform. That means, if you’re developing application for new and modern phones, choose the latest option (Windows Mobile 6.5 in time of writing). Be careful with choosing between Standard and Professional, while first means non-touch screen devices and the second is for touch screen devices (as described in part 1).
For this tutorial, I’ll choose Windows Mobile 6.0 Standard and .NET CF 3.5. I’m not choosing the latest version, just because I have phone, which is running 6.1 version and I’m planning to deploy the application on my phone.
OK, so now we’re finally in! Now let’s see, what we have in toolbar:
All the basic components are here. There are missing some advanced, like Containers, Dialogs, ErrorProvider, etc, but we have already discussed, why is it like that, so if you will need some kind of advanced functionality, you’ll need to write it by yourself.
Now let’s put on Form one Label with text set to “Hello World!” (yeah, another hello world app here :)). Now we’ll try to deploy it, so let’s focus a little bit on emulators first.
We can access to every installed emulator via Tools>Device Emulator Manager. You can do various things from this tool, but mostly it is useful to check, what kind of emulators you have and which are running.
In case you will need internet in your application, you have to first setup connection in emulator. This is rather complicated step, but hey, something must be a little bit interesting :) So here is the procedure:
- In emulator, go to File>Configure, select tab Network, check Enable NE2000 PCMCIA network adapter and select Connected Network Card
- In device go to Start>Settings>Connections>Proxy>New…, set Description to something (doesn’t matter) and select Connects from: Work and Connect to: The Internet. Left other fields blank and click Done.
- Check if internet is working (eg. open IE and navigate somewhere), if not try to set up proxy server (if you are behind one)
Getting back to Visual Studio, you can view all available devices for you current project on Device toolbar:
That is the setting we set in the beginning on which platform we would like to develop. As we can see, we have 4 options:
- Device – that will connect to your physical device, if it is connected to your PC via ActiveSync (or Windows Mobile Device Center on Windows Vista). It doesn’t matter what kind of connection is (USB, Bluetooth or some more exotic stuff)
- Emulator – this will connect to emulator with screen size 176x220
- Landscape QVGA Emulator – screen size 320x240
- QVGA Emulator – screen size 240x320
The great thing about deploying on device (instead of emulator) is that you can check real life situation, if application really fits and is still usable even on those small devices. Oh, and you can debug directly on device! That’s pretty cool feature, which is overseen a lot of times.
Just to show you the difference between emulators, there is a comparison:
It’s very useful having more than one emulator, just for sake of testing your application on different environments, which will most likely to happen, if you are developing application for end users. You can also create your own emulator image, you can read a how-to here.
Now let’s take a look at our test application. I have set the background for label on yellow and height of label to fit on default (smallest) emulator, just to show you, how it will be shown on different emulators:
Notice how it’s differently shown in other emulators? In the middle one there is even a slider! I’ve done this, just to point out, that we must be careful of “resizing” our application on different devices. This particular problem can be very easily solved, with setting Anchor property of particular Label to Top,Left,Bottom.
On devices full with buttons, like non-touch screen devices normally are, we need to handle button presses. So let’s take a look at that.
In design view of our application (or particular form) we just click on on button and Visual Studio will generate code for event KeyDown of particular Form:
private void Form1_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == System.Windows.Forms.Keys.F1)) { // Soft Key 1 // Not handled when menu is present. } /* .... */ }There are also generated comments for each button, to know which one is what. Let’s quickly summarize that:
| KeyCode | Physical button |
| F1 | Soft key 1 (left) |
| F2 | Soft key 2 (right) |
| Up | Up |
| Down | Down |
| Left | Left |
| Right | Right |
| Enter | Enter (middle button) |
| D0 … D9 | Numbers on phone’s keypad |
| F8 | * |
| F9 | # |
| A-Z | Letters (useful on devices with QWERY keypad) |
Now, we have done quite a lot – but what if we would like to check how our application runs on touch screen devices? And how to programmatically detect running platform? How to combine both (touch and non-touch) worlds in one application? We’ll cover that in part 3.
Drop any comment, if you have any question or suggestion!
author: Aleš Rosina | Comments: 0 | Tags: windows-mobile, visual-studio, developing, series
June
2009
