MFC控件基本用法

一 控件内容的设置和读取

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]);
	}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值