MFC笔记

1、CString 与 std::string的相互转换:
1.1:string to CString

string str = "hello world";
CString cstr(str.c_str());

1.2:CString to string

CString theCStr = L"Hello C++";
std::string STDStr(CW2A(theCStr.GetString()));

2、打开文件选择对话框:

void Cpdf2pic3Dlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	CString openfile = _T("pdf文件(.pdf)|*.pdf|");
	CFileDialog fileOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, openfile);
	if (IDOK == fileOpen.DoModal()) {
		CString path = fileOpen.GetPathName();
		//CString filename = fileOpen.GetFileName();
		GetDlgItem(IDC_EDIT1)->SetWindowTextW(path);
	}
}
posted @ 2022-05-10 09:08  icefield817  阅读(30)  评论(0编辑  收藏  举报