TamsPPC - the PocketPC Blog

The PocketPC news and opinion source

February 13th, 2008

Code reuse for Pocket PC and Smartphone

I am currently working on “porting” my VB.NET test application from Pocket PC to Windows Mobile Smartphone(two binaries, but one code base) and have found the following links very useful. Treat it as a “collection of resources” for now - a detailed writeup comes in the near future!

Share Source Code Across Platforms (Devices)
This article gives you a broad overview at what’s needed.

Verify Platform Support for Code in Device Projects
A single line can kill your app - this article tells you how to tell the VB compiler to make sure that no “unedible” code is compiled.

Change Platforms in Device Projects
This little writeup tells you how to switch your Visual Studio between the two “platforms”…

If you find any other useful resources, please post them here!

February 9th, 2008

Create Numeric text boxes with .NET CF

Sometimes, UI designs demand text boxen to accept only numeric data(aka no characters) - after all, entering abc as a delay time value most definitely won’t make much sense. While the Palm OS allows developers to create so-called “numeric text fields” that only accept numbers, the .NET CF does not include this feature…

The code below restricts user input to the characters 1234567890 - no decimal points/commas can be entered:

Private Sub TxtX_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtX.KeyPress, TxtY.KeyPress
e.Handled = True
If Char.IsNumber(e.KeyChar.ToString) Then
e.Handled = False
End If
End Sub

Just paste it into the form’s code, and add the names of all numeric text boxen instead of TxtX and TxtY(you can have 1 to n).

Enjoy your numeric text box…

January 14th, 2008

Autorun/autostart applications from a memory card on a Windows Mobile device

Palm OS handhelds have a lovely feature - whenever you insert a memory card, they look for a file called Start.prc and - if they find it - execute it automatically(sort of like the Autostart feature found on CD and DVD media). Windows Mobile devices can do that, too - but it is a bit more difficult.

Autostarting an application on a PocketPC can be accomplished by creating the following file/folder structure on a memory card:
/2577/autorun.exe

The application file must always be called autorun.exe. The 4-number folder name defines the processor architecture(always 2577 for PocketPC) - here are numbers for other processor architectures:

HITACHI_SH3 10003 // Windows CE
HITACHI_SH3E 10004 // Windows CE
HITACHI_SH4 10005 // Windows CE
MOTOROLA_821 821 // Windows CE
SH3 103 // Windows CE
SH4 104 // Windows CE
STRONGARM 2577 // Windows CE - 0xA11
ARM720 1824 // Windows CE - 0x720
ARM820 2080 // Windows CE - 0x820
ARM920 2336 // Windows CE - 0x920
ARM_7TDMI 70001

Files are copied to the /windows/ folder and are then run from there - your Autorun application should thus be able to stand on its own….

Further information here:
http://www.informit.com/guides/content.aspx?g=security&seqNum=91&rl=1

November 19th, 2007

Determine a font’s line height in .NET CF(.NET compact framework)

Determining the line height of a font is very important thing for programmers creating applications that use changing texts as part of their UI. However, Microsoft(for some reason) decided to remove the .Height attribute from the .net CF Font object.

However, the height and width of a text can still be determined - if your code has access to a Graphics object. The object’s MeasureString method returns a SizeF parameter containing the height and the width of the string passed in….the values, of course, are in pixels!

The code example below creates a moving bar that permanently changes its color. In the middle of the bar, the text contained in drawString is displayed in white - this animated GIF simulates the effect:


ElseIf Globals.Globals.TextMode = textmode_enum.series60 Then
Dim drawString As String = TextParser.getDateText
Dim myFont As New Font(System.Drawing.FontFamily.GenericSansSerif, 12, FontStyle.Regular)
Dim myTextBrush As New SolidBrush(Color.White)
Dim myBackBrush As New SolidBrush(Color.FromArgb(Int((254 * Rnd())), Int((254 * Rnd())), Int((254 * Rnd()))))
Dim y As Integer = Int(((MainForm.Height - 4 - gfx.MeasureString(drawString, myFont).Height) * Rnd()))
gfx.FillRectangle(myBackBrush, 0, y, MainForm.Width, 4 + gfx.MeasureString(drawString, myFont).Height)
gfx.DrawString(drawString, myFont, myTextBrush, (MainForm.Width-gfx.MeasureString(drawString, myFont).Width)/2, y + 2)
End If

Enjoy!

P.s. If anyone of you knows how the MS boys format the code that they put onto their blogs so neatly….PLEASE let me know!
P.s.2 If anyone knows WHY Microsoft removed the Font.Height property from .NET CF, please let me know too!

November 16th, 2007

.net CF example code dump

While stumbling across the net in order to find a way to pick fonts in .net CF, I stumbled upon the following site offering a variety of interesting code samples:
http://samples.gotdotnet.com/quickstart/compactframework/doc/default.aspx

While the page’s formatting probably is horrible, the examples found on it could potentially be helpful!

Do you know other pages containing .net CF sample code? If yes, please give us a holler!

November 14th, 2007

A color picker for .NET CF

The lack of a color picker dialog in the .NET CF(yes, the desktop framework has a ColorPicker class - but .NET CF doesn’t contain it) has annoyed hell out of me for quite some time - even the 10yr old Palm OS contains a well-done color picker. Anyways, problems are here to be solved - please allow me to present you my own ColorPicker(running in .NET CF 2.0 on a hp rx4240, blots are due to GIF compression):

Using this is very simple - just download the form file here and integrate it into your project like you would do with any other form.

Then, do the following to make the user pick a color:

Dim colorX as color
colorX = ColorPicker.getcolor()

Feel free to do with this code whatever you feel like. However, no warranties are given on anything….and posting a link to an app that uses it always is appreciated!

June 22nd, 2007

Finding .NET Compact Framework information on MSDN

Microsoft’s MSDN is a very useful resource - if you can find the information you need in plethora of information. Microsoft has documented the .NET compact framework pretty well - but you need to find it. Here’s how to:

Step 1: visit MSDN
Visit the MSDN library at msdn.microsoft.com

Step 2: visit the category
In the TOC on the left, click the following:
.NET Development -> .NET framework Technologies -> .NET Compact Framework

As of this writing, the following link takes me right to the correct category:
http://msdn2.microsoft.com/en-us/library/f44bbwa1.aspx

June 22nd, 2007

Creating a dialog/popup form in .net CF

I am in a pretty bad mood about this…please forgive me the slightly aggressive slant

I am a programmer who takes pride in designing his UI’s himself - and indeed, many of my Palm OS applications have won awards for simple and well-done interfacing. For me, popping up a dialog over another form is a standard issue - it looks like this on a Palm:

The code for doing this is approx 1 line long; and all you need to do is set the form dimensions and popup styles in Resource XML.

Creating such a dialog is next to impossible on the PocketPC in vb.net - for some strange reason, this absolutely operating system insists on making each and every form “full-screen” - even if you set the dimensions differently(even explicitly in code). All this while a MessageBox floats around the screen merrily…

However, I am not alone with this problem. Looking around in the CF newsgroup brought along the following gem of a thread:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.framework.compactframework&tid=57f3a71b-7166-4b7b-98d6-003453f86c7c&p=1

Essentially, it all comes down to setting FormBorderStyle to none. You then have a form that doesn’t get resized automatically and can be popped up with Form.ShowDialog - but it doesn’t have a frame or title area.

Fabien Decret has a writeup on the “gory details” and also covers creating a simple border around the form - visit his blog here:
http://fabdecret.blogspot.com/2007/05/non-full-screen-window.html

How do you create a popup window in .net CF? If you have an idea, please email it to me at Tamog AT gmx DOT at!

May 20th, 2007

Double Buffering for PocketPC

Double Buffering is a common technique to reduce flickering in “simple” 2d animations. Binary Clock for Palm OS uses this technique to deliver smooth graphics. The idea behind double buffering is to draw in an offscreen window and copy the contents of the window into the display buffer en bloc every now and then. This way, the user always sees a stable and completely-drawn image.

This is - of course - also possible on a PocketPC. Microsoft’s MSDN contains an article on double buffering - however, finding it took a bit of time. That’s why I’m sharing this link…

Get the full scoop here:
http://msdn2.microsoft.com/en-us/library/ms172506(VS.80).aspx

The page above doesn’t render well in Firefox 2. The German MSDN page contains exactly the same sample code(with English comments) - without the CSS bug:
http://msdn2.microsoft.com/de-de/library/ms172506(VS.80).aspx

|