Blue Theme Orange Theme Green Theme Red Theme
 
Discover the top 5 tips for understanding .NET Interop
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
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » VB.NET » Animate with Pocket PC

Animate with Pocket PC

This article discusses programming for a Pocket PC in general. If you are lucky enough to get the Smart Devices Extensions you will finally be able to target devices.

Author Rank :
Page Views : 6704
Downloads : 171
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
PocketPCAnimateCode.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

This article discusses programming for a Pocket PC in general complete with a code sample.

If you are lucky enough to get the Smart Devices Extensions you will finally be able to target devices like Pocket PCs using C# however like all good things there are a few snags.

The first of course is that Microsoft cannot squeeze the entire .NET framework into perhaps a 32mb ROM or even 32MB Ram. Microsoft have made some cutbacks so before jumping in and developing the worlds greatest application on Pocket PC take care and have a think about these considerations.

  1. Just because a class exists on the full .NET framework does not mean it exists on the Compact Framework. This means you need to research your Pocket PC project and ensure that all the classes you need and even the methods you are used to using have been implemented on the Compact Framework.

  2. If one of your favorite classes is not implemented, what do you do? Well its possible that Microsoft has implemented a different Pocket PC class that gives you the functionality you need or maybe they have not included the functionality as it can be achieved with another class.

  3. Remember that a Pocket PC or mobile device, unlike a desktop PC has very limited performance and so any duplication of functionality has to be removed.

  4. Welcome to the Win32 API. If you have used Microsofts embedded Visual Basic tool you may assume that all its functionality is included in the Smart Device Extensions. This is a mistake, a lot of the functionality of embedded visual basic was developed over a few versions of the product and the same thing happens with Smart Device Extensions. Some of the common functionality of a Pocket PC like hiding and displaying the Pocket PC SIP or keyboard are not provided as classes and such you need to call out to Win32 APIs.

  5. Assuming the above, the best book I can recommend for using API calls on Pocket PC is Programming Microsoft Windows CE and you can see this on Amazon at

     
    http://www.amazon.com/exec/obidos/ASIN/0735614431/qid=1019870793/sr=1-1/ref=sr_1_1
    /002-8613147-9333661.

  6. Smart Devices Extension also includes an emulator to enable you to write code for a Pocket PC and run it on your development system. Of course this is an excellent tool but don't be fooled into thinking you can develop and complete a Pocket PC project without actually having a real Pocket PC. Keep in mind that you cannot guarantee that the emulator will show up all problems in your code. With each release of these tools the emulator gets better but you cannot beat the real thing!

  7. As I have just found if you take C# code and try to run it on a Pocket PC project it will probably fail. Perhaps you have used a class that the Pocket PC does not support. Or more annoyingly there are inconsistencies between the Pocket PC classes and the desktop versions. Even something as simple as the Timer class exhibits this problem. On the desktop version of my animate example I use Start and Stop methods to stop and start the timer. On a Pocket PC project you set the Enabled property to true or false to achieve the same thing. An annoying problem but not a major one. However it means you cannot just copy and paste code between desktop and Pocket PC projects.

Finally, you may read the above and think I am negative about coding C# on Pocket PC. This of course is not the case. I can now use the same (more or less) code to write apps on both a desktop and a mobile device. As long as you are aware of the limitations the possibilities are great and once again thanks to Microsoft for producing another great development system on Pocket PC.
Now onto some code!!

This first screenshot shows what happens when you create a new project when you have Smart Device Extensions installed.



As you can see I now have a new Smart Device Application Project type. Once entering the name etc I get a new dialog asking me whether I want to create a Windows CE or a Pocket PC project. Here is the Dialog.



Once you have entered your code and try to run it you will be asked whether you want to run the code in either a Pocket PC device or using the emulator. Because I am lazy and have not unpacked my Pocket PC I will target the emulator as you can see from this screen.



Here is the final code and the project has been included in the attached zip file.

'Pocket PC Animate
'Shows some very basic animation code on the Pocket PC platform
'Written 06/04/2004 by John O'Donnell - csharpconsulting@hotmail.com
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Public Class Form1
Inherits System.Windows.Forms.Form
Public ballarray(20, 20) As Integer
Public
g1 As Integer = 1
Public g2 As Integer = 200
Private timer1 As System.Windows.Forms.Timer
Private menuItem1 As System.Windows.Forms.MenuItem
Private mainMenu1 As System.Windows.Forms.MainMenu
#
Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase
.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.mainMenu1 = New System.Windows.Forms.MainMenu
Me.menuItem1 = New System.Windows.Forms.MenuItem
Me.timer1 = New System.Windows.Forms.Timer
'
'mainMenu1
'
Me.mainMenu1.MenuItems.Add(Me.menuItem1)
'
'menuItem1
'
Me.menuItem1.Text = "Start"
AddHandler menuItem1.Click, AddressOf menuItem1_Click
'
'timer1
'
Me.timer1.Interval = 10
AddHandler timer1.Tick, AddressOf timer1_Tick
'
'Form1
'
Me.Menu = Me.mainMenu1
Me.Text = "Form1"
End Sub
#End Region
Private
Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim i As Integer
For
i = 1 To 13
'add direction vectors to coordinates
ballarray(i, 1) = ballarray(i, 1) + ballarray(i, 3)
ballarray(i, 2) = ballarray(i, 2) + ballarray(i, 4)
'if ball goes of to right
If ballarray(i, 1) + 50 >= ClientSize.Width Then
ballarray(i, 1) = ballarray(i, 1) - ballarray(i, 3)
ballarray(i, 3) = -ballarray(i, 3)
'if ball goes off bottom
Else
If
ballarray(i, 2) + 50 >= ClientSize.Height Then
ballarray(i, 2) = ballarray(i, 2) - ballarray(i, 4)
ballarray(i, 4) = -ballarray(i, 4)
'if ball goes off to left
Else
If
ballarray(i, 1) <= 1 Then
ballarray(i, 1) = ballarray(i, 1) - ballarray(i, 3)
ballarray(i, 3) = -ballarray(i, 3)
'if ball goes over top
Else
If
ballarray(i, 2) <= 1 Then
ballarray(i, 2) = ballarray(i, 2) - ballarray(i, 4)
ballarray(i, 4) = -ballarray(i, 4)
End If
End
If
End
If 'force repaint of window
End If
Next
i
Me.Refresh()
End Sub
Protected
Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim p As New Pen(Color.Blue)
Dim i As Integer
For
i = 1 To 13
e.Graphics.DrawEllipse(p, ballarray(i, 1), ballarray(i, 2), 50, 50)
Next i
End Sub 'OnPaint
Private Sub menuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim r As New Random
'set ball coords and vectors x,y,xv,yv
Dim i As Integer
For
i = 1 To 13
ballarray(i, 1) = +r.Next(10) + 1
'+1 means i lose zero values
ballarray(i, 2) = +r.Next(10) + 1
ballarray(i, 3) = +r.Next(10) + 1
ballarray(i, 4) = +r.Next(10) + 1
Next i
Me.timer1.Enabled = True
End
Sub
End
Class

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
 
John O Donnell
John O’Donnell is a former Microsoft UK employee and is an MCSE. Currently John works in Chicago for MAS Consulting (www.mcas.com) as a Senior Technical Consultant. He is available for C# contract work across the USA .
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:
Team Foundation Server Hosting
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.