?? 矩陣控制器dlg.cpp
字號:
// 矩陣控制器Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "矩陣控制器.h"
#include "矩陣控制器Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_csReceive = _T("");
m_csSend = _T("");
m_csMon = _T("");
m_csCam = _T("");
m_csCam1 = _T("");
m_csCam2 = _T("");
m_csTime = _T("");
m_csDesk = _T("");
m_csMessage = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pCom=new CSerialCom();
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_BUTTON20, m_Backone2Button);
DDX_Control(pDX, IDC_BUTTON19, m_Addone2Button);
DDX_Control(pDX, IDC_BUTTON18, m_Backward2Button);
DDX_Control(pDX, IDC_BUTTON17, m_Advanced2Button);
DDX_Control(pDX, IDC_BUTTON8, m_Stop2Button);
DDX_Control(pDX, IDC_BUTTON5, m_Backone1Button);
DDX_Control(pDX, IDC_BUTTON4, m_Addone1Button);
DDX_Control(pDX, IDC_BUTTON3, m_Backward1Button);
DDX_Control(pDX, IDC_BUTTON2, m_Advanced1Button);
DDX_Control(pDX, IDC_BUTTON1, m_Stop1Button);
DDX_Control(pDX, IDC_BUTTON6, m_IntoproButton);
DDX_Text(pDX, IDC_RECEIVE_EDIT, m_csReceive);
DDX_Text(pDX, IDC_SEND_EDIT, m_csSend);
DDX_Text(pDX, IDC_MON_EDIT, m_csMon);
DDX_Text(pDX, IDC_CAM_EDIT, m_csCam);
DDX_Text(pDX, IDC_CAM1_EDIT, m_csCam1);
DDX_Text(pDX, IDC_CAM2_EDIT, m_csCam2);
DDX_Text(pDX, IDC_TIME_EDIT, m_csTime);
DDX_Text(pDX, IDC_DESK_EDIT, m_csDesk);
DDX_Text(pDX, IDC_MESSAGE_EDIT, m_csMessage);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
ON_BN_CLICKED(IDC_BUTTON15, OnButton15)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
//為停止1、2設置圖標
HICON hStop = AfxGetApp()->LoadIcon(IDI_STOPBUTTON);
m_Stop1Button.SetIcon(hStop);
m_Stop2Button.SetIcon(hStop);
//為向前1、2設置圖標
HICON hAdvanced = AfxGetApp()->LoadIcon(IDI_ADVANCEDBUTTON);
m_Advanced1Button.SetIcon(hAdvanced);
m_Advanced2Button.SetIcon(hAdvanced);
//為向后1、2設置圖標
HICON hBackward = AfxGetApp()->LoadIcon(IDI_BACKWARDBUTTON);
m_Backward1Button.SetIcon(hBackward);
m_Backward2Button.SetIcon(hBackward);
//為增加1、2設置圖標
HICON hAddone = AfxGetApp()->LoadIcon(IDI_ADDONEBUTTON);
m_Addone1Button.SetIcon(hAddone);
m_Addone2Button.SetIcon(hAddone);
//為后退1、2設置圖標
HICON hBackone = AfxGetApp()->LoadIcon(IDI_BACKONEBUTTON);
m_Backone1Button.SetIcon(hBackone);
m_Backone2Button.SetIcon(hBackone);
//為程控設置圖標
HICON hIntopro = AfxGetApp()->LoadIcon(IDI_INTOPROBUTTON);
m_IntoproButton.SetIcon(hIntopro);
if(!m_pCom->OpenCom())AfxMessageBox(_T("COM口error!"));
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnButton12()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON4)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON5)->EnableWindow(TRUE);
}
void CMyDlg::OnButton7()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON5)->EnableWindow(FALSE);
}
void CMyDlg::OnButton9()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x01';
buffer[1]=atoi(m_csMon);
buffer[2]=atoi(m_csCam);
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %s"),1,m_csMon,m_csCam);
UpdateData(FALSE);
}
void CMyDlg::OnButton10()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x02';
buffer[1]=atoi(m_csCam);
buffer[2]=atoi(m_csDesk);
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %s"),2,m_csCam,m_csDesk);
UpdateData(FALSE);
}
void CMyDlg::OnButton11()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[6];
buffer[0]='\x03';
buffer[1]=atoi(m_csMon);
buffer[2]=atoi(m_csCam1);
buffer[3]=atoi(m_csCam2);
buffer[4]=atoi(m_csTime);
buffer[5]=buffer[1]+buffer[2]+buffer[3]+buffer[4];
m_pCom->WriteCommBlock(buffer,6);
m_csSend.Format(_T("%d %s %s %s %s"),3,m_csMon,m_csCam1,m_csCam2,m_csTime);
UpdateData(FALSE);
}
void CMyDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x04';
buffer[1]=atoi(m_csMon);
buffer[2]='\x00';
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %d"),4,m_csMon,0);
UpdateData(FALSE);
}
void CMyDlg::OnButton2()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x04';
buffer[1]=atoi(m_csMon);
buffer[2]='\x01';
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %d"),4,m_csMon,1);
UpdateData(FALSE);
}
void CMyDlg::OnButton3()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x04';
buffer[1]=atoi(m_csMon);
buffer[2]='\x02';
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %d"),4,m_csMon,2);
UpdateData(FALSE);
}
void CMyDlg::OnButton4()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x04';
buffer[1]=atoi(m_csMon);
buffer[2]='\x03';
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %d"),4,m_csMon,3);
UpdateData(FALSE);
}
void CMyDlg::OnButton5()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x04';
buffer[1]=atoi(m_csMon);
buffer[2]='\x04';
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %d"),4,m_csMon,4);
UpdateData(FALSE);
}
void CMyDlg::OnButton13()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x05';
buffer[1]=atoi(m_csMon);
buffer[2]=atoi(m_csDesk);
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %s"),5,m_csMon,m_csDesk);
UpdateData(FALSE);
}
void CMyDlg::OnButton15()
{
// TODO: Add your control notification handler code here
UpdateData();
char buffer[4];
buffer[0]='\x08';
buffer[1]=atoi(m_csMon);
buffer[2]=atoi(m_csDesk);
buffer[3]=buffer[1]+buffer[2];
m_pCom->WriteCommBlock(buffer,4);
m_csSend.Format(_T("%d %s %s"),8,m_csMon,m_csDesk);
UpdateData(FALSE);
}
void CMyDlg::DisplayString(int m)
{
if (m == 0x3c)
{
m_csReceive = "3c";
m_csMessage = "準備好了!";
UpdateData(FALSE);
}
if (m == 0xc3)
{
m_csReceive = "c3";
m_csMessage = "還沒準備好!";
UpdateData(FALSE);
}
if (m == 0x69)
{
m_csReceive = "69";
m_csMessage = "發送了完整命令!";
UpdateData(FALSE);
}
if (m == 0x96)
{
m_csReceive = "96";
m_csMessage = "沒發送了完整命令!";
UpdateData(FALSE);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -