Handling the device change functionality for HID Devices
-
Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.
-
Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.
Registering for a device notification[^] You can check the details of the inserted device by interpreting the LPARAM received to WM_DEVICECHANGE[^] notification. Check documentation for details
-Sarath. "Great hopes make everything great possible" - Benjamin Franklin
My blog - Sharing My Thoughts
-
Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.
Hi. I am sure you can help me. I want to write a program that just detect that a device has been changed. And in my program it is not concerned which device is changed. I have been trying for 15days but not able to handle windproc function. I am not getting any clue how to handle this function. Please send me a sample code. Please please please. I am getting really sick of this. Send me at john.alex.programmer@gmail.com. Please help me. PLZ PLZ PLZ PLZ PLZ.
-
Hi all, In my application I want to handle the insert(plug in) and removal(plug out) of the devices so that i have to re enumerate and show the user present devices connected to the system.But my application is limited to re enumeration of HID devices only, so i want to handle the device change only for HID devices. I handled the WindProc() in which I used if(message == WM_DEVICECHANGE) but I am getting in to this loop for every device change but how can I check whether device change is for HID devices or not. Please suggest a right approach for this. Thanks in advance.
Hi. I am sure you can help me. I want to write a program that just detect that a device has been changed. And in my program it is not concerned which device is changed. I have been trying for 15days but not able to handle windproc function. I am not getting any clue how to handle this function. Please send me a sample code. Please please please. I am getting really sick of this. Send me at john.alex.programmer@gmail.com. Please help me.
-
Hi. I am sure you can help me. I want to write a program that just detect that a device has been changed. And in my program it is not concerned which device is changed. I have been trying for 15days but not able to handle windproc function. I am not getting any clue how to handle this function. Please send me a sample code. Please please please. I am getting really sick of this. Send me at john.alex.programmer@gmail.com. Please help me.
Hi Alex, Did u try with the WindowProc(...) and if(message == WM_DEVICECHANGE ) inside it? This will be triggered if there is any change in the device connected to the system (Like plugging and Unplugging)
-
Hi Alex, Did u try with the WindowProc(...) and if(message == WM_DEVICECHANGE ) inside it? This will be triggered if there is any change in the device connected to the system (Like plugging and Unplugging)
I have tried. But you know the main problem with me is that i dont know how to write windproc function and what are the parameters. I just want a running sample of windproc function. Then I will definitely do. Thanx.
-
I have tried. But you know the main problem with me is that i dont know how to write windproc function and what are the parameters. I just want a running sample of windproc function. Then I will definitely do. Thanx.
LRESULT ClassName::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_DEVICECHANGE ) { } return CDialog::WindowProc(message, wParam, lParam); } Note : In the first line when i say ClassName it is your respective class name.
-
LRESULT ClassName::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_DEVICECHANGE ) { } return CDialog::WindowProc(message, wParam, lParam); } Note : In the first line when i say ClassName it is your respective class name.
#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. Re