Wednesday, July 22, 2009


Don't know the meaning .. check this out here

- Nicolas

Thursday, July 2, 2009

Change the Screen Rotation in your application

Windows Mobile devices allows user to rotate the screen orientation, on some devices, this rotation is automatically done while sliding keyboard is opened to provide the good orientation to user to get a chance to type text using the hardware keyboard. More advanced devices get an accelerometer and can automatically rotate the screen while the user physically rotate the device from portrait to landscape and vice versa.
Windows Embedded CE devices on their side can also have screen rotation enabled, but as they are usually for industrial purposes, this feature is not necessarily enabled.

On both version, when user have to do screen rotation the ChangeDisplaySettingsEx function is used. The sample code below shows up the steps to perform screen rotation.

BOOL RotateScreen(int iRotationAngle)
int iAngle;

// Check if rotation angle is a multiple of 90 degres
if ((iRotationAngle % 90) != 0)
return FALSE;

// Screen rotation is a bit field value
// 0 = 0, 1 = 90, 2 = 180, 4 = 270
iAngle = iRotationAngle / 90;
if( iAngle == 3 )
iAngle = 0x4;

DEVMODE devMode;
memset (&devMode, 0, sizeof (devMode));
devMode.dmSize = sizeof (devMode);

// Retrieve the supported screen rotation angles
if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(NULL, &devMode, NULL, CDS_TEST, NULL))
return FALSE;

// Check if required screen rotation is supported
if (iAngle == 0 || iAngle & devMode.dmDisplayOrientation)
memset(&devMode, 0, sizeof (devMode));
devMode.dmSize = sizeof (devMode);
devMode.dmDisplayOrientation = iAngle;

if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettingsEx(NULL, &devMode, NULL, CDS_RESET, NULL))
return FALSE;
else return TRUE;

return FALSE;

Thanks to Alban for his help.

- Nicolas

State and Notifications Broker API

The State and Notification Broker API provide an easy way to get notified while system state changed or registry content changed. This API is available for both Windows Embedded and Windows Mobile operating systems, and works with a provider and client.

The Provider:
The provider create in registry one entry per state managed, and is in charge of the update of those entries when states changed. Usually system states are defined in HKEY_CURRENT_USER\System\State and HKEY_LOCAL_MACHINE\System\State, and user defined (or applicative) states are located in HKEY_CURRENT_USER\Software\State and HKEY_LOCAL_MACHINE\Software\State. The snapi.h header file defines most of the system states notifications for various system functionalities like Phone, Mails, SMS Appointment, Battery, Screen Rotation ... and custom entries should be managed by your own.

The Client:
The client register to a state defined in registry by the Provider, and get notified by the operating system while value changed. Different notifications mechanism can be used :
  • Application activation : can start a client application while registry content changed (or state changed)
  • Message Queue : signal a state notification through a Message Queue
  • Window message : signal a state notification via a Windows Message loop (WindowProc)
  • Callback : signal a state notification using a call back function

The client should register for state notification using one of the following function depending on the type of notification required (RegistryNotifyApp, RegistryNotifyWindow, RegistryNotifyCallback or RegistryNotifyMsgQueue). When state change notification is received the client should read the value using the regular regsitry functions access, or RegistryGetDWORD or RegistryGetString. While notification is no longer required, the client have to call RegistryCloseNotification to close the notification.

No specific action is required by the provider except to update the registry values while internal application transition should generate external state notifications.

You can find a usage sample in the Windows Mobile SDK sample source code of the Battery Statistic :
%ProgramFiles%\Windows Mobile 6 SDK\Samples\PocketPC\CPP\win32\battstat

- Nicolas