Detect High Resolution Display


You have to use larger images for VGA or WVGA, or scale your UserControl, and you don't know where is your code running?

For dealing with high DPI (Dots Per Inch) VGA devices, we used to detect the high resolution this way:

private float DetectResolution1()
{
float scaleFactor = 1.0f;

using (Graphics gr = this.CreateGraphics())
{
scaleFactor = (gr.DpiX == 192.0f) ? 2.0f : 1.0f;
}

return scaleFactor;
}

But never use this code if you want to save CPU time.

Ten times faster way is here:

private float DetectResolution2()
{
return this.CurrentAutoScaleDimensions.Height / 96.0F;
}

My code is available here: http://winmobile.euweb.cz/#Post14

If you are developing your custom control, I advise you to read more about UserControl.ScaleControl(..) method, which is called often by the system, so take care with method.

protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
{
m_ScaleFactor = factor;

base.ScaleControl(factor, specified);
}

Smart Device Development Forums



A great Forum to ask your questions around Windows Mobile Development:

http://social.msdn.microsoft.com/Forums/en-US/category/smartdevicedevelopment


T9 again


I wrote about T9 implementation on last year:
http://winmobiledeveloper.blogspot.com/2008/06/how-can-i-add-t9-to-textbox.html

And I found a little different way to enable T9 on your textbox.
There are more special feature, e.g. you can associate PIM Contacts with the TextBox.

Here is blog post from Christopher Fairbairn with sample code:
Making auto suggestions more appropriate for your textbox

Form.Owner


If you simply use ShowDialog to display another form:
a) The new form (specifically its caption/text) appears in the "running programs list"
b) The original form also appears in the list, which means you can navigate to it (although it appears disabled once activated)
c) There is potential for closing the second form and returning to another window on the PPC (the original form has moved back in the z-order)

With CF 2.0 you can use the Owner property of the Form and hence get rid of every problem from the above list. Do not confuse the Owner property with the Parent property, which is inherited from Control and is not intended to be used with forms

Run the following snippet:

using (Form2 form2 = new Form2())
{
form2.Owner = this;
form2.ShowDialog();
}

...you'll notice that only one entry for your application exists in the running list. The only potentially strange thing is that it has the caption of the first form (while the body of the form is clearly that of Form2)! This is easily rectified with the following modification:

using (Form2 form2 = new Form2())
{
form2.Owner = this;

string title = this.Text; //make a copy of the original caption
this.Text = form2.Text; //set our caption to the form

form2.ShowDialog();

this.Text = title; //restore the original caption
}

Sample Project:
http://winmobile.euweb.cz/#Post12

Drawing is slower in Landscape mode


I found a strange drawing on Windows Mobile. If you draw a Bitmap it takes:
- 3 ms in Portrait mode and
- 65 ms in Landscape mode.
(Tested on VGA emulator)

Method:
e.Graphics.DrawImage(m_Bmp, 0, 0);

It seems the Landscape drawing is emulated only, and the bitmap rotation takes so many time.

It can make problems when you want to animate, or e.g. when you have double buffering and you need repaint some areas on mouse move event.

If you know a faster way of drawing Bitmap, feel free to comment this post.

You can try out my sample here:
http://winmobile.euweb.cz/#Post11

Update:
On QVGA device:
- Portrait: 2 ms (average)
- Landscape: 6 ms (average)
On VGA device:
- Portrait: 6 ms (average)
- Landscape: 47 ms (average)

Speed Up Your Windows Mobile Builds

I found this useful trick on Nick Randolph's blog:

"One of the things that continually frustrates me about building Windows Mobile applications in Visual Studio is that for some reason it takes so long to do a build. Behind the scenes there is a lot that goes on and I always forget that there is one part of the build that you can mostly do without, the platform verification. As pointed out by the now quite old post by the Visual Studio for Devices team you can disable this part of the build quite easily:

1) Open the file %windir%\Microsoft.NET\Framework\v2.0.50727\Microsoft.CompactFramework.Common.Targets for editing.

2) Go to the line which reads:
Name="PlatformVerificationTask">
and change it to:
Name="PlatformVerificationTask" Condition="'$(SkipPlatformVerification)' != 'true'">

3) Add the SkipPlatformVerification environment variable to the system and set it to "true" (To re-enable Platform Verification set the environment variable to "false")

4) Restart Visual Studio for the changes to take effect (If building from the command line using MSBuild, add /p:SkipPlatformVerification=true to your command line to turn off the task. You can specify the variable in the project file also, so that this information is persisted across sessions).

As noted by Thomas you may just want to disable this functionality, instead of having it contingent on an environment variable. In this case just change the PlatformVerificationTask line to:

Name="PlatformVerificationTask" Condition="false">

Doing this you should notice that your mobile projects build just as fast as other projects within Visual Studio. Note: This is still relevant in Visual Studio 2008 with SP1."

I tried it out, and it really decreased the time for building my projects.

Source:
http://community.softteq.com/blogs/nick/archive/2009/07/22/speed-up-your-windows-mobile-builds.aspx

Freeware obfuscator for .NET CF and .NET



Eazfuscator.NET
is a free obfuscator for both .Net Framework and .Net Compact Framework with a simple and nice GUI.

The main purpose of obfuscator is to protect intellectual property of the software.

If you have a good experience with another obfuscator for windows mobile applications, feel free to comment this post.

Windows Mobile 6.5 Developer Tool Kit


The Windows Mobile 6.5 Developer Tool Kit is available for download. It includes the Emulator images as well as the documentation and the samples on Gesture APIs.

Converting a VS2008 csproj to VS2005

I discovered a few easy steps that can allow you to do this. Note: I had already converted (most) of the project files to use .NET 2.0. If you are using Ajax extensions you will have to make your web.config align with this as well. Do this first in VS2008. Obviously if you are using any .NET 3.0 or .NET 3.5 features, this isn't going to work for you...

Next open the csproj file you want to change in Notepad.

Near the top is the Project node. If this contains ToolsVersion="3.5" remove this attribute:

<Project ToolsVersion="3.5" DefaultTargets=...

becomes

<Project DefaultTargets=...

A few lines down there is a <ProductVersion> node, change the value:

<ProductVersion> 9.0.21022 </ ProductVersion>

becomes

<ProductVersion >8.0.50727 </ ProductVersion>

Near the bottom of the file, look for the

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

becomes

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

If there is another <Import node with an MSBuildExtensionsPath, delete this entire line.

Save the file and you should then be able to to open the file in VS2005. Don't double click on the file if you have both versions of Visual Studio installed, you will likely get the default VS2008 to load it.

G-Sensor, Light sensor

The Windows Mobile Unified Sensor API allows developers to easily access the hardware sensors that are available on various phones.

http://sensorapi.codeplex.com/