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 dbcc_name field contains the device filename.

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

Wdm2Notify is a Win32 MFC dialog application that displays any device change events for the Wdm2 device interface. It can be found in the Wdm2Notify directory of the book software. I had a little difficulty setting up the project so that it would compile and link correctly. As I was using VC++ 5, some of the header files and libraries were out of date. I therefore had to change the project settings to use the Platform SDK include directories first, before the Visual C++ directories. My Platform SDK was installed at D:MSSDK, so you may need to change the project settings if you want to recompile Wdm2Notify. I also had to link to the version of user32.lib in the Platform SDK. If you are running a later version of Visual Studio, you may be able to undo these project changes.

Some of the device change structures are defined in dbt.h, so I included this header file in the Wdm2Notify main MFC header, stdafx.h. I also had to include the following line in the stdafx.h to ensure that the correct functions were declared.

#define WINVER 0x0500

Listing 9.14 shows the main Wdm2Notify PnP Notification routines in file Wdm2Notif.yDlg.cpp. RegisterDeviceNotification is called in the dialog OnInitDialog routine and unregistered in DestroyWindow. Device change messages are handled in OnDeviceChange. The rest of the source code for Wdm2Notify can be found on the book software disk.

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:

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату
×