MFC-GUI常用API
替换
m_comboSNCodeRandom.ResetContent();
m_comboSNCodeRandom.AddString("数字0-9");
m_comboSNCodeRandom.AddString("大写字母A-Z");
m_comboSNCodeRandom.AddString("小写字母a-z");
m_comboSNCodeRandom.InsertString(0, "数字0-9");
m_comboSNCodeRandom.InsertString(1, "大写字母A-Z");
m_comboSNCodeRandom.InsertString(2, "小写字母a-z");
m_comboSNCodeRandom.AddString("数字0-9");
m_comboSNCodeRandom.SetItemData(0, 0);
m_comboSNCodeRandom.AddString("大写字母A-Z");
m_comboSNCodeRandom.SetItemData(1, 1);
m_comboSNCodeRandom.AddString("小写字母a-z");
m_comboSNCodeRandom.SetItemData(2, 2);
int类型转CString
int num = 123;
CString str;
str.Format("%d", num);
double类型转CString
double num = 3.14;
CString str;
str.Format("%f", num);
GetDlgItem(IDC_EDIT_TIP)->SetWindowTextA(strTime + "\r\n" + strErrorMsg);
CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST_LOG);
pListBox->ResetContent();
pListBox->AddString(strLog);
pListBox->ModifyStyle(0, LBS_DISABLENOSCROLL | LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL);
//long lStrWidth = 0;
// CDC* dc = pListBox->GetDC();
// lStrWidth = max(dc->GetTextExtent(strMsg).cx, lStrWidth); // 最长字符串的像素宽度
pListBox->SetHorizontalExtent(400);
pListBox->SetColumnWidth(400);
当ListBox控件的MultiColumn属性为True多列时候
pListBox->SetHorizontalExtent(400);//水平滚动条的滚动范围
pListBox->SetColumnWidth(500); //设置列表框中每列项目的显示宽度
当MultiColumn属性设置为FALSE时,需要进行以下设置:
设置ListBox控件的风格:需要将ListBox控件的风格设置为单列显示的样式。在对话框资源中设置ListBox控件的风格为LBS_STANDARD。
设置ListBox控件的大小:需要为ListBox控件设置适当的大小,使其能够完整显示单列的所有项。
设置ListBox控件的水平滚动条:当MultiColumn属性为FALSE时,ListBox控件的水平滚动条是根据内容长度自动显示或隐藏的,不需要进行额外的设置。
设置ListBox控件的列宽:当MultiColumn属性为FALSE时,不需要设置ListBox控件的列宽。
保存int文件
CString strG;
::GetPrivateProfileString("通信","配置保存路径", "", strG.GetBuffer(256), 256, strHCSMDir+"\\Info.ini");
strG.ReleaseBuffer();
if (strG!="")
{
if (_access(strG, 0)==-1)
{
CreateMultipleDirectory(strG);
}
strHCSMDir = strG;
}
else
{
strHCSMDir += "\\Data";
::CreateDirectory(strHCSMDir, NULL);
}
CString strHCSMDir="";
GetModuleFileName(NULL,strHCSMDir.GetBufferSetLength(256),256);
strHCSMDir.ReleaseBuffer();
int tmp=strHCSMDir.ReverseFind('\\');
strHCSMDir=strHCSMDir.Left(tmp);
strHCSMDir+="\\DATA\\Config";
保存日志
CTime currentTime = CTime::GetCurrentTime();
CString strCurrentDate = currentTime.Format(_T("%Y%m%d"));
// 获取当前日期
//CString currentDate = COleDateTime::GetCurrentTime().Format("%Y-%m-%d");
// 写入日志内容
m_strLogFile.Format(_T("%sMES上传日志.txt"), strCurrentDate);
std::string filePath = __FILE__;
int nLastSlashIndex = filePath.find_last_of("\\/");
if (nLastSlashIndex != std::string::npos)
{
std::string newFilePath = filePath.substr(0, nLastSlashIndex + 1);
filePath = newFilePath;
}
CString cstrFilePath = filePath.c_str() + m_strLogFile;
CStdioFile SFile;
SFile.Open(cstrFilePath, CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
SFile.SeekToEnd();
SFile.WriteString(m_strLog);
SFile.Flush();
SFile.Close();
int文件读写
CString strTemp;
GetPrivateProfileString("临时参数","上传功能","0",strTemp.GetBuffer(256),256,"D:\\临时保存.ini");
strTemp.ReleaseBuffer();
WritePrivateProfileString("临时参数","上传功能",strTemp,"D:\\临时保存.ini");