📄 newdlg.cpp
字号:
// NEWDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NEW.h"
#include "NEWDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CNEWDlg dialog
CNEWDlg::CNEWDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNEWDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNEWDlg)
m_LocalCpu1 = _T("");
m_LocalCpu2 = _T("");
m_strCitou = _T("");
m_strReset = _T("");
m_strGudao = _T("");
m_NearCpu1 = _T("");
m_NearCpu2 = _T("");
m_nCpu1 = _T("");
m_nCpu2 = _T("");
m_strTongxin = _T("");
m_GetData = _T("");
m_nUpdatenum = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CNEWDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNEWDlg)
DDX_Text(pDX, IDC_BENCPU1, m_LocalCpu1);
DDX_Text(pDX, IDC_BENCPU2, m_LocalCpu2);
DDX_Text(pDX, IDC_CITOU, m_strCitou);
DDX_Text(pDX, IDC_FUWEI, m_strReset);
DDX_Text(pDX, IDC_GUDAO, m_strGudao);
DDX_Text(pDX, IDC_LINCPU1, m_NearCpu1);
DDX_Text(pDX, IDC_LINCPU2, m_NearCpu2);
DDX_Control(pDX, IDC_MSCOMM1, m_Comm);
DDX_Text(pDX, IDC_QUJIANCPU1, m_nCpu1);
DDX_Text(pDX, IDC_QUJIANCPU2, m_nCpu2);
DDX_Text(pDX, IDC_TONGXIN, m_strTongxin);
DDX_Text(pDX, IDC_GETDATA, m_GetData);
DDX_Text(pDX, IDC_UPDATENUM, m_nUpdatenum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNEWDlg, CDialog)
//{{AFX_MSG_MAP(CNEWDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_RADIO1, OnCom1)
ON_BN_CLICKED(IDC_RADIO2, OnCom2)
ON_BN_CLICKED(IDC_RADIO3, OnCom3)
ON_BN_CLICKED(IDC_RADIO4, OnCom4)
ON_EN_ERRSPACE(IDC_GETDATA, OnErrspaceGetdata)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNEWDlg message handlers
BOOL CNEWDlg::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 CNEWDlg::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 CNEWDlg::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 CNEWDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CNEWDlg::OnSend()
{
// TODO: Add your control notification handler code here]
if(!m_Comm.GetPortOpen())
{
m_Comm.SetPortOpen(TRUE);
if(!m_Comm.GetPortOpen())
AfxMessageBox("你选择的串口不能打开,请重新选择");
else
UpdateData(TRUE);
}
//m_Comm.SetOutput(COleVariant(m_SendData));
}
void CNEWDlg::OnClear()
{
// TODO: Add your control notification handler code here
m_LocalCpu1.Empty();
m_LocalCpu2.Empty();
m_NearCpu1.Empty();
m_NearCpu2.Empty();
m_nCpu1.Empty();
m_nCpu2.Empty();
m_strGudao.Empty();
m_strTongxin.Empty();
m_strReset.Empty();
m_strCitou.Empty();
m_GetData.Empty();
m_nUpdatenum.Empty();
UpdateData(FALSE);
}
BEGIN_EVENTSINK_MAP(CNEWDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CNEWDlg)
ON_EVENT(CNEWDlg, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CNEWDlg::OnComm()
{
// TODO: Add your control notification handler code here
VARIANT m_Input1;
static int seekendflag=0,iupdate=0;
static long maxlength=0,headflag=0;
static BYTE data[1024];
COleSafeArray m_Input2;
register long length,i;
register CString str;
int num1,num2,numa,numb;
BYTE add,iflag;
if(m_Comm.GetCommEvent()==2)
{ m_Input1=m_Comm.GetInput();
m_Input2=m_Input1;
length=m_Input2.GetOneDimSize();
if(maxlength<1024)
{
for(i=0;i<length;i++)
{
m_Input2.GetElement(&i,(&data[maxlength]+i));
str.Format("%4X",data[maxlength+i]);
m_GetData+=str;
}
maxlength+=length;
}
else
{
headflag=0;
maxlength=0;
seekendflag=0;
}
for(i=headflag;((i<(maxlength))&&(!seekendflag));i++)
{
if(data[i]==0x0ff)
{
seekendflag=1;
headflag=i;
}
}
if((maxlength-headflag)>8)
{
iupdate+=1;
numa=(data[headflag+3]&0x0f)*128;
numb=(data[headflag+7]&0x0f)*128;
num1=numa+(data[headflag+2]&0x7f);
num2=numb+(data[headflag+6]&0x7f);
add=data[headflag+1]&0x0003;
iflag=data[headflag+1]&0x00f8;
if(1024<=numa) num1=(num1-2048);
if(1024<=numb) num2=(num2-2048);
str.Format("%4d",data[headflag+4]);
m_nUpdatenum=str;
if((add&0x001)==0x001)
{
str.Format("%04d",num1);
m_LocalCpu1=str;
str.Format("%04d",num2);
m_NearCpu1=str;
str.Format("%04d",abs(num2-num1));
m_nCpu1=str;
}
else
{
str.Format("%04d",num1);
m_LocalCpu2=str;
str.Format("%04d",num2);
m_NearCpu2=str;
str.Format("%04d",abs(num2-num1));
m_nCpu2=str;
}
if((iflag&0x0008)==0x0008)
{
m_strGudao="1";
}
else
{
m_strGudao="0";
}
if((iflag&0x0010)==0x0010)
{
m_strTongxin="1";
}
else
{
m_strTongxin="0";
}
if((iflag&0x0040)==0x0040)
{
m_strCitou="1";
}
else
{
m_strCitou="0";
}
if((data[headflag+3]&0x0020)==0x0020)
{
m_strReset="1";
}
else
{
m_strReset="0";
}
headflag+=8;
seekendflag=0;
if(iupdate>20)
{
CNEWDlg::OnClear();
iupdate=0;
}
}
}
UpdateData(FALSE);
}
void CNEWDlg::OnStop()
{
// TODO: Add your control notification handler code here
m_Comm.SetPortOpen(FALSE);
UpdateData(TRUE);
}
void CNEWDlg::OptionClick(int index)
{
m_Comm.SetCommPort(index);
}
void CNEWDlg::OnCom1()
{
// TODO: Add your control notification handler code here
if(m_Comm.GetPortOpen())
m_Comm.SetPortOpen(FALSE);
UpdateData(TRUE);
int index=1;
OptionClick(index);
}
void CNEWDlg::OnCom2()
{
// TODO: Add your control notification handler code here
if(m_Comm.GetPortOpen())
m_Comm.SetPortOpen(FALSE);
UpdateData(TRUE);
int index=2;
OptionClick(index);
}
void CNEWDlg::OnCom3()
{
// TODO: Add your control notification handler code here
if(m_Comm.GetPortOpen())
m_Comm.SetPortOpen(FALSE);
UpdateData(TRUE);
int index=3;
OptionClick(index);
}
void CNEWDlg::OnCom4()
{
// TODO: Add your control notification handler code here
if(m_Comm.GetPortOpen())
m_Comm.SetPortOpen(FALSE);
UpdateData(TRUE);
int index=4;
OptionClick(index);
}
void CNEWDlg::OnErrspaceGetdata()
{
// TODO: Add your control notification handler code here
m_GetData.Empty();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -