Tuesday, December 8, 2009

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);
}

Wednesday, October 21, 2009

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


Tuesday, October 13, 2009

Meet Resco at PDC 09


We will be there at a booth with number: 1110.
Hope you will visit us personally and talk to us about your mobile development experience, feature requests and opinions. Your feedback is very important.

Feel free to write a comment if you will be there too.
Thanks in advance!

Thursday, September 24, 2009

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

Tuesday, September 8, 2009

Similar icons with ImageButton


Sometimes you need the same background image for your image buttons to keep your style in your mobile application, and you just want to change the icon of your buttons.

This sample shows you how to do it with Resco's ImageButton control.

Source Code:
http://winmobile.euweb.cz/#Post13

Wednesday, August 26, 2009

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

Tuesday, August 18, 2009

Resco CustomKeyboard Designer


Currently I'm developing a new CustomKeyboard Designer, which should prevent your headache. :)
With this designer you won't calculate the Bounds of a Key on your custom keyboard, but simple you would be able to resize and move the keys with the mouse.

You could also cut, copy, paste KeyDescriptor from one Layout to another.

This application saves your design into XML file, so you can load it back in Visual Studio or during the run-time.

Thursday, July 30, 2009

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)

Friday, July 24, 2009

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

Wednesday, July 1, 2009

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.