Friday, October 29, 2010

Unlock the Windows Mobile Device programmatically

Windows Mobile 6.5 comes with a 'lock' mechanism just like any other mobile device .This feature has been available since Pocket PC days, although the mechanism was a little different. Though this built in locking feature was available, many companies and users had to build their own locking feature as no direct API/Handle was available for granular control of locking and timing.

Most of the cases, these locks are not password protected by users, and the sole intention of locking is to prevent any unwitting access to applications on Today screen.

Now, there are situations where the device is locked and the user warm boots the device. Under certain conditions when the device warm boots, the OS takes the user back to the locked state. Though unlocking the device is as simple as sliding the button (as shown in picture)
If not in all the cases, there are some cases where some start up applications run on a warm boot and come on top of today screen (controlled by its Z-index), eventually to find the focus being stolen by unseen lock screen hidden behind this app. Now the user is bogged under the real 'dead lock' scenario, he can neither close the app on top of the screen nor unlock the device, a catch-22 situation.
To avert such situation any start up app should ensure that the device is either programmatically unlocked and stay behind the lock screen. I couldn't find the way of keeping the app being the lock screen, but definitely found of way of unlocking the device..courtesy the Remote Spy tool shipped with VS.NET 2005+ onwards.
This tool helps in trapping all hte messages an open windows goes through. A quick look at the editor showed that lock runs under the name of "ConfettiLockScreen". By sending the right messages in right order simulates a 'slide' event and voila... unlocks the device.

[DllImport("coredll.dll", EntryPoint = "SendMessage")]
extern public static Int32 SendMessage(
IntPtr hWnd, // handle to destination window
uint Msg, // message
uint wParam, // first message parameter
uint lParam); // second message parameter

[DllImport("coredll.dll", EntryPoint = "FindWindow")]
extern public static IntPtr FindWindow(string className,
string windowName);

public Form1()
IntPtr hwnd = FindWindow("ConfettiLockScreen", null);
if (hwnd != null && hwnd != IntPtr.Zero)
SendMessage(hwnd, 0x00000111, 0x00004076, 0 ); //WM_COMMAND
SendMessage(hwnd, 0x00000008, 0, 0); //WM_KILLFOCUS
SendMessage(hwnd, 0x00000281, 0, 0xC000000F); //WM_IME_SETCONTEXT
SendMessage(hwnd, 0x00000282, 0, 0x00000001); //WM_IME_NOTIFY
MessageBox.Show("Could not get handle to lock object");

Tuesday, June 22, 2010

What Windows Phone 7 offers CF developers?

Yesterday I was looking for some insights on Windows Phone 7 and what it offers for Windows Mobile developers. After going through the MS sites, it seems Microsoft wanted to bridge the gap between full framework and compact framework developers, or essentially make any .Net developer (who uses Silverlight) a Windows Phone developer.

So, in other words, rug has been pulled under the legs of developers who are working with .Net CF :-)

Stumbled across this good book from Charles Petzold. Scheduled to be released by year end, but has few review chapters that focuses on what Windows Phone 7 is all about. A definite good read.

In a nutshell...
1. .NET CF is OUT (ironically, it is still the core runtime engine .NET CF 3.7 on the device, but framework is not available for developers)
2. Silverlight and XNA are IN
3. WP7 defines the hardware and not the OEM's
4. No custom SIPs
5. C/C++ is also OUT. NO native coding. Only Managed.
6. Doesn't support copy/paste
7. No Mutiltasking. very unlike WM 6 Series.
8. SQL CE - This is not part of CTP, but seems to be in works and will be released later. Till then its either Isolated Storage or XML files.

Still needs to see if Windows Phone is specific for Smart phone or can scale up to Enterprise level applications that Windows Mobile has been supporting using a technology mix.

Sunday, June 13, 2010

Setting WIFI using registry

This is another of those challenges Pocket PCs/Windows Mobile devices throw at developers.
With the advent of CSPs (Configuration Service Provider), much of the device interaction complexities are resolved, however there are few that still either elude us or cryptic in implementation.
One such issue that I came across is setting the wifi, i.e., configuring the network adapter to use either"Work" or "The Internet" options. Though I read some articles on using CSP's CM_NetEntries on resolving this issue, somehow it didn't work for me.

Using the below approach by setting the guid in the registry did the trick.

string WiFiSettingPath = @"HKEY_LOCAL_MACHINE\ControlPanel\WiFi\Ethernet";
Microsoft.Win32.Registry.SetValue(WiFiSettingPath, "DestId", "{A1182988-0D73-439E-87AD-2A5B369F808B}");
//{A1182988-0D73-439E-87AD-2A5B369F808B} -- is the guid for work

As usual once you set as above, warm boot the device for the new settings to take affect.
Note: Sending a WM_BROADCAST doesn't work in this case.

Monday, June 7, 2010

Disable Windows Mobile 'out of box' Phone

You may have noticed many times that soft phone on windows mobile (6.0, 6.1, 6.5) pops up on screen whenever you press the green phone button. This could be annoying if the device happens to be of type PocketPC (like the robust ones used in retail stores) where other LOB applications are of significance and not the phone itself. I could not find an easy way to turn it off and comes up when I inadvertently end up hitting the key owing to the size of the small keypad.

I figured this phone application is controlled by OS and runs as CProg.exe. Killing this process doesn't help because OS kick starts it, if found not running.

Use the following workaround to turn it off completely...
1. Create a console exe that does nothing and name it as CProg.exe
2. Override the below registry entries HKLM\SOFTWARE\Microsoft\Shell\Rai\:MSCPROG
0 = "CProg"
1 = ""\[path to exe]\CProg.exe""

...and warm boot the device.