Tuesday, July 08, 2008

After Lightning Strikes, One iMac Becomes Two

Here is an article that shows you how you can share an Internet connection over a firewire cable if lightning strikes your Mac. It references an article I have written sometime back on how to share an Internet connection using a Firewire cable. Thanks Phil for letting me know about this article!

Sunday, July 06, 2008

Tip: Bringing a .NET CF Application to the Foreground

In the .NET CF, there is no API to easily bring your application to the foreground. For example, your application may be intercepting incoming SMS messages and is switched to the background when the user uses other applications. When a SMS message is received, you often need to bring your application to the foreground so that the user is notified of the event. To do so, you need to understand that Windows Mobile applications are single-instance. That is, only a single instance of an application can run at a time.

To bring the application to the foreground, first use reflection to find the path of the current application. Then use the Process.Start() method to run the application again. Since Windows Mobile applications are single-instance, using the Start() method on an already running application simply brings it to the foreground:

String appPath =
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
System.Diagnostics.Process.Start(appPath, "");

Thursday, July 03, 2008

Mastering the Windows Mobile Emulators

The latest versions of the Windows Mobile 6 Professional and Standard SDKs allow you to test phone and SMS functionalities using the built-in Cellular Emulator—without needing to use a physical device. Learn how to master the Windows Mobile emulators.

在Windows Mobile中应用智能设备框架(Smart Device Framework)

Sometime back in Dec 2007 I wrote an article on using OpenNETCF's Smart Device Framework (Using the Smart Device Framework for Windows Mobile Development‏). A reader from China,
YuanHui, has done a great job translating it into Chinese. If you are a Chinese reader, do check out the article in Chinese here.

Tip: Convert image to byte array and vice versa

Very often, when you are developing a Windows Mobile application you need to convert an image displayed in a PictureBox control to a byte array. You can do so using:

public byte[] ImageToByteArray(Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}


You can call this function like this:

byte[] data = ImageToByteArray(pictureBox1.Image);

Conversely, if you want to convert a byte array to back to an image so that it can be displayed in a PictureBox control, you can use the following function:

public Image ByteArrayToImage(byte[] data)
{
MemoryStream ms = new MemoryStream(data);
Image img = new Bitmap(ms);
return img;
}

You can use this as follows:

pictureBox2.Image = ByteArrayToImage(data);