4/8/2010
An application can use the
RegistryNotifyWindowfunction to register a custom Windows
message that detects changes in the
Bluetoothregistry value located under the
HKEY_LOCAL_MACHINE\System\State\Hardwarekey. When the state
of the Bluetooth radio changes, the specified Window is notified
through the custom message. The
pConditionparameter points to the
NOTIFICATIONCONDITIONstructure that stores the the registration
criteria.
To stop receiving notifications through messages, call the
RegistryCloseNotificationfunction and pass the handle returned
by
RegistryNotifyWindowas 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. |
|
Copy Code
|
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