Blue Theme Orange Theme Green Theme Red Theme
 
Safari Books Online
Home | Forums | Videos | Photos | Blogs | Beginners
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
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:
Total page views :  5854
Total downloads :  152
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
PocketPCAnimateCode.zip
 
Become a Sponsor

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


Login to add your contents and source code to 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.
SQL and .NET performance profiling in one place
Investigate SQL and .NET code side-by-side with ANTS Performance Profiler 6, so you can see which is causing the problem without switching tools.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
60 FREE UI Controls from DevExpress
Register for your FREE copy on over 60 free presentation controls from DevExpress - Absolutely Free-of-Charge without any royalties or distribution costs. Visit Devexpress.com/60 today. Free controls include advanced lists box, dropdown calendar, rich text edit, spin edit, tab control and so much more!

DevExpress engineers feature rich presentation controls and reporting tools for WinForms, ASP.NET, WPF, and Silverlight. Our technologies help you build your best, see complex software with greater clarity and deliver compelling business solutions for Windows and the web in the shortest possible time.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Visualize your workspace with new multiple monitor support, powerful Web development, new SharePoint support with tons of templates and Web parts, and more accurate targeting of any version of the .NET Framework. Get set to unleash your creativity.
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.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Become a Sponsor
 Comments
ASP.Net 4 Hosting is here
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2010.8.14
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.