// DetectDialog.cpp : implementation file // #include "stdafx.h" #include "ADSample.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() { // TODO: Add your control notification handler code here unsigned long DeviceMask; unsigned long PID; bool Found; m_deviceList.ResetContent(); DeviceMask = GetDevices(); for (int i = 0; i <= 7; i++) { CString Nom; DeviceOK[i] = false; if (DeviceMask & (1 << i)) { unsigned long NomLen = 256; QueryDeviceInfo(i, &PID, &NomLen, Nom.GetBuffer(NomLen), NULL, NULL); Nom.ReleaseBuffer(NomLen); switch(PID) { case 0x804A: case 0x804B: case 0x804C: case 0x804D: case 0x804E: case 0x804F: case 0x8050: case 0x8051: case 0x8052: case 0x8053: case 0x8054: case 0x8055: case 0x8056: case 0x8057: case 0x8058: case 0x8059: case 0x805A: case 0x805B: case 0x805C: case 0x805D: case 0x814A: case 0x814B: case 0x814C: case 0x814D: case 0x814E: case 0x814F: case 0x8150: case 0x8151: case 0x8152: case 0x8153: case 0x8154: case 0x8155: case 0x8156: case 0x8157: case 0x8158: case 0x8159: case 0x815A: case 0x815B: case 0x815C: case 0x815D: DeviceOK[i] = true; Found = true; break; default: itoa(PID, Nom.GetBuffer(5), 16); Nom.ReleaseBuffer(); 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]) { CDialog::OnOK(); } else { MessageBox("Invalid selection", "Exiting"); EndDialog(IDABORT); } } }