// Sample0Dlg.cpp : implementation file // #include "stdafx.h" #include "Sample0.h" #include "Sample0Dlg.h" #include "acces32.h" int Address; bool TimerEnabled = false; CString PortPanels[3] = {"","",""}; int current = 0xfffe; unsigned char i = 0; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define InsCR(x) x += 0x0d; x += 0x0a; ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg dialog CSample0Dlg::CSample0Dlg(CWnd* pParent /*=NULL*/) : CDialog(CSample0Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CSample0Dlg) m_PortLabel0 = _T("0000000000000000"); m_PortLabel1 = _T("0000000000000000"); m_PortLabel2 = _T("0000000000000000"); m_BaseEdit = _T("300"); m_Instructions = _T("Sample 0"); //}}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_BaseEdit, m_BaseEditCtrl); DDX_Control(pDX, IDOK, m_StartButtonCtrl); DDX_Control(pDX, IDCANCEL, m_ExitButtonCtrl); DDX_Text(pDX, IDC_PortLabel0, m_PortLabel0); DDX_Text(pDX, IDC_PortLabel1, m_PortLabel1); DDX_Text(pDX, IDC_PortLabel2, m_PortLabel2); DDX_Text(pDX, IDC_BaseEdit, m_BaseEdit); DDX_Text(pDX, IDC_Instructions, m_Instructions); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSample0Dlg, CDialog) //{{AFX_MSG_MAP(CSample0Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDCANCEL, OnExitButtonClick) ON_WM_TIMER() ON_BN_CLICKED(IDOK, OnStartTestButtonClick) //}}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 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); } InsCR(m_Instructions); m_Instructions += "This sample writes to each of the IDO-48's input ports' 16 input channels and displays on/off status of what it writes to those channels."; InsCR(m_Instructions); InsCR(m_Instructions); m_Instructions += "Please enter the base address (in hex) in the text box below, and click the 'Start Test' button to begin."; 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::OnExitButtonClick() { exit(0); } // end ExitButtonClick void CSample0Dlg::OnTimer(UINT nIDEvent) { int port, j; unsigned mask; CString ThisString; ThisString = ""; mask = 1; for (j = 0; j <= 15; j++) { ThisString = ((current & mask)?"1":"0") + ThisString; mask <<= 1; } for (port = 0; port <= 2; port++) { PortPanels[port] = ThisString; OutPort(Address + port * 2, current); } current = ~(1<