Click here to Skip to main content
15,922,145 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VC 6.0 in WinXP? Pin
Michael P Butler2-Feb-02 4:05
Michael P Butler2-Feb-02 4:05 
GeneralAh SP5 Pin
Joel Holdsworth2-Feb-02 4:20
Joel Holdsworth2-Feb-02 4:20 
GeneralPassing CArray to function Pin
User 267402-Feb-02 2:57
professionalUser 267402-Feb-02 2:57 
GeneralRe: Passing CArray to function Pin
Joel Holdsworth2-Feb-02 3:48
Joel Holdsworth2-Feb-02 3:48 
GeneralMSN Messenger style alert windows Pin
tinsleyphone1-Feb-02 23:32
tinsleyphone1-Feb-02 23:32 
GeneralRe: MSN Messenger style alert windows Pin
tinsleyphone1-Feb-02 23:37
tinsleyphone1-Feb-02 23:37 
QuestionThe Function of check if the CD-ROM's door opened or closed? Pin
Love In Snowing1-Feb-02 20:41
Love In Snowing1-Feb-02 20:41 
AnswerRe: The Function of check if the CD-ROM's door opened or closed? Pin
Wolfram Steinke1-Feb-02 23:46
Wolfram Steinke1-Feb-02 23:46 
Have a look into MSDN document

HOWTO: Getting Notification of CD-ROM Insertion or Removal

Here is the sample code from it

Sample Code
The following code demonstrates how to use the WM_DEVICECHANGE message to check for compact disc or DVD insertion or removal.

#include <windows.h>
#include <dbt.h>

char FirstDriveFromMask (ULONG unitmask); //prototype


/*----------------------------------------------------------------------
Main_OnDeviceChange (hwnd, wParam, lParam)

Description
Handles WM_DEVICECHANGE messages sent to the application's
top-level window.
----------------------------------------------------------------------*/

void Main_OnDeviceChange (HWND hwnd, WPARAM wParam, LPARAM lParam)
{

PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
char szMsg[80];


switch(wParam)
{
case DBT_DEVICEARRIVAL:
// See if a CD-ROM or DVD was inserted into a drive.
if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;

if (lpdbv -> dbcv_flags & DBTF_MEDIA)
{
wsprintf (szMsg, "Drive %c: arrived\n",
FirstDriveFromMask(lpdbv ->dbcv_unitmask));

MessageBox (hwnd, szMsg, "WM_DEVICECHANGE", MB_OK);
}
}
break;


case DBT_DEVICEREMOVECOMPLETE:
// See if a CD-ROM was removed from a drive.
if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;

if (lpdbv -> dbcv_flags & DBTF_MEDIA)
{
wsprintf (szMsg, "Drive %c: was removed\n",
FirstDriveFromMask(lpdbv ->dbcv_unitmask));

MessageBox (hwnd, szMsg, "WM_DEVICECHANGE", MB_OK);
}
}
break;

default:
/*
Other WM_DEVICECHANGE notifications get sent for other devices
or reasons; we don't care about them here. If they were
important, we would check for them and act accordingly.
*/
;
}
}


/*----------------------------------------------------------------------
FirstDriveFromMask (unitmask)

Finds the first valid drive letter from a mask of drive letters. The
mask must be in the format bit 0 = A, bit 1 = B, bit 3 = C, etc.

A valid drive letter is defined when the corresponding bit is set to
1.

Returns the drive letter that was first found.
----------------------------------------------------------------------*/
char FirstDriveFromMask (ULONG unitmask)
{
char i;

for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
break;
unitmask = unitmask >> 1;
}

return (i + 'A');
}
Although this sample code only checks for volume arrivals due to the insertion of new media, it can be extended to get notification of other hardware events for other types too. To do so, you have to add cases for other device events and handle different device types for each event.

Happy programming!!
GeneralSetting HREF from ATL Pin
1-Feb-02 20:17
suss1-Feb-02 20:17 
GeneralRefreshing problem.. Pin
Neha1-Feb-02 19:04
Neha1-Feb-02 19:04 
GeneralRe: Refreshing problem.. Pin
Wolfram Steinke1-Feb-02 23:39
Wolfram Steinke1-Feb-02 23:39 
GeneralRe: Refreshing problem.. Pin
Neha2-Feb-02 1:46
Neha2-Feb-02 1:46 
GeneralRe: Refreshing problem.. Pin
Wolfram Steinke2-Feb-02 11:52
Wolfram Steinke2-Feb-02 11:52 
GeneralKinda New at this Pin
1-Feb-02 17:17
suss1-Feb-02 17:17 
GeneralRe: Kinda New at this Pin
Rick York1-Feb-02 18:06
mveRick York1-Feb-02 18:06 
QuestionIs it possible to use multiple CDC's?? Pin
Jay Beckert1-Feb-02 17:18
Jay Beckert1-Feb-02 17:18 
AnswerRe: Is it possible to use multiple CDC's?? Pin
Paul M Watt1-Feb-02 21:37
mentorPaul M Watt1-Feb-02 21:37 
GeneralRe: Is it possible to use multiple CDC's?? Pin
Jay Beckert19-Jun-02 14:24
Jay Beckert19-Jun-02 14:24 
Questionwhat is wrong? Pin
1-Feb-02 16:00
suss1-Feb-02 16:00 
AnswerRe: what is wrong? Pin
Michael Dunn1-Feb-02 16:16
sitebuilderMichael Dunn1-Feb-02 16:16 
GeneralRe: what is wrong? Pin
Le centriste4-Feb-02 4:20
Le centriste4-Feb-02 4:20 
GeneralList Control Space Bug Pin
Swinefeaster1-Feb-02 14:10
Swinefeaster1-Feb-02 14:10 
QuestionClass prototype? Pin
1-Feb-02 14:05
suss1-Feb-02 14:05 
AnswerRe: Class prototype? Pin
Swinefeaster1-Feb-02 14:14
Swinefeaster1-Feb-02 14:14 
GeneralRe: Class prototype? Pin
Tim Smith1-Feb-02 14:40
Tim Smith1-Feb-02 14:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.