// 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 0x8040: case 0x8041: case 0x8042: case 0x8043: case 0x8044: case 0x8140: case 0x8141: case 0x8142: case 0x8143: case 0x8144: 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]) { CDialog::OnOK(); } else { MessageBox("Invalid selection", "Exiting"); EndDialog(IDABORT); } } }