Wednesday, September 26, 2007

My first .Net app : C# Analog Clock

Finally, my first try on a simple .NET app is done. I created a analog clock widget using C#. I think it's quite challenging for a beginner because it will require simple background of Math, image processing, and 3D graphics programming.

With the mouse hit-test, anti-aliasing graphics and flicker-free double buffering, you couldn't even tell the difference between it and Sidebar gadget. Yet it is in C#, and it reduces the pain to deal with Win32 API directly.


To draw the hour-hand, minute-hand and second-hand needs a little trick.

1) Set the origin of form to center, from left-top (so that following rotation can be taken place)
2) Save the current state
3) Rotate the new graphics objects
4) Draw the second-hand (or any hands) at new origin, new orientation
5) Restore the saved state
6) Rotate the new graphics objects
7) Draw the minute-hand (or any hands left) at new origin, new orientation
8) Reload the identity / Reset the origin and orientation (Restore the saved state seems failed)
9) Rotate the new graphics objects
10) Draw the hour-hand (or any hands left) at new origin, new orientation

Voila!
You can get the source here or get the exe here!

#p/s: thanks for the Fasticon for its free icon provided.

Tuesday, September 18, 2007

How to compete with Microsoft

I just happend to come across to this the Inquirer (It is famous of MS-bashing), ironic but true.
Qoute:

Plan B: Start by developing a killer ap. If you can't think of one, don't worry - simply write a copy of an existing piece of software. It doesn't even have to do anything. When people point out that your product is rubbish, issue a press release blaming Microsoft for refusing to give you its proprietary code for free.
...
If you persevere for long enough, you may even convince the European Union that your product would be a world beater if only those bastards at Microsoft would give you the code to make it work properly.
...

Monday, September 17, 2007

Wow, write an OS!!

While surfing on OSNews, I come across to this site. Know what, you also can write your own OS.

With the QEMU processor emulator, anyone one can write & test OS written. Start from doc here and here, now. I wish i could do it now, but not yet master ASP.NET, NET Framework, NET CF, ... , to name a few. OMG.

Sunday, September 16, 2007

Bumblebee I am?

While reading the Mike Hall's Windows Embeded blog, I also take part in the Which Transformer are you? quiz.
Haha, I get this:

I AM
61%
BUMBLEBEE
Take the Transformers Quiz

But I still prefer the Bumblebee in the anime I watched during the time I was a kid.

Tuesday, September 11, 2007

SQL CE database upgrade

This blog will talk about SQL CE database upgrade.
Actually, SQL CE database upgrade is briefly discussed in BOL (Book On-Line). And this blog is just to fill the missing link.

Normally, You can create a brand new application to use .NET CF 2.0 & SQL CE 3.0. Then what's the big deal about the SQL CE database upgrade, you might ask. Well,What you actually face in real-life situation is you are .NET CF 1.0 & SQL CE 2.0 application developer. Due to performance issue (SqlCeResultSet Class) or new functionality that only available in SQL CE 3.0, you need to meet the new requirement yet need to maintain the records that already keep in existing SQL CE 2.0 database. You do not want to create a new SQL CE 3.0 database and import back all the records, ain't you? Then, this is where SQL CE database upgrade comes in.

How will one know the database file (*.sdf) is not workable in SQL CE 3.0 ? Simple, open it from MSSQL Management Studio (Sorry, you need full version to run it). If you see this message, clearly you need to upgrade your database.

Now I will show you how to upgrade it within the emulator environment, specifically for OS PPC 2003. It can be done in actual device in the similar way. First, copy all the cabinet files of SQL CE run-time components for SQL CE 2.0 and 3.0 into you emulator, using Windows CE Remote File Viewer. The default location of the SQL CE 2.0 run-time components is C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v2.0\[platform]\[processor] & the default location of the SQL CE 3.0 run-time components is C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\[platform]\[processor]. You also need a upgrade.exe. This files is located in the same folder with SQL CE 3.0 run-time components.

Then you need to download the Pocket Shell in Windows Mobile Developer Power Toys. It is the PPC version of you desktop command prompt. The default location is in C:\Program Files\Windows Mobile Developer Power Toys\PPC_Command_Shell\arm. Copy the console.dll to emulator's \WINDOWS directory and copy the shell to emulator root folder for less programming later.

So now you should have 5 cabinet files(sqlce20.dev.ppc.wce4.armv4.cab, sqlce20.ppc.wce4.armv4.cab, sqlce30.dev.ENU.ppc.wce4.armv4.cab, sqlce30.dev.ppc.wce4.armv4.cab, sqlce30.rep.ppc.wce4.armv4.cab), 3 executable files (upgrade.exe, cmd.exe & shell.exe from Power Toy) and one SQL CE 2.0 database (oldDB.sdf). Install all the 5 cabinet files & click on the cmd.exe to run it. You will be prompt to enter command.

Type something like: upgrade.exe /s oldDB.sdf /d newDB.sdf

viola! (You need to wait a while if your database is huge)

Try to open it with desktop MSSQL:


If you have missed any cabinet file during installation (eg. you did not install "sqlce30.rep.ppc.wce4.armv4.cab"), you will get this error message:

Try to export the upgrade.log file to analyze:

In this case, you will get:

Connecting to source databaseCreating destination databaseUnable to instantiate SQL CE 3.0 provider
HRESULT: 0x80040154Database upgrade failed

First blog

Hi, this is my first blog. Since my hobby is programming, of course most of the blogs will relate to programming. Haha.