void CtestdeviceDlg::OnBnClickedButton1()
{
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(NotificationFilter);
NotificationFilter.dbcc_devicetype=DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid=CAMERA;
RegisterDeviceNotification(this->m_hWnd,&NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
//DWORD err= GetLastError();
}
BOOL CtestdeviceDlg::PreTranslateMessage(MSG* pMsg)
{
char str[200];
if( pMsg->message == WM_DEVICECHANGE )
{
//if ( pMsg->wParam==DBT_DEVNODES_CHANGED )
//int kk=1;
//sprintf(str,"%d %d ",pMsg->wParam,pMsg->lParam);
//::MessageBoxA(NULL,str,"",MB_OK);
if ( pMsg->wParam == DBT_DEVICEARRIVAL) //device arrival
{
AfxMessageBox(L"arrival",MB_OK,0);
return 1;
}
else if (pMsg->wParam == DBT_DEVICEREMOVECOMPLETE) //device remove
{
AfxMessageBox(L"remove",MB_OK,0);
return -1;
}
}