// sample0Dlg.cpp : implementation file // #include "stdafx.h" #include "sample0.h" #include "sample0Dlg.h" #include "aiousb.h" #include "DetectDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg dialog CSample0Dlg::CSample0Dlg(CWnd* pParent /*=NULL*/) : CDialog(CSample0Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CSample0Dlg) m_label0 = _T(""); m_label1 = _T(""); m_label2 = _T(""); m_label3 = _T(""); m_label4 = _T(""); m_label5 = _T(""); m_label6 = _T(""); m_label7 = _T(""); m_autoUpdate = FALSE; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CSample0Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSample0Dlg) DDX_Control(pDX, IDC_SLIDER7, m_slider7); DDX_Control(pDX, IDC_SLIDER6, m_slider6); DDX_Control(pDX, IDC_SLIDER5, m_slider5); DDX_Control(pDX, IDC_SLIDER4, m_slider4); DDX_Control(pDX, IDC_SLIDER3, m_slider3); DDX_Control(pDX, IDC_SLIDER2, m_slider2); DDX_Control(pDX, IDC_SLIDER1, m_slider1); DDX_Control(pDX, IDC_SLIDER0, m_slider0); DDX_Text(pDX, IDC_LABEL0, m_label0); DDX_Text(pDX, IDC_LABEL1, m_label1); DDX_Text(pDX, IDC_LABEL2, m_label2); DDX_Text(pDX, IDC_LABEL3, m_label3); DDX_Text(pDX, IDC_LABEL4, m_label4); DDX_Text(pDX, IDC_LABEL5, m_label5); DDX_Text(pDX, IDC_LABEL6, m_label6); DDX_Text(pDX, IDC_LABEL7, m_label7); DDX_Check(pDX, IDC_UPDATE_CHECK, m_autoUpdate); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSample0Dlg, CDialog) //{{AFX_MSG_MAP(CSample0Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER0, OnReleasedcaptureSlider0) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER2, OnReleasedcaptureSlider2) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER3, OnReleasedcaptureSlider3) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER4, OnReleasedcaptureSlider4) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER5, OnReleasedcaptureSlider5) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER6, OnReleasedcaptureSlider6) ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER7, OnReleasedcaptureSlider7) ON_BN_CLICKED(IDC_UPDATE_CHECK, OnUpdateCheck) ON_BN_CLICKED(IDC_UPDATE_BTN, OnUpdateBtn) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg message handlers BOOL CSample0Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here unsigned long Status, productID; deviceIndex = diOnly; Status = QueryDeviceInfo(diOnly, &productID, NULL, NULL, NULL, NULL); if ( (Status != ERROR_SUCCESS) || ! ((productID == 0x4003) || (productID == 0x4002)) ) { DetectDialog box; if (box.DoModal() != IDOK) { exit(0); } else { deviceIndex = 7 - box.index; } } sliders[0] = &m_slider0; sliders[1] = &m_slider1; sliders[2] = &m_slider2; sliders[3] = &m_slider3; sliders[4] = &m_slider4; sliders[5] = &m_slider5; sliders[6] = &m_slider6; sliders[7] = &m_slider7; labels[0] = &m_label0; labels[1] = &m_label1; labels[2] = &m_label2; labels[3] = &m_label3; labels[4] = &m_label4; labels[5] = &m_label5; labels[6] = &m_label6; labels[7] = &m_label7; int count; for (count = 0; count < 8; count++) { sliders[count]->SetRange(0, 0xFFF, FALSE); labels[count] -> Format("000"); } m_autoUpdate = TRUE; for (count = 0; count < 8; count++) { DACDirect(deviceIndex, count, 0); } UpdateData(false); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CSample0Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CSample0Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CSample0Dlg::sliderChange(int index) { int foo = 0; labels[index] -> Format("%3X", sliders[index] -> GetPos()); UpdateData(false); if (m_autoUpdate == TRUE) { foo=DACDirect(deviceIndex, index, sliders[index] -> GetPos()); } foo++; } void CSample0Dlg::OnReleasedcaptureSlider0(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(0); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(1); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider2(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(2); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider3(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(3); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider4(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(4); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider5(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(5); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider6(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(6); *pResult = 0; } void CSample0Dlg::OnReleasedcaptureSlider7(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here sliderChange(7); *pResult = 0; } void CSample0Dlg::OnUpdateCheck() { // TODO: Add your control notification handler code here UpdateData(true); } void CSample0Dlg::OnUpdateBtn() { // TODO: Add your control notification handler code here int count; for (count = 0; count < 8; count++) { DACDirect(deviceIndex, count, sliders[count] -> GetPos()); } }