Source file: /~heha/mb-iwp/USB-1210/1210-201023.zip/src/CardIDDlg.cpp

#include "1210.h"

/*extern*/
int nCardID;
/*static*/
U16 wModuleNum;
USBDAQ_DEVICE AvailModules[MAX_USB_DEVICE];

static INT_PTR CALLBACK CardSelProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  switch (msg) {
    case WM_INITDIALOG: {
      HWND hCombo=GetDlgItem(wnd,101);
      for (unsigned i=0; i<wModuleNum; i++) {
	if (AvailModules[i].wModuleType == USB_1210) {
	  unsigned id = AvailModules[i].wCardID;
	  TCHAR s[32];
	  _sntprintf(s,elemof(s),TEXT("%u"),id);
	  int idx=ComboBox_AddString(hCombo,s);
	  ComboBox_SetItemData(hCombo,idx,id);
	}
      }
      ComboBox_SetCurSel(hCombo,0);
    }return TRUE;
    case WM_COMMAND: switch (wParam) {
      case IDOK: {
        HWND hCombo=GetDlgItem(wnd,101);
        nCardID=ComboBox_GetItemData(hCombo,ComboBox_GetCurSel(hCombo)); // store to global variable
      }	// fallthrough
      case IDCANCEL: EndDialog(wnd,wParam);
    }break;
  }
  return FALSE;
}

bool CardSel(HWND hParent) {
  U16 wModuleNum;
  USBDAQ_DEVICE AvailModules[MAX_USB_DEVICE];
  I16 nErr = UD_Device_Scan(&wModuleNum,AvailModules);
  if (nErr) {
    MBox(hParent,1,MB_OK,nErr);
    return false;
  }
  int nModules=0;
  for (unsigned i=0; i<wModuleNum; i++) {
    if (AvailModules[i].wModuleType == USB_1210) {
      ++nModules;
      nCardID=AvailModules[i].wCardID;
    }
  }
  if (nModules<2) return nModules&1;
  return DialogBox(hInstance,MAKEINTRESOURCE(102),hParent,CardSelProc)==IDOK;
}
Detected encoding: ASCII (7 bit)2