Article ID: 163503 - Last Review: May 1, 2007 - Revision: 4.3 How to receive notification of CD-ROM insertion or removalThis article was previously published under Q163503 On This PageSUMMARY
Some applications need to know when the user inserts or removes a
compact disc or DVD from a CD-ROM drive without polling for media changes. Windows provide a way to notify these applications through the
WM_DEVICECHANGE message. This article explains how to handle the
WM_DEVICECHANGE message to detect CD-ROM or DVDmedia changes.
MORE INFORMATION
Windows sends all top-level windows a WM_DEVICECHANGE
message when new devices or media are added and become available, and when
existing devices or media are removed. Each WM_DEVICECHANGE message has an
event associated with it to describe the change, and a structure that
provides detailed information about the change.
The structure consists of an event-independent header followed by an event- dependent structure. The event-dependent part of the structure describes which device the event applies to. To use this structure, applications must first determine the event type and the device type. Then, they can use the correct structure to take appropriate action. When the user inserts a new compact disc or DVD into a drive, applications get a WM_DEVICECHANCE message with a DBT_DEVICEARRIVAL event. The application must check the event to make sure that the type of device arriving is a volume (DBT_DEVTYP_VOLUME) and that the event's media flag (DBTF_MEDIA) is set. When the user removes a compact disc from a CD-ROM drive or DVD, applications will get a WM_DEVICECHANCE message with a DBT_DEVICEREMOVECOMPLETE event. As with DBT_DEVICEARRIVAL above, the application must check the event to make sure that the device being removed is a volume and that the event's media flag is set. Sample CodeThe following code demonstrates how to use the WM_DEVICECHANGE message to check for compact disc or DVD insertion or removal.REFERENCES
Microsoft Platform SDK documentation, "Device Management" overview" chapter
| Article Translations
|
Back to the top
