|
本帖最后由 FSL_TICS_ZP 于 2014-7-2 21:57 编辑
- // practise4Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "practise4.h"
- #include "practise4Dlg.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()
- /////////////////////////////////////////////////////////////////////////////
- // CPractise4Dlg dialog
- CPractise4Dlg::CPractise4Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPractise4Dlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPractise4Dlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CPractise4Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPractise4Dlg)
- DDX_Control(pDX, IDC_COMBO1, m_combo1);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPractise4Dlg, CDialog)
- //{{AFX_MSG_MAP(CPractise4Dlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- 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_exit, Onexit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPractise4Dlg message handlers
- BOOL CPractise4Dlg::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_combo1.SetCurSel(1); //选择第二个串口
- GetDlgItem(IDC_BUTTON3)->EnableWindow(m_openflag);
- GetDlgItem(IDC_BUTTON4)->EnableWindow(m_openflag);
- // port1.InitPort()
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CPractise4Dlg::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 CPractise4Dlg::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 CPractise4Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CPractise4Dlg::OnButton1()
- {
- char buf[1]={'a'};
- if(!m_bSerialPortOpened) //检查串口是否打开
- {
- AfxMessageBox("串口没有打开");
- return;
- }
- // TODO: Add your control notification handler code here
- port1.WriteToPort(buf);
- }
- void CPractise4Dlg::OnButton2()
- {
- // TODO: Add your control notification handler code here
- char buf1[1]={'b'};
- if(!m_bSerialPortOpened) //检查串口是否打开
- {
- AfxMessageBox("串口没有打开");
- return;
- }
- // TODO: Add your control notification handler code here
- port1.WriteToPort(buf1);
- }
- void CPractise4Dlg::OnButton3()
- {
- // TODO: Add your control notification handler code here
- int nPort=m_combo1.GetCurSel()+1; //得到串口号,想想为什么要加1
- if(port1.InitPort(this, nPort, 9600,'N',8,1,EV_RXFLAG | EV_RXCHAR,512))
- {
- port1.StartMonitoring();
- m_bSerialPortOpened=TRUE;
- m_unPort=nPort;
- }
- else
- {
- AfxMessageBox("没有发现此串口或被占用");
- m_bSerialPortOpened=FALSE;
- }
- GetDlgItem(IDC_BUTTON3)->EnableWindow(!m_bSerialPortOpened);
- GetDlgItem(IDC_BUTTON4)->EnableWindow(m_bSerialPortOpened);
- }
- void CPractise4Dlg::OnButton4()
- {
- // TODO: Add your control notification handler code here
- port1.ClosePort();//关闭串口
- m_bSerialPortOpened=FALSE;
- GetDlgItem(IDC_BUTTON3)->EnableWindow(!m_bSerialPortOpened);
- GetDlgItem(IDC_BUTTON4)->EnableWindow(m_bSerialPortOpened);
- }
- void CPractise4Dlg::Onexit()
- {
- // TODO: Add your control notification handler code here
- CDialog::OnCancel();
- }
复制代码 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|