MFC控件基本用法
2015-10-11 16:43
375 查看
一 控件内容的设置和读取
a)方法一
b)方法二
二 打开文件对话框
三 读取路径中所有文件名,将文件名添加到Combox Box中
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]); }
相关文章推荐
- 【Redis基础】SSH 中Spring-data-redis使用体验
- UVA 10277 Boastin' Red Socks
- HDU 3729 最大二分匹配
- 线程中的yield与sleep方法的区别
- 自动化软件测试概述
- ARM裸机开发(四):bootloader的设计
- Android.mk中call all-subdir-makefiles和call all-makefiles-under,$(LOCAL_PATH)的区别(转载)
- srm 550
- 《探索需求》阅读笔记一
- CodeForces 527B(字符串)
- git客户端提交代码到github
- 数据结构实验之栈八:栈的基本操作 SDUT
- Java接口声明对象
- CodeForces 527B(字符串)
- hdoj The Next 5491 (进制转换+技巧)
- 声明变量
- 其实参与QtCreator开发也很容易
- GraphicsMagick
- 【Python】Learn Python the hard way, ex18 def函数
- UVa10817