Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Mindcracker MVP Summit 2012
Search :       Advanced Search »
Home » VB.NET » Considerations in Porting and Deploying a WinForms GDI+ Game to the Pocket PC

Considerations in Porting and Deploying a WinForms GDI+ Game to the Pocket PC

This article describes some of the issues I came across when porting a Windows Form Game to the Pocket PC. It also describes how to deploy a Windows Mobile Application from Visual Studio 5.

Author Rank :
Page Views : 8935
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 



Figure 1 - PocketPC game running on the Windows Mobile Emulator

Introduction

The next big frontier is around the corner. That's right, it's the Pocket PC. Mobile phones, PDA's, they are all merging into one small powerhouse called the Pocket PC. And these little babies ARE powerful. A single Pocket PC has the power that the desktop had only a few years ago. And now with storage cards as high as 4 GB and increasing every day, the Pocket PC will only be limited by the dexterity of your fingers and the life of the battery. Also with the Pocket PC you can be connected and mobile, a huge advantage over the bulky and heavy laptop. 

Although there are currently just two main flavors of pocket mobile operating systems out there (Palm OS and Microsoft), it has never been easier to develop mobile applications because windows mobile applications can be programmed in .NET. Not only does a stepped down form of the Windows.NET framework run on most Pocket PC's, but the .netcf (.NET compact framework) runtime is actually built into the ROM (Read Only Memory) of most new Pocket PC's. All Pocket PC running Windows Mobile 5 and some of the later Pocket PC 2003 OS's already have a runtime on board. All you need is Visual Studio and away you go, programming in .NET.

The only drawback is that the .NET compact framework excludes  a lot of the .NET functionality you are currently used to in order to keep the necessary files small. Also problematic is that Microsoft's new .NET framework 2.0 must currently be installed in RAM on most devices since only the 1.0 version is built into ROM. But fear not. There is an open source movement for the .NET compact framework called OpenNETCF. This organization of generous developers has created a library to address the functionality gaps in both the 1.0 and 2.0 .NET framework.

Getting Started

If you want to develop .NET applications for Windows Mobile 5.0, it is not enough to just have the Visual Studio 2005 environment installed on your development computer. You need to download the Windows Mobile 5.0 SDK Extension for Visual Studio. This extension will allow you to develop both .NET 1.1 and .NET 2.0 Compact Framework applications under the Visual Studio 2005 environment. You can also extend Visual Studio to develop for Windows Mobile 5.0 SmartPhone Applications.

Conversion Whoas

I recently took on the challenge of converting my Space Invaders Window Form application to .NET for the Pocket PC. Having discussed this with other Pocket PC developers at Tech Ed, I determined that this is not recommended. I felt that the Space Invaders application was generic enough to be moved to another platform. But I quickly found quickly that many classes that compiled very well under .NET for XP, did not necessarily compile at all under the .NET compact framework. Sometimes namespaces didn't exist, sometimes classes in namespaces didn't exist, and sometimes properties in classes didn't exist. It was as if someone took the .NET framework and fired buckshot through it. What was left when the smoke cleared was the .NET compact framework. Take for example the windows timer object (or equivalent in the .NET framework). In order to start the timer, you just call the Start method, right?  Wrong!  You enable the timer. Your next guess is that to stop the timer you need to disable it, right? Yes...thank goodness for simple logic. 

Double Buffering

When I finally managed to convert the whole app, I noticed that the screen was flashing a lot. Clearly double buffering was not working, so how could I double buffer my Pocket PC application? Simple. You perform all your drawing to an in-memory bitmap and then blast the bitmap to the screen.

Listing 1 - Double Buffering an Image on the Pocket PC

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    CreateMemoryBitmap()

    Dim g As Graphics = Graphics.FromImage(m_bmp)

    g.DrawImage(BackgroundImage, ClientRectangle, _backgroundBounds, GraphicsUnit.Pixel)

    Dim i As Integer = 0

    While i < kNumberOfShields

        Shields(i).Draw(g)

        System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)

    End While
    ....

 

    'now blast the whole bitmap to the screen

    e.Graphics.DrawImage(m_bmp, 0, 0)

End Sub

 

Private Sub CreateMemoryBitmap()

    'Only create if don't have one and the size hasn't changed

    If m_bmp Is Nothing OrElse Not (m_bmp.Width = Me.Width) OrElse Not (m_bmp.Height = Me.Height) Then

        m_bmp = New Bitmap(Me.Width, Me.Height)

    End If

End Sub

Closing the Application

Normally, to close or exit the application, you simply call Application.Exit. In the Pocket PC it is recommended that you remove the minimize box so a little OK button shows up in the corner. The problem with not turning off the minimize box is that the program will still sit in memory after you hit the x. To close a form, just call Close. If the form is a dialog, the Close method will close the dialog (modal or not). If the form is the main form, the Close method will close the application. Listing 2 shows you how to turn off the minimize box on the form.

Listing 2 - Removing the Minimize Box so an OK Button shows up in your Form

Public Sub New()

    MinimizeBox = False 'causes the little ok button to show up in the right hand corner instead of the minimize button

End Sub 

Debugging the Application

Visual Studio allows you to debug an application like you would any other .NET application using the built in debugger. An application can either be debugged directly on the Mobile Device through ActiveSync or through an emulator on your PC. The emulator completely simulates the device on your pc with an image of the device but gives you the convenience of not having to work with the Pocket PC device itself. In other words, you don't even need to own a Pocket PC to develop applications for it. In both cases, you may notice that running the debugger for the Pocket PC takes a bit longer to load than it would for a regular .NET windows application, but it's still the best environment you could use to develop and debug a Pocket PC application. Also you can use a trick to speed up your debugging sessions (as someone at Tech-Ed kindly pointed out to me). In Visual Studio 2005 you can save the last state of the emulator so you don't have to keep reloading the entire emulator each time you debug

Deploying your Application

Pocket PC Applications for .NET are deployed through a CAB file. A cab file is a compressed file similar to a zip file. Visual Studio 2005 gives you the ability to create a CAB file for smart devices. Simply go to New -> Projects in the file menu and choose the Smart Device CAB Project under Setup and Deployment as shown in figure 2. This will create a new project whose sole purpose is to create a deployment CAB package for your .NET application.



Figure 2 - Creating a Deployment project for the Pocket PC.

Once you've created the deployment project, you can use the File System View in Visual Studio to add files and short cuts for your deployment to the Pocket PC. To bring up the File System View, right click on your project and choose View --> File System as shown in figure 3. Note that you can also add Registry entries for deployment through the View menu if your application requires it.



Figure 3 - Viewing the File System for deploying applications

Once in the File System View you can add the files you want to deploy for your application. Simply go to the Application Folder, right click on the right pane, and choose Add-->File.



Figure 4 - Adding files for deployment

Like XP, the Pocket PC has special folders into which you can deploy your application. We found that the iPAQ keeps all its games inside the Programs Folder under a Games Subfolder. To add a special folder to your deployment, simply right click on the File System Icon in the left pane and choose the folder you want to deploy your application to as shown in figure 5. Then right click inside the programs folder and create a new folder called Games. You may notice that in figure 5 there is a Games files folder, but installing the shortcut into this folder doesn't seem to work for the iPAQ we tested.



Figure 5 - Adding the Program Folder for the Space Invader Game Shortcut

Click inside the Games folder inside the left pane of the File View. Then create a shortcut inside the File System view by right clicking on the right pane and choosing Create New Shortcut menu item as shown in Figure 6. When you deploy your application, this shortcut will show up inside your Games folder.



Figure 6 - Creating a Shortcut for the Invaders Game in the Games Folder

Signing your Application with a Certificate

An unfortunate feature of the new Pocket PC apps that you develop is that you will be prompted for a certificate. The certificate needs to come from a trusted certificate company. This means you need to shell out money for a certificate in order to ensure that your application is safe to run on other applications. You can deploy your application without a certificate, but when you try to install it on the Pocket PC, you get a nasty message that says:

The program is from an unknown publisher. You should install it only if you trust its publisher. Do you want to continue?

Name: ...rsDeployDEMO.cab
Publisher:  Unknown
Location: \My Documents\test

So if you want to start publishing for the Pocket PC industry, you may want to consider ponying out the $300 or so it takes to get a certification for your application. You can use companies such as Verisign, GeoTrust, or Thawte. Once you have a real certificate, you can sign your application with it using Visual Studio. Simply right click on the project and choose Properties. Then go to the Devices tab as shown in Figure 7.



Figure 7  - Choosing a Certificate for Authentication Signing

Click on the Select Certificate button and the Certificate Chooser dialog will appear. Click Manage Certificates as shown in figure 8 if you don't already have a certificate available:



Figure 8 - Selecting a Certificate

Clicking Manage Certificates brings up the Manage Certificates dialog shown in Figure 9. Here you can choose the type of certificate you want to import. You must first purchase a certificate from one of the licensed certificate companies listed in order to import the certificate with extension .cer or .crt.  Microsoft Visual Studio will convert this to a pfx file.



Figure 9 - Importing a Trusted Publisher Certificate

Note:  Some companies, such as GEOTrust, will allow you to upload your CAB file to a portal and sign your application for you.  This way they can track the number of signings.

Conclusion

If you are a .NET programmer on the Windows platform, you may find some initial challenges in suddenly developing for the Pocket PC. There will be missing functionality and you'll need to come up with some work-arounds to make your application function. Nonetheless, you should find Pocket PC application development rewarding. As memory limitations and storage space become less of an issue on Pocket PCs, the development environment in .NET will become richer.

Pocket PC's are really a new world and developing for them is a new challenge. There is no better time to start creating Pocket PC applications and probably no better tool for developing these applications than the .NET environment. We encourage you to try developing a few simple Compact .NET applications and playing with them on your compact device or on the emulator. You may think of some portable applications that help you and others in your day-to-day activities. Everyone is going mobile, so hop on the ride for the next big programming opportunity using .NET! 

NOTE: THIS ARTICLE IS CONVERTED FROM C# TO VB.NET USING A CONVERSION TOOL. ORIGINAL ARTICLE CAN BE FOUND ON C# CORNER (http://www.c-sharpcorner.com/).

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mike Gold

Michael Gold is President of Microgold Software Inc., makers of the WithClass UML Tool. His company is a Microsoft VBA Partner and Borland Partner. Mike is a Microsoft MVP and founding member of C# Corner. He has a BSEE and MEng EE from Cornell University and has consulted for Chase Manhattan Bank, JP Morgan, Merrill Lynch, and Charles Schwab. Currently he is a senior developer at Finisar Corp. He has been involved in several .NET book projects, and is currently working on a book for using .NET with embedded systems.

He can be reached at mike@c-sharpcorner.com

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Comments
question by emeka On August 28, 2010
please how do i develop who wants to be a millionaire game
Reply | Email | Modify 
Re: question by Mike On August 30, 2010
you might want to post this in the forum. and  you might want to narrow down your question to something someone can answer in a few minutes.  My initial thoughts are, design a database architecture to support the questions and answers of the game.  create classes and behavior that will support the game logic for going through questions.  Not sure how you would do a lifeline, perhaps a 24 hour internet site?  You could simulate polling the audience.
Reply | Email | Modify 
BV.net by lordman On March 4, 2011
how is that.......
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.