Notification Through Windows Messages
4/8/2010
An application can use the RegistryNotifyWindow function to register a custom Windows message that detects changes in the Bluetooth registry value located under the HKEY_LOCAL_MACHINE\System\State\Hardware key. When the state of the Bluetooth radio changes, the specified Window is notified through the custom message. The pCondition parameter points to the NOTIFICATIONCONDITION structure that stores the the registration criteria.
To stop receiving notifications through messages, call the RegistryCloseNotification function and pass the handle returned by RegistryNotifyWindow as a parameter.
The following code example shows how to register for notifications using RegistryNotifyWindow.
Note
Error handling has been omitted in this topic for clarity.
HRESULT RegisterBluetoothWindowsMessage(HWND hDlg)
{
#define SN_BLUETOOTHPOWERBSTATE_ROOT HKEY_LOCAL_MACHINE
#define SN_BLUETOOTHPOWERBSTATE_PATH TEXT("System\\State\\Hardware")
#define SN_BLUETOOTHPOWERBSTATE_VALUE TEXT("Bluetooth")
#define SN_BLUETOOTHPOWERBSTATE_BITMASK 3
HRESULT hr = NULL;
NOTIFICATIONCONDITION nc;
HREGNOTIFY g_hNotify_Windows = NULL; // Handles to notifications through Windows message
nc.ctComparisonType = REG_CT_ANYCHANGE;
nc.dwMask = SN_BLUETOOTHPOWERBSTATE_BITMASK;
nc.TargetValue.dw = 0;
hr = RegistryNotifyWindow(
SN_BLUETOOTHPOWERBSTATE_ROOT,
SN_BLUETOOTHPOWERBSTATE_PATH,
SN_BLUETOOTHPOWERBSTATE_VALUE,
hDlg,
WM_CHANGE_BLUETOOTH, // This notification uses a custom window message.
0,
&nc,
&g_hNotify_Windows
);
if (FAILED(hr))
{
//perform error handling;
return hr;
}
return S_OK;
}
See Also
Concepts
Detecting Power State Changes By Using State and Notifications Broker
Notification Through Callback