?? comset.cpp
字號:
// ComSet.cpp : implementation file
//
#include "stdafx.h"
#include "GpsTest.h"
#include "ComSet.h"
#include "EnumSerial.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComSet dialog
CComSet::CComSet(CWnd* pParent /*=NULL*/)
: CDialog(CComSet::IDD, pParent)
{
//{{AFX_DATA_INIT(CComSet)
//}}AFX_DATA_INIT
m_butOk.SetXButtonStyle(BS_XT_SEMIFLAT);
m_butCancle.SetXButtonStyle(BS_XT_SEMIFLAT);
}
void CComSet::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CComSet)
DDX_Control(pDX, IDC_COMBO_MODEMSEL, m_cmbModemSel);
DDX_Control(pDX, IDC_COMBO_COMRATE, m_cmbComRate);
DDX_Control(pDX, IDC_COMBO_COMNUM, m_cmbComNum);
DDX_Control(pDX, IDOK, m_butOk);
DDX_Control(pDX, IDCANCEL, m_butCancle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CComSet, CDialog)
//{{AFX_MSG_MAP(CComSet)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComSet message handlers
BOOL CComSet::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//添加串口
GetComConfig();
int nItem;
int nCommPort;
CString str;
CArray<SSerInfo,SSerInfo&> asi;
EnumSerialPorts(asi,FALSE/*include all*/);
for (int ii=0; ii<asi.GetSize(); ii++)
{
// str = asi[ii].strFriendlyName;
// if (str.Find("USB") != -1)
// {
str = asi[ii].strPortName;
nItem = m_cmbComNum.AddString(str);
str.MakeUpper();
str.TrimLeft("COM");
nCommPort = atoi((LPCSTR)str);
m_cmbComNum.SetItemData(nItem,nCommPort);
// }
}
str = "COM" + m_strComNum;
m_cmbComNum.SelectString(-1, str);
//添加波特率
int nItem1;
CString str1;
int rate;
rate = 300;
for (int j=0; j<4; j++)
{
str1.Format("%d",rate);
nItem1 = m_cmbComRate.AddString(str1);
m_cmbComRate.SetItemData(nItem1,rate);
rate *= 2;
}
rate = 9600;
for (int i=0; i<3; i++)
{
str1.Format("%d",rate);
nItem1 = m_cmbComRate.AddString(str1);
m_cmbComRate.SetItemData(nItem1,rate);
rate *= 2;
}
rate = 57600;
str1.Format("%d",rate);
nItem1 = m_cmbComRate.AddString(str1);
m_cmbComRate.SetItemData(nItem1,rate);
rate = 115200;
str1.Format("%d",rate);
nItem1 = m_cmbComRate.AddString(str1);
m_cmbComRate.SetItemData(nItem1,rate);
m_cmbComRate.SelectString(-1, m_strComRate);
//添加模塊選擇
int nItem2;
nItem2 = m_cmbModemSel.AddString("單Modem");
m_cmbModemSel.SetItemData(nItem2, 0);
nItem2 = m_cmbModemSel.AddString("Modem池");
m_cmbModemSel.SetItemData(nItem2, 1);
if (m_strModemSel == "0")
m_cmbModemSel.SelectString(-1, "單Modem");
else
m_cmbModemSel.SelectString(-1, "Modem池");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CComSet::OnOK()
{
// TODO: Add extra validation here
int nItem1, nItem2, nItem3;
int nCommPort;
int nComRate;
int nModemSel;
nItem1 = m_cmbComNum.GetCurSel();
nItem2 = m_cmbComRate.GetCurSel();
nItem3 = m_cmbModemSel.GetCurSel();
nCommPort = m_cmbComNum.GetItemData(nItem1);
nComRate = m_cmbComRate.GetItemData(nItem2);
nModemSel = m_cmbModemSel.GetItemData(nItem3);
m_strComNum.Format("%d", nCommPort);
m_strComRate.Format("%d", nComRate);
m_strModemSel.Format("%d", nModemSel);
SetComConfig();
CDialog::OnOK();
}
int CComSet::GetComConfig(void)
{
CString section;
CString strConfigFileName;
char cStore1[16];
char cStore2[16];
char cStore3[16];
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "COMSET";
GetPrivateProfileString(section, "ComNumber", "1", cStore1, 16, strConfigFileName);
GetPrivateProfileString(section, "ComRate", "115200", cStore2, 16, strConfigFileName);
GetPrivateProfileString(section, "ModemSel", "0", cStore3, 16, strConfigFileName);
m_strComNum = cStore1;
m_strComRate = cStore2;
m_strModemSel = cStore3;
return 0;
}
int CComSet::SetComConfig(void)
{
CString section;
CString strConfigFileName;
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "COMSET";
WritePrivateProfileString(section, "ComNumber", m_strComNum, strConfigFileName);
WritePrivateProfileString(section, "ComRate", m_strComRate, strConfigFileName);
WritePrivateProfileString(section, "ModemSel", m_strModemSel, strConfigFileName);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -