// CSSMPDlg.cpp : implementation file // #include "stdafx.h" #include "COSSAMP.h" #include "CSSMPDlg.h" #include "COSTHRD.h" #include "ACCES32.h" #include "Win32COS.h" CCOSTHRD *thread; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCOSSampDlg dialog CCOSSampDlg::CCOSSampDlg(CWnd* pParent /*=NULL*/) : CDialog(CCOSSampDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCOSSampDlg) m_StatusLabel = _T("Set Base, IRQ and Bus Info, then Initialize"); m_BusNumber = 0; m_BusType = _T(""); m_IRQCount = _T("IRQ Count: 0"); m_Data = _T("000000 000000"); m_IRQ = 0; m_BaseAddress = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCOSSampDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCOSSampDlg) DDX_Control(pDX, IDC_STARTBUTTON, m_StartButton); DDX_Control(pDX, IDC_ABORTBUTTON, m_AbortButton); DDX_Text(pDX, IDC_STATUS, m_StatusLabel); DDX_Text(pDX, IDC_BNEDIT, m_BusNumber); DDX_CBString(pDX, IDC_BTCOMBO, m_BusType); DDX_Text(pDX, IDC_COUNT, m_IRQCount); DDX_Text(pDX, IDC_DATA, m_Data); DDX_Text(pDX, IDC_IRQ, m_IRQ); DDV_MinMaxByte(pDX, m_IRQ, 0, 15); DDX_Text(pDX, IDC_BASE, m_BaseAddress); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCOSSampDlg, CDialog) //{{AFX_MSG_MAP(CCOSSampDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_INITBUTTON, OnInitbutton) ON_BN_CLICKED(IDC_EXITBUTTON, OnExitbutton) ON_BN_CLICKED(IDC_STARTBUTTON, OnStartbutton) ON_BN_CLICKED(IDC_ABORTBUTTON, OnAbortButton) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCOSSampDlg message handlers BOOL CCOSSampDlg::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 if (InPortB(0x61) == 0xAA55) { MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", MB_OK); } // TODO: Add extra initialization here m_AbortButton.EnableWindow(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 CCOSSampDlg::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 CCOSSampDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } // Note: Everything before this point was created by Visual C++ void CCOSSampDlg::OnExitbutton() { exit(0); } void CCOSSampDlg::OnInitbutton() { short BT = InterfaceTypeUndefined; unsigned long Base; UpdateData(true); if (m_BusType == "PCI") BT = PCIBus; else if (m_BusType == "ISA") BT = Isa; sscanf(m_BaseAddress, "%lx", &Base); bool success = InitCOSDriver(Base, m_IRQ, BT, m_BusNumber); if (!success) m_StatusLabel = "Driver Error During Initialization"; else m_StatusLabel = "Press Start Acquisition"; UpdateData(false); } void CCOSSampDlg::OnStartbutton() { thread = (CCOSTHRD*)AfxBeginThread(RUNTIME_CLASS(CCOSTHRD),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL); thread->InitWnd(m_hWnd); thread->ResumeThread(); m_AbortButton.EnableWindow(true); m_StartButton.EnableWindow(false); } void CCOSSampDlg::OnAbortButton() { thread->Terminated = true; AbortCOSRequest(); m_StatusLabel = "Aborted - press Start Acquisition to resume"; m_AbortButton.EnableWindow(false); m_StartButton.EnableWindow(true); UpdateData(false); }