// SDK9524GPTCDlg.cpp : implementation file // #include "stdafx.h" #include "SDK9524GPTC.h" #include "SDK9524GPTCDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #define TIMEBASE 40000000.0 #define TIMER_GPTC_MAJOR_MODE0 1 // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CSDK9524GPTCDlg dialog CSDK9524GPTCDlg::CSDK9524GPTCDlg(I16 hCard, CWnd* pParent /*=NULL*/) : CDialog(CSDK9524GPTCDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_nTimer0 = NULL; m_bRunning0 = 0; m_GPTCMode = P9524_x4_AB_Phase_Decoder; m_hCard = hCard; } void CSDK9524GPTCDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO_GPTC, m_cbGPTCNo); } BEGIN_MESSAGE_MAP(CSDK9524GPTCDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_CBN_SELCHANGE(IDC_COMBO_GPTC, &CSDK9524GPTCDlg::OnGPTCNoSelchange) ON_BN_CLICKED(IDC_BT_MODE0, &CSDK9524GPTCDlg::OnGPTCMode0Start) ON_WM_TIMER() END_MESSAGE_MAP() // CSDK9524GPTCDlg message handlers BOOL CSDK9524GPTCDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 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 m_wGPTCNo = P9524_CTR_QD0; m_cbGPTCNo.SetCurSel( 0 ); return TRUE; // return TRUE unless you set the focus to a control } void CSDK9524GPTCDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 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 CSDK9524GPTCDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CSDK9524GPTCDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CSDK9524GPTCDlg::OnGPTCNoSelchange() { // TODO: Add your control notification handler code here int nIndex; nIndex = m_cbGPTCNo.GetCurSel(); switch( nIndex ) { case 0: m_wGPTCNo = P9524_CTR_QD0; break; case 1: m_wGPTCNo = P9524_CTR_QD1; break; case 2: m_wGPTCNo = P9524_CTR_QD2; break; } } void CSDK9524GPTCDlg::OnGPTCMode0Start() { // TODO: Add your control notification handler code here I16 err; CString strTmp; if( m_bRunning0 == 1 ) { err = GPTC_Control(m_hCard, m_wGPTCNo, P9524_CTR_Enable, 0); err = GPTC_Clear(m_hCard, m_wGPTCNo); if( m_nTimer0 != NULL ) { KillTimer( m_nTimer0 ); m_nTimer0 = NULL; } m_bRunning0 = 0; SetDlgItemText( IDC_BT_MODE0, TEXT("Start") ); } else { if( m_nTimer0 == NULL ) { m_nTimer0 = SetTimer( TIMER_GPTC_MAJOR_MODE0, 20, NULL ); } /*Setup GPTC*/ err = GPTC_Setup(m_hCard, m_wGPTCNo, m_GPTCMode, 0, 0, 0, 0); if( err<0 ) { strTmp.Format( TEXT("GPTC_Setup Error: %d"), err ); AfxMessageBox( strTmp ); return; } /*Enable Counter*/ err = GPTC_Control(m_hCard, m_wGPTCNo, P9524_CTR_Enable, 1); if(err<0) { strTmp.Format( TEXT("GPTC_Control Error: %d"), err ); AfxMessageBox( strTmp ); return; } m_bRunning0 = 1; SetDlgItemText( IDC_BT_MODE0, TEXT("Stop") ); } } void CSDK9524GPTCDlg::OnTimer(UINT_PTR nIDEvent) { I16 err; U32 dwGPTC_Val; // TODO: Add your message handler code here and/or call default switch( nIDEvent ) { case TIMER_GPTC_MAJOR_MODE0: err = GPTC_Read(m_hCard, m_wGPTCNo, &dwGPTC_Val); SetDlgItemInt( IDC_EDIT_STATUS0, (UINT)dwGPTC_Val); break; } CDialog::OnTimer(nIDEvent); }