📄 three_flutedlg.cpp
字号:
// three_fluteDlg.cpp : implementation file
//
#include "stdafx.h"
#include "three_flute.h"
#include "three_fluteDlg.h"
//
#include "WinIo.h"
#include "conio.h"
//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CThree_fluteDlg dialog
CThree_fluteDlg::CThree_fluteDlg(CWnd* pParent /*=NULL*/)
: CDialog(CThree_fluteDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CThree_fluteDlg)
m_nNum = 1;
m_dwPoint1 = 0;
m_dwPoint2 = 0;
m_dwPoint3 = 0;
m_dwPoint4 = 0;
m_dwPoint5 = 0;
m_dwPoint6 = 0;
m_nCount = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CThree_fluteDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CThree_fluteDlg)
DDX_Text(pDX, IDC_EDT_NUM, m_nNum);
DDX_Text(pDX, IDC_EDIT1, m_dwPoint1);
DDX_Text(pDX, IDC_EDIT2, m_dwPoint2);
DDX_Text(pDX, IDC_EDIT3, m_dwPoint3);
DDX_Text(pDX, IDC_EDIT4, m_dwPoint4);
DDX_Text(pDX, IDC_EDIT5, m_dwPoint5);
DDX_Text(pDX, IDC_EDIT6, m_dwPoint6);
DDX_Text(pDX, IDC_EDIT7, m_nCount);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CThree_fluteDlg, CDialog)
//{{AFX_MSG_MAP(CThree_fluteDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_ACT, OnBtnAct)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CThree_fluteDlg message handlers
BOOL CThree_fluteDlg::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
m_bResult =InitializeWinIo();
_outp(0x378,0x00);//将DATA端口初始化为低电平
m_bS =true;//the status of busy假设为高电平
m_bSP =m_bS;//previous status of busy
//
return TRUE; // return TRUE unless you set the focus to a control
}
void CThree_fluteDlg::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 CThree_fluteDlg::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 CThree_fluteDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CThree_fluteDlg::OnBtnAct()
{
// TODO: Add your control notification handler code here
LARGE_INTEGER Point1,Point2,Point3,Point4,Point5,Point6;
LARGE_INTEGER ret;
LARGE_INTEGER frequence;
//
int busy;
//
UpdateData(TRUE);
//
if(!QueryPerformanceFrequency( &frequence)){
MessageBox("Your computer hardware doesn't support the high-resolution performance counter", "Not Support", MB_ICONEXCLAMATION | MB_OK);
}
//
Point1.QuadPart = frequence.QuadPart * m_dwPoint1/1000000;
Point2.QuadPart = frequence.QuadPart * (m_dwPoint2-m_dwPoint1)/1000000;
Point3.QuadPart = frequence.QuadPart * (m_dwPoint3-m_dwPoint2)/1000000;
Point4.QuadPart = frequence.QuadPart * (m_dwPoint4-m_dwPoint3)/1000000;
Point5.QuadPart = frequence.QuadPart * (m_dwPoint5-m_dwPoint4)/1000000;
Point6.QuadPart = frequence.QuadPart * (m_dwPoint6-m_dwPoint5)/1000000;
//
_outp(0x378, 0x00);//initialize DATA port to low
//
while(true){
busy =_inp(0x379);
busy =busy & 0x80;
this->m_bSP =this->m_bS;
if(busy ==0x80){
m_bS =false;//busy is low level voltage
}
else{
m_bS =true;
}
if( (!m_bS) && m_bSP){//BUSY from high to low
break;//lock the DATA port high, and jump out
}
}
_outp(0x378, 0xff);
//
ret = MySleep( Point1 );
_outp(0x378, 0x00);
this->m_nCount++;
//
ret = MySleep( Point2);
_outp(0x378, 0xff);
this->m_nCount++;
//
ret = MySleep( Point3 );
_outp(0x378, 0x00);
this->m_nCount++;
//
ret = MySleep( Point4);
_outp(0x378, 0xff);
this->m_nCount++;
//
ret = MySleep( Point5);
_outp(0x378, 0x00);
this->m_nCount++;
//
ret = MySleep( Point6);
_outp(0x378, 0xff);
this->m_nCount++;
//
}//OnBtnAct函数结束
BOOL CThree_fluteDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if(this->m_bResult){
ShutdownWinIo();
}
return CDialog::DestroyWindow();
}
LARGE_INTEGER CThree_fluteDlg::MySleep(LARGE_INTEGER Interval)
{
LARGE_INTEGER previous, current, Elapse;
QueryPerformanceCounter( &previous );
current = previous;
while( (current.QuadPart - previous.QuadPart) < Interval.QuadPart )
QueryPerformanceCounter( ¤t );
Elapse.QuadPart = current.QuadPart - previous.QuadPart;
return Elapse;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -