Detecting Power State Changes By Using State and Notifications Broker

Send Feedback

Applications can use State and Notifications Broker to get notification when the state of the Bluetooth radio changes. The current state of the Bluetooth radio is stored in the Bluetooth registry value under the HKEY_LOCAL_MACHINE\System\State\Hardware key. The following table shows the possible DWORD values for Bluetooth.

DWORD Value Description
0 Power off - Bluetooth is turned off on the device.
1 Connectable - Bluetooth is turned on. The local device can initiate a connection with a peer device but the local device is not discoverable by peer devices that are within range.
3 Discoverable - Bluetooth is turned on. The local device is listed, when a peer device searches for available devices within range. The peer device can pair with the local device.

For information about changing power states programmatically, see Changing the Bluetooth Radio Mode

The following topics provide information about getting transient notifications by using State and Notifications Broker functions.

The State and Notifications Broker also provides the RegistryNotifyMsgQueue function that an application can use to get notifications using message queues.

Displaying a Status Icon on the Today Screen

Application can respond to Bluetooth power state changes by displaying the state of the Bluetooth stack on the user interface, such as an icon. To add an icon to the lower right-hand corner on the Today screen of a Windows Mobile-based Pocket PC, use the Shell_NotifyIcon function. The pnid parameter points to the NOTIFYICONDATA structure.

Setting the uFlags member of NOTIFYICONDATA to NIF_ICON | NIF_MESSAGE enables an application to register the icon and receive events on the icon by using a custom defined Windows message.

The Tray sample in the Windows Mobile 5.0 Pocket PC SDK demonstrates how to place an icon on the tray on the Today page, then have it activate a popup dialog. For more information, see Tray Application.

Activating the Control Panel for Bluetooth

The application can activate the control panel for Bluetooth settings programmatically by calling the CreateProcess function as the following code example shows.

//launch the control panel with Bluetooth settings programmatically.
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
if (!CreateProcess(L"\\Windows\\ctlpnl.exe", L"cplmain.cpl,23,0", NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi))
{
  MessageBox(hDlg, L"Control Panel could not be opened.", L"Error", MB_OK);
}

See Also

State and Notifications Broker Usage Model

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.