Platform SDK: Hardware

WM_DEVICECHANGE

The WM_DEVICECHANGE device message notifies an application of a change to the hardware configuration of a device or the computer.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
  HWND hwnd,       // handle to window
  UINT uMsg,       // WM_DEVICECHANGE
  WPARAM wParam,   // device-change event
  LPARAM lParam    // event-specific data
);

Parameters

wParam
Specifies the event. This parameter can be one of the following values.
Value Meaning
DBT_CONFIGCHANGECANCELED A request to change the current configuration (dock or undock) has been canceled.
DBT_CONFIGCHANGED The current configuration has changed, due to a dock or undock.
DBT_CUSTOMEVENT Windows 98 and Windows 2000: 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 can deny this request and cancel the removal.
DBT_DEVICEQUERYREMOVEFAILED A request to remove a device has been canceled.
DBT_DEVICEREMOVECOMPLETE A device has been removed.
DBT_DEVICEREMOVEPENDING A device is about to be removed. Cannot be denied.
DBT_DEVICETYPESPECIFIC A device-specific event has occurred.
DBT_QUERYCHANGECONFIG Permission is requested to change the current configuration (dock or undock).
DBT_USERDEFINED The meaning of this message is user-defined.

lParam
Pointer to a structure that contains event-specific data. Its format depends on the value of the wParam parameter. For more information, refer to the documentation for each event.

Return Values

Return TRUE to grant the request.

Return BROADCAST_QUERY_DENY to deny the request.

Remarks

For devices that offer software-controllable features, such as ejection and locking, the system typically sends a DBT_DEVICEREMOVEPENDING message to let applications and device drivers end their use of the device gracefully. If the system forcibly removes a device, it may not send a DBT_DEVICEQUERYREMOVE message before doing so.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winuser.h; include Windows.h.

See Also

Device Management Overview, Device Management Messages, DBT_CONFIGCHANGECANCELED, DBT_CONFIGCHANGED, DBT_CUSTOMEVENT, DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE, DBT_DEVICEQUERYREMOVEFAILED, DBT_DEVICEREMOVECOMPLETE, DBT_DEVICEREMOVEPENDING, DBT_DEVICETYPESPECIFIC, DBT_QUERYCHANGECONFIG, DBT_USERDEFINED