Click here to Skip to main content
15,908,906 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHandling the device change functionality for HID Devices Pin
hariakuthota2-Feb-09 18:14
hariakuthota2-Feb-09 18:14 
AnswerRe: Handling the device change functionality for HID Devices Pin
Sarath C2-Feb-09 18:28
Sarath C2-Feb-09 18:28 
AnswerRe: Handling the device change functionality for HID Devices Pin
john.alex.prog14-Feb-10 8:37
john.alex.prog14-Feb-10 8:37 
AnswerRe: Handling the device change functionality for HID Devices Pin
john.alex.prog14-Feb-10 8:41
john.alex.prog14-Feb-10 8:41 
GeneralRe: Handling the device change functionality for HID Devices Pin
hariakuthota14-Feb-10 17:32
hariakuthota14-Feb-10 17:32 
GeneralRe: Handling the device change functionality for HID Devices Pin
john.alex.prog14-Feb-10 19:01
john.alex.prog14-Feb-10 19:01 
GeneralRe: Handling the device change functionality for HID Devices Pin
hariakuthota14-Feb-10 19:10
hariakuthota14-Feb-10 19:10 
GeneralRe: Handling the device change functionality for HID Devices Pin
john.alex.prog15-Feb-10 4:14
john.alex.prog15-Feb-10 4:14 
#include <windows.h>
#include <dbt.h>
#include <strsafe.h>
#include<iostream.h>
#pragma comment(lib, "user32.lib")

void Main_OnDeviceChange (HWND hwnd, WPARAM wParam, LPARAM lParam);
char FirstDriveFromMask (ULONG unitmask); //prototype

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

Description
Handles WM_DEVICECHANGE messages sent to the application's
top-level window.
--------------------------------------------------------------------*/
HWND hwnd;
WPARAM wParam;
LPARAM lParam;

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:
// Check whether a CD 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)
{
StringCchPrintf (szMsg, 80, "Drive %c: Media has arrived.\n",
FirstDriveFromMask(lpdbv ->dbcv_unitmask));

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

case DBT_DEVICEREMOVECOMPLETE:
// Check whether a CD or DVD 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)
{
StringCchPrintf (szMsg, 80, "Drive %c: Media was removed.\n",
FirstDriveFromMask(lpdbv ->dbcv_unitmask));

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

default:
/*
Process other WM_DEVICECHANGE notifications for other
devices or reasons.
*/
;
}
}

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

Description
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 2 = C,
etc. A valid drive letter is defined when the corresponding bit
is set to 1.

Returns the first drive letter that was found.
--------------------------------------------------------------------*/

char FirstDriveFromMask (ULONG unitmask)
{
char i;

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

return (i + 'A');
}

int main()
{
while(1)
{
Main_OnDeviceChange (hwnd,wParam,lParam);
}

return 0;
}

I found this code on msdn. Where to write it in Vc++. On win32 application or on simple c++ file. Neither main() function is here no win_main function is here. Please help.
Questionhow to disable vertical and horizontal scrollbar in a FormView class Pin
Deepu Antony2-Feb-09 18:05
Deepu Antony2-Feb-09 18:05 
AnswerRe: how to disable vertical and horizontal scrollbar in a FormView class Pin
Roger Allen4-Feb-09 14:07
Roger Allen4-Feb-09 14:07 
QuestionHow can chk Dialog box is open? Pin
Le@rner2-Feb-09 17:54
Le@rner2-Feb-09 17:54 
AnswerRe: How can chk Dialog box is open? Pin
Nibu babu thomas2-Feb-09 18:00
Nibu babu thomas2-Feb-09 18:00 
GeneralRe: How can chk Dialog box is open? Pin
Le@rner2-Feb-09 18:15
Le@rner2-Feb-09 18:15 
GeneralRe: How can chk Dialog box is open? Pin
Nibu babu thomas2-Feb-09 18:16
Nibu babu thomas2-Feb-09 18:16 
GeneralRe: How can chk Dialog box is open? Pin
Le@rner2-Feb-09 18:21
Le@rner2-Feb-09 18:21 
GeneralRe: How can chk Dialog box is open? Pin
Nibu babu thomas2-Feb-09 18:38
Nibu babu thomas2-Feb-09 18:38 
GeneralRe: How can chk Dialog box is open? Pin
Le@rner2-Feb-09 18:49
Le@rner2-Feb-09 18:49 
GeneralRe: How can chk Dialog box is open? Pin
SandipG 2-Feb-09 19:29
SandipG 2-Feb-09 19:29 
AnswerRe: How can chk Dialog box is open? Pin
Sarath C2-Feb-09 18:20
Sarath C2-Feb-09 18:20 
AnswerRe: How can chk Dialog box is open? Pin
_AnsHUMAN_ 2-Feb-09 18:30
_AnsHUMAN_ 2-Feb-09 18:30 
GeneralRe: How can chk Dialog box is open? [modified] Pin
Le@rner2-Feb-09 18:32
Le@rner2-Feb-09 18:32 
GeneralRe: How can chk Dialog box is open? Pin
_AnsHUMAN_ 2-Feb-09 19:29
_AnsHUMAN_ 2-Feb-09 19:29 
QuestionINI FILE in vc++6 Pin
hrishiS2-Feb-09 17:05
hrishiS2-Feb-09 17:05 
AnswerRe: INI FILE in vc++6 Pin
Sarath C2-Feb-09 18:16
Sarath C2-Feb-09 18:16 
GeneralRe: INI FILE in vc++6 Pin
hrishiS2-Feb-09 18:19
hrishiS2-Feb-09 18:19 

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.