Table 9.4 lists the main event types returned in wParam. lParam may point to an appropriate structure. For device interface change events, it is a DEV_BROADCAST_DEVICEINTERFACE structure whose
For a WM_DEVICECHANGE message that asks permission to remove a device, the handler must return TRUE to agree or BROADCAST_QUERY_DENY[23] to deny the requests. Returning FALSE seems to have the same effect as returning TRUE.
Table 9.4 WM_DEVICECHANGE event types
DBT_CONFIGCHANGECANCELED | A request to change the current configuration (dock or undock) has been cancelled |
DBT_CONFIGCHANGED | The current configuration has changed, due to a dock or undock |
DBT_CUSTOMEVENT | A custom event has occurred |
DBT_DEVICEARRIVAL | A device has been inserted and is now available |
DBT_DEVICEQUERYREMOVE | Permission is requested to remove a device. Any application candeny this request and cancel the removal |
DBT_DEVICEQUERYREMOVEFAILED | A request to remove a device has been cancelled |
DBT_DEVICEREMOVEPENDING | A device is about to be removed. Cannot be denied |
DBT_DEVICEREMOVECOMPLETE | A device has been removed |
DBT_DEVICETYPESPECIFIC | A device-specific event has occurred |
DBT_QUERYCHANGECONFIG | Permission is requested to change the current configuration (dock or undock) |
DBT_DEVNODES_CHANGED | Device tree has changed |
DBT_USERDEFINED | The meaning of this message is user-defined |
Wdm2Notify application
Some of the device change structures are defined in dbt.h, so I included this header file in the
#define WINVER 0x0500
Listing 9.14 shows the main
Listing 9.14 Wdm2Notify device change routines
BOOL CWdm2NotifyDlg::OnInitDialog() {
CDialog::OnlnitDialog();
// …
// Register for Wdm2 device interface changes
DEV_BROADCAST_DEVICEINTERFACE dbch;
dbch.dbcc_size = sizeof(dbch);
dbch.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
dbch.dbcc_classguid = WDM2_GUID;
dbch.dbcc_name[0] = ' ';
WdmNotificationHandle = RegisterDeviceNotification(GetSafeHwnd(), &dbch, DEVICE_NOTIFY_WINDOW_HANDLE);
if (WdmNotificationHandle==NULL)
GetDlgItem(IDC_STATUS)->SetWindowText('Cannot register for Wdm2 class device notification');
return TRUE;
}
BOOL CWdm2NotifyDlg::DestroyWindow() {
if (WdmNotificationHandle!=NULL) {
UnregisterDeviceNotification(WdmNotificationHandle);
WdmNotificationHandle = NULL;
}
return CDialog::DestroyWindow();
}
BOOL CWdm2NotifyDlg::OnDeviceChange(UINT nEventType, DWORD dwData) {
CString Msg = 'duh';
switch (nEventType) {
case DBT_CONFIGCHANGECANCELED: