// DetectDialog.cpp : implementation file // #include "stdafx.h" #include "sample0.h" #include "DetectDialog.h" #include "aiousb.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // DetectDialog dialog DetectDialog::DetectDialog(CWnd* pParent /*=NULL*/) : CDialog(DetectDialog::IDD, pParent) { //{{AFX_DATA_INIT(DetectDialog) m_message = _T(""); //}}AFX_DATA_INIT } void DetectDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(DetectDialog) DDX_Control(pDX, IDC_LIST1, m_deviceList); DDX_Text(pDX, IDC_EDIT_MESSAGE, m_message); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(DetectDialog, CDialog) //{{AFX_MSG_MAP(DetectDialog) ON_BN_CLICKED(IDC_DETECT_BTN, OnDetectBtn) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // DetectDialog message handlers void DetectDialog::OnDetectBtn() { unsigned long DeviceMask; unsigned long PID, NameSize; CString nom; bool Found; m_deviceList.ResetContent(); DeviceMask = GetDevices(); for (int i = 0; i <= 7; i++) { DeviceOK[i] = false; if (DeviceMask & (1 << i)) { NameSize = 256; QueryDeviceInfo(i, &PID, &NameSize, nom.GetBuffer(NameSize), NULL, NULL); nom.ReleaseBuffer(NameSize); switch(PID) { case 0x4002: case 0x4003: DeviceOK[i] = true; Found = true; break; default: nom += " "; break; } } else { nom = ""; } m_deviceList.InsertString(i, nom); } if (Found) { m_message = "Select the device you want to work with and click Go."; } else { m_message = "No compatible devices found; your device may not be installed, or may not be installed properly. Click Redetect to check again."; } UpdateData(true); } BOOL DetectDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here OnDetectBtn(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void DetectDialog::OnOK() { // TODO: Add extra validation here index = m_deviceList.GetCurSel(); if (index != LB_ERR) { if (DeviceOK[index]) { } else { MessageBox("Invalid selection", "Exiting"); } } CDialog::OnOK(); }