/* * $RCSfile: DetectDialog.cpp,v $ * $Date: 2009/10/09 17:24:35 $ * $Revision: 1.4 $ * jEdit:collapseFolds=1:tabSize=4: * * class DetectDialog implementation */ #include "stdafx.h" #include "sample0.h" #include "DetectDialog.h" #include "AIOUSB.h" BEGIN_MESSAGE_MAP( DetectDialog, CDialog ) //{{AFX_MSG_MAP(DetectDialog) ON_BN_CLICKED( IDC_GO_BUTTON, OnGoButton ) ON_BN_CLICKED( IDC_REDETECT_BUTTON, OnRedetectButton ) //}}AFX_MSG_MAP END_MESSAGE_MAP() DetectDialog::DetectDialog( CWnd *pParent /* = NULL */ ) : CDialog( DetectDialog::IDD, pParent ) { //{{AFX_DATA_INIT(DetectDialog) messageEditText = _T(""); //}}AFX_DATA_INIT } // DetectDialog::DetectDialog() BOOL DetectDialog::OnInitDialog() { CDialog::OnInitDialog(); OnRedetectButton(); return TRUE; } // DetectDialog::OnInitDialog() void DetectDialog::DoDataExchange( CDataExchange *pDX ) { CDialog::DoDataExchange( pDX ); //{{AFX_DATA_MAP(DetectDialog) DDX_Control( pDX, IDC_DEVICE_LISTBOX, deviceListBox ); DDX_Text( pDX, IDC_MESSAGE_EDIT, messageEditText ); //}}AFX_DATA_MAP } // DetectDialog::DoDataExchange() void DetectDialog::OnCancel() { // prevent ESC from closing dialog } // DetectDialog::OnCancel() void DetectDialog::OnOK() { // prevent ENTER from closing dialog } // DetectDialog::OnOK() void DetectDialog::OnGoButton() { deviceIndex = deviceListBox.GetCurSel(); if( deviceIndex == LB_ERR || ! deviceValid[ deviceIndex ] ) { MessageBox( "Invalid selection", "Exiting" ); deviceIndex = -1; }; // if( deviceIndex ... EndDialog( 0 ); } // DetectDialog::OnGoButton() void DetectDialog::OnRedetectButton() { deviceListBox.ResetContent(); int validDevices = 0; unsigned long deviceMask = GetDevices(); for( int index = 0; index < MAX_DEVICES; index++ ) { CString productName; deviceValid[ index ] = false; if( ( deviceMask & 1 ) != 0 ) { const int MAX_NAME_SIZE = 256; char name[ MAX_NAME_SIZE + 2 ]; unsigned long nameSize = MAX_NAME_SIZE; unsigned long productID; if( QueryDeviceInfo( index, &productID, &nameSize, name, NULL, NULL ) == ERROR_SUCCESS ) { if( nameSize > 0 ) { name[ nameSize ] = 0; productName = name; } else { // device didn't return a name, so use its product ID as name productName.Format( "Product ID %#06X", productID ); } // if( nameSize ... if( productID >= 0x8140 && productID <= 0x815D ) { // this device is valid for this sample program deviceValid[ index ] = true; validDevices++; } else { productName += " "; } // if( productID ... } else productName = ""; } else productName = ""; deviceListBox.InsertString( index, productName ); deviceMask >>= 1; } // for( int index ... if( validDevices > 0 ) messageEditText = "Select the device you want to use with this sample program and click the 'Go' button."; else messageEditText = "No devices found that are suitable for this sample program. Device may not be properly installed. Click the 'Redetect' button to check again."; UpdateData( FALSE ); } // DetectDialog::OnRedetectButton() /* end of file */