一 控件内容的设置和读取
a)方法一
CString strINCOM1 = _T("COM1");
SetDlgItemText(IDC_COMBO1, strINCOM1);
CString strCoutCOM1 = _T("");
GetDlgItemText(IDC_COMBO1, strCoutCOM1);
MessageBox(strCoutCOM1);
b)方法二
CComboBox* pConboBox = (CComboBox*) GetDlgItem(IDC_COMBO1);
CString strpINCOM1 = _T("COM1");
pConboBox->SetWindowText(strpINCOM1);
CString strpCoutCOM1 = _T("");
pConboBox->GetWindowText(strpCoutCOM1);
MessageBox(strpCoutCOM1);
二 打开文件对话框
CString strType = _T("*|*");
CString strPath = _T("D:\\Dtest7 - EMR\\EMR-Src\\");
CFileDialog file(true, NULL, strPath, OFN_HIDEREADONLY, strType, NULL);//创建文件对象并打开
if(file.DoModal() != IDOK)//显示文件打开对话框
{
MessageBox(_T("ERROR"));
}
CString strPathName = file.GetPathName();
MessageBox(strPathName);
三 读取路径中所有文件名,将文件名添加到Combox Box中
//strPathName 为文件路径,路径返回到上一级路径名
int n = strPathName.ReverseFind('\\');
CString strTempL = strPathName.Left(n);
strTempL = strTempL + _T("\\*.*");
vector<CString> vctFileList;
CString strPathTemp = strTempL;
CString strNamett = _T("");
CFileFind finder;
bool bWorking = finder.FindFile(strPathTemp);
bWorking = finder.FindNextFile(); //路径中的 文件名 第一个和第二个为...不正确 从第三个开始读取
bWorking = finder.FindNextFile();
while(bWorking)
{
bWorking = finder.FindNextFile();
strNamett = finder.GetFileName();
vctFileList.push_back(strNamett);
}
CComboBox* pCb = (CComboBox*) GetDlgItem(IDC_COMBO1);
pCb->ResetContent();
vector<CString>::iterator itvct = vctFileList.begin();
CString strOut;
for(int i = 0; i < vctFileList.size(); i++)
{
strOut = strOut + itvct[i] + _T("\r\n");
pCb->InsertString(i, itvct[i]);
}