Code:
// DCMCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DCMC.h"
#include "DCMCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int speedFactor;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDCMCDlg dialog
CDCMCDlg::CDCMCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDCMCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDCMCDlg)
m_speedfact = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDCMCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDCMCDlg)
DDX_Text(pDX, IDC_SF, m_speedfact);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDCMCDlg, CDialog)
//{{AFX_MSG_MAP(CDCMCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_FWD, OnFwd)
ON_BN_CLICKED(IDC_FRW, OnFrw)
ON_BN_CLICKED(IDC_DWN, OnDwn)
ON_BN_CLICKED(IDC_REW, OnRew)
ON_BN_CLICKED(IDC_RWS, OnRws)
ON_BN_CLICKED(IDC_UP, OnUp)
ON_BN_CLICKED(IDC_XIT, OnXit)
ON_BN_CLICKED(IIDC_STP, OnStp)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDCMCDlg message handlers
BOOL CDCMCDlg::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)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
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
return TRUE; // return TRUE unless you set the focus to a control
}
void CDCMCDlg::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 CDCMCDlg::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 CDCMCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDCMCDlg::OnFwd()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++);
{
p = _outp(0x0378,0x03);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}
void CDCMCDlg::OnFrw()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x03);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}
void CDCMCDlg::OnDwn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a>-45) a-=5;
else MessageBox("Minimum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}
}
void CDCMCDlg::OnRew()
{
// TODO: Add your control notification handler code here
int p;
int z = 5000/(2*m_sf);
for(int i=0;i<z;i++)
{
p = _outp(0x0378,0x0C);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
}
void CDCMCDlg::OnRws()
{
// TODO: Add your control notification handler code here
int r;
r = _outp(0x0378,0x0C);
}
}
void CDCMCDlg::OnUp()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(a<45) a+=5;
else MessageBox("Maximum speed limit");
m_speedfact.Format("%d", a);
UpdateData(FALSE);
}
}
void CDCMCDlg::OnXit()
{
// TODO: Add your control notification handler code here
int r;
r = _outp(0x0378,0x00);
OnOK();
}
}
void CDCMCDlg::OnStp()
{
// TODO: Add your control notification handler code here
int r;
r = _outp(0x0378,0x00);
}
}
void CDCMCDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int p;
if((nFlags & MK_LBUTTON) == MK_LBUTTON)
{
p = _outp(0x0378,0x03);
Sleep(50);
p = _outp(0x0378,0x00);
}
CDialog::OnLButtonDown(nFlags, point);
}
void CDCMCDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int p;
if((nFlags & MK_RBUTTON) == MK_RBUTTON)
{
p = _outp(0x0378,0x0C);
Sleep(50);
p = _outp(0x0378,0x00);
}
CDialog::OnRButtonDown(nFlags, point);
}
void CDCMCDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int p;
if((nFlags & MK_LBUTTON) == MK_LBUTTON)
{
p = _outp(0x0378,0x03);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
else if((nFlags & MK_RBUTTON) == MK_RBUTTON)
{
p = _outp(0x0378,0x0C);
Sleep(m_sf + a);
p = _outp(0x0378,0x00);
Sleep(m_sf - a);
}
CDialog::OnMouseMove(nFlags, point);
}