1、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/ Implementationprotected: /AFX_MSG(CAboutDl
2、g) /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog) /AFX_MSG_MAP(CAboutDlg)
3、/ No message handlers /AFX_MSG_MAPEND_MESSAGE_MAP()/ CSerilDlg dialogCSerilDlg:CSerilDlg(CWnd* pParent /*=NULL*/) : CDialog(CSerilDlg:IDD, pParent) /AFX_DATA_INIT(CSerilDlg) m_strRXData = _T(); m_strTXData = _T( m_TestFlag = _T( / Note that LoadIcon does not require a subsequent DestroyIcon in Win32
4、 m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CSerilDlg: /AFX_DATA_MAP(CSerilDlg) DDX_Control(pDX, IDC_OPENSERIL, m_Opensril); DDX_Control(pDX, IDC_COM, m_serilcom); DDX_Text(pDX, IDC_EDIT_RXDATA, m_strRXData); DDX_Text(pDX, IDC_EDIT_TXDATA, m_strTXData); DDX_Control(pDX, IDC_MSCOMM1, m_ctrlCo
5、mm); DDX_Text(pDX, IDC_TESTFLAG, m_TestFlag);BEGIN_MESSAGE_MAP(CSerilDlg, CDialog) /AFX_MSG_MAP(CSerilDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_CLEAR, OnClear) ON_BN_CLICKED(IDC_CLEARSEND, OnClearsend) ON_CBN_CLOSEUP(IDC_COM, OnCloseupCom) ON_BN_CLICKED(IDC_FASONG
6、, OnFasong) ON_BN_CLICKED(IDC_OPENSERIL, OnOpenseril)/ CSerilDlg message handlersBOOL CSerilDlg:OnInitDialog()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 AppendMenu(MF_SE
7、PARATOR);AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); / Set the icon for this dialog. The framework does this automatically / when the applications 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
8、 return TRUE; / return TRUE unless you set the focus to a controlOnSysCommand(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
9、 the icon. For MFC applications using the document/view model,/ this is automatically done for you by the framework.OnPaint() if (IsIconic() CPaintDC dc(this); / device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); / Center icon in client rectangle int cxIcon = Ge
10、tSystemMetrics(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);OnPaint();/ The system calls this to obtain the cursor to display while
11、 the user drags/ the minimized window.HCURSOR CSerilDlg:OnQueryDragIcon() return (HCURSOR) m_hIcon;BEGIN_EVENTSINK_MAP(CSerilDlg, CDialog) /AFX_EVENTSINK_MAP(CSerilDlg) ON_EVENT(CSerilDlg, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE) /AFX_EVENTSINK_MAPEND_EVENTSINK_MAP()OnComm() Add your control n
12、otification handler code here VARIANT variant_inp; COleSafeArray safearray_inp; LONG len,k; BYTE rxdata20480,rxtemp20480=0,top20480,down20480,jm20480,jm120480; /设置BYTE数组 An 8-bit integerthat is not signed. CString strtemp,test,test1; if (m_ctrlComm.GetCommEvent() = 2) /事件值为2表示接收缓冲区内有字符 / CString rw=
13、rw; /以下你可以根据自己的通信协议加入处理代码 variant_inp = m_ctrlComm.GetInput(); /读缓冲区 safearray_inp = variant_inp; /VARIANT型变量转换为ColeSafeArray型变量 len = safearray_inp.GetOneDimSize(); /得到有效数据长度 for(k = 0;k len;k+) safearray_inp.GetElement(&k,rxdata+k);/转换为BYTE型数组 if(rxdata0 = r&rxdata1 = erxdata2 = crxdata3 = irxdata
14、4 = vrxdata5 = ) m_TestFlag = 已被成功接收 else m_ctrlComm.SetOutput(COleVariant(recive); for (k=0;k 1000#pragma once#endif / _MSC_VER class CSerilDlg :/ Construction CSerilDlg(CWnd* pParent = NULL); / standard constructor /AFX_DATA(CSerilDlg) enum IDD = IDD_SERIL_DIALOG ; CButton m_Opensril; CComboBox m_
15、serilcom; CString m_strRXData; CString m_strTXData; CMSComm m_ctrlComm; CString m_TestFlag; /AFX_VIRTUAL(CSerilDlg) HICON m_hIcon; / Generated message map functions /AFX_MSG(CSerilDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HC
16、URSOR OnQueryDragIcon(); afx_msg void OnClear(); afx_msg void OnClearsend(); afx_msg void OnCloseupCom(); afx_msg void OnFasong(); afx_msg void OnComm(); afx_msg void OnOpenseril(); DECLARE_EVENTSINK_MAP()/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif / !defined(AFX_SERILDLG_H_1B
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1