📄 testserial0dlg.cpp
字号:
// TestSerial0Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestSerial0.h"
#include "TestSerial0Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define STRCOM1 L"COM1:"
#define STRCOM2 L"COM2:"
/////////////////////////////////////////////////////////////////////////////
// CTestSerial0Dlg dialog
CTestSerial0Dlg::CTestSerial0Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestSerial0Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestSerial0Dlg)
// 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 CTestSerial0Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestSerial0Dlg)
DDX_Control(pDX, IDC_BUTTON_OPEN2, m_btnopen2);
DDX_Control(pDX, IDC_COMBO_BANDRATE, m_comboBandRate);
DDX_Control(pDX, IDC_EDIT_SERIAL2, m_editSerial2);
DDX_Control(pDX, IDC_EDIT_SERIAL1, m_editSerial1);
DDX_Control(pDX, IDC_BUTTON_OPEN, m_btnopen);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestSerial0Dlg, CDialog)
//{{AFX_MSG_MAP(CTestSerial0Dlg)
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_MESSAGE(WM_READPORT,OnReadPort)
ON_BN_CLICKED(IDC_BUTTON_OPEN2, OnButtonOpen2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestSerial0Dlg message handlers
BOOL CTestSerial0Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
m_comboBandRate.SetCurSel(1);
// TODO: Add extra initialization here
// m_btnopen.SetWindowText(L"埃担罚");
// SetUserDefaultLCID(MAKELANGID(LANG_CHINESE,SUBLANG_ENGLISH_US));
// ::PostMessage(HWND_BROADCAST, WM_WININICHANGE,0, INI_INTL);SUBLANG_CHINESE_SINGAPORE
// SetSystemDefaultLCID(MAKELANGID(LANG_CHINESE,SUBLANG_ENGLISH_US));
// if(!SetUserDefaultLCID(0x0409))
// AfxMessageBox(L"SetUserDefaultLCID faile");
// ::PostMessage(HWND_BROADCAST, WM_WININICHANGE,0, INI_INTL);
// SetSystemDefaultLCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED));
// SetUserDefaultUILanguage(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED));
// if(!SetUserDefaultLCID(0x0404))
// AfxMessageBox(L"SetUserDefaultLCID faile");
// ::PostMessage(HWND_BROADCAST, WM_WININICHANGE,0, INI_INTL);
// SetSystemDefaultLCID(0x0c04);
// if(!SetUserDefaultUILanguage(0x0c04))
// AfxMessageBox(L"SetUserDefaultUILanguage faile");
LANGID ld = GetUserDefaultLangID();
ld = GetUserDefaultLCID();
ld = GetUserDefaultUILanguage();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestSerial0Dlg::OnButtonOpen()
{
CString str,strBandRate;
str.Empty();
m_btnopen.GetWindowText(str);
// MessageBox(str);
m_comboBandRate.GetLBText(m_comboBandRate.GetCurSel(),strBandRate);
DWORD dwBandRate = _ttol(strBandRate.GetBuffer(strBandRate.GetLength()));
if (!str.Compare(L"Open1"))
{
m_com1.OpenPort(STRCOM1,dwBandRate);
// m_com2.OpenPort(STRCOM2,dwBandRate);
m_btnopen.SetWindowText(L"Close1");
}
else
{
m_com1.ClosePort();
// m_com2.ClosePort();
m_btnopen.SetWindowText(L"Open1");
}
// ::SendMessage(HWND_BROADCAST,WM_READPORT,0,0);
// Invalidate();
}
void CTestSerial0Dlg::OnReadPort(WPARAM wParam, LPARAM lParam)
{
THREADPARAM * thparam = (THREADPARAM *)lParam;
TCHAR strwparam[1024];
if(!_tcscmp(STRCOM1,(TCHAR*)thparam->lpvoid))
{
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(LPCSTR)wParam,1024,strwparam,1024);
m_editSerial1.ReplaceSel(strwparam);
}
else if(!_tcscmp(STRCOM2,(TCHAR*)thparam->lpvoid))
{
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(LPCSTR)wParam,1024,strwparam,1024);
m_editSerial2.ReplaceSel(strwparam);
}
}
void CTestSerial0Dlg::OnButtonOpen2()
{
CString str,strBandRate;
str.Empty();
m_btnopen2.GetWindowText(str);
// MessageBox(str);
m_comboBandRate.GetLBText(m_comboBandRate.GetCurSel(),strBandRate);
DWORD dwBandRate = _ttol(strBandRate.GetBuffer(strBandRate.GetLength()));
if (!str.Compare(L"Open2"))
{
// m_com1.OpenPort(STRCOM1,dwBandRate);
m_com2.OpenPort(STRCOM2,dwBandRate);
m_btnopen2.SetWindowText(L"Close2");
}
else
{
// m_com1.ClosePort();
m_com2.ClosePort();
m_btnopen2.SetWindowText(L"Open2");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -