📄 settingsdlg.cpp
字号:
// SettingsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SmsTest.h"
#include "SettingsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSettingsDlg dialog
CSettingsDlg::CSettingsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSettingsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSettingsDlg)
m_strSmsc = _T("");
//}}AFX_DATA_INIT
}
void CSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSettingsDlg)
DDX_Control(pDX, IDC_RATE_LIST, m_ctrlRateList);
DDX_Control(pDX, IDC_COMM_LIST, m_ctrlCommList);
DDX_Text(pDX, IDC_SMSC, m_strSmsc);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSettingsDlg, CDialog)
//{{AFX_MSG_MAP(CSettingsDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSettingsDlg message handlers
BOOL CSettingsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strComm;
/*for(int i=0; i<9; i++)
{
strComm.Format("COM%d", i + 1);
m_ctrlCommList.AddString(strComm);
}
*/
CString sList;
GetAllPortList(sList); //获取计算机端口
m_ctrlRateList.AddString("9600");
m_ctrlRateList.AddString("14400");
m_ctrlRateList.AddString("19200");
m_ctrlRateList.AddString("28800");
m_ctrlRateList.AddString("38400");
m_ctrlRateList.AddString("57600");
m_ctrlRateList.AddString("115200");
if(m_strPort.IsEmpty()) m_strPort="COM1";
if(m_strRate.IsEmpty()) m_strRate="9600";
m_ctrlCommList.SelectString(-1, m_strPort);
m_ctrlRateList.SelectString(-1, m_strRate);
this->SetIcon(AfxGetApp( )->LoadIcon (IDR_MAINFRAME),false);//标题栏加入图标
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSettingsDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
int nSel;
nSel = m_ctrlCommList.GetCurSel();
if(nSel > -1) m_ctrlCommList.GetLBText(nSel, m_strPort);
nSel = m_ctrlRateList.GetCurSel();
if(nSel > -1) m_ctrlRateList.GetLBText(nSel, m_strRate);
if(m_strPort.IsEmpty() || m_strRate.IsEmpty() || m_strSmsc.IsEmpty())
{
AfxMessageBox("请正确设置端口和SMSC!");
return;
}
CDialog::OnOK();
}
//获得计算机端口的程序
WORD CSettingsDlg::GetAllPortList(CString &sList)
{
CString str;
HKEY hKey;
str=_T("HARDWARE\\DEVICEMAP\\SERIALCOMM");
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, str,0,KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
{
RegCloseKey( hKey );
return 0;
}
TCHAR achClass[MAX_PATH] = _T(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cValues; // number of values for key
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time
TCHAR achValue[MAX_PATH];
DWORD cchValue = MAX_PATH;
BYTE achBuff[80];
DWORD chValue = 60;
DWORD type = REG_SZ;
// Get the class name and the value count.
if(RegQueryInfoKey(hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime)!=ERROR_SUCCESS) // last write time
{
RegCloseKey( hKey );
return 0;
}
if (cValues)
{
for (DWORD j = 0, retValue = ERROR_SUCCESS;
j < cValues; j++)
{
chValue = 60;
cchValue = 60;
retValue = RegEnumValue(hKey, j, achValue,
&cchValue,
NULL,
&type, // &dwType,
achBuff, // &bData,
&chValue); // &bcData
if(retValue == ERROR_SUCCESS)
{
sList += (LPTSTR)(achBuff);
m_ctrlCommList.AddString(LPTSTR(achBuff));
}
}
}
RegCloseKey( hKey );
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -