最近做的项目简单总结一下,因为对MFC不是很熟,所以简单记录一下。
顺便发现可以在VS2017编译的工程,放到VS2012反而有很多编译无法通过。
1、MFC的文件打开框(多字节)
char* cFileName=NULL; //保存文件
void CToolDlg::OnBnClickedSelect()
{
BOOL isOpen = TRUE; //是否打开(否则为保存)
#ifdef WIN32
CString defaultDir = (LPCSTR)"E:\\FileTest"; //默认打开的文件路径
CString fileName = (LPCSTR)""; //默认打开的文件名
CString filter = (LPCSTR)"ALL(*.*)|*.*|文件 (*.bin)|*.bin|文件(*.dfu)|*.dfu|"; //文件过虑的类型
CFileDialog openFileDlg(isOpen, defaultDir, fileName, OFN_HIDEREADONLY | OFN_READONLY, filter, NULL);
openFileDlg.GetOFN().lpstrInitialDir = (LPCSTR)"E:\\FileTest\\test.doc";
#else
CString defaultDir = (LPCWSTR)"E:\\FileTest"; //默认打开的文件路径
CString fileName = (LPCWSTR)""; //默认打开的文件名
CString filter = (LPCWSTR)"ALL(*.*)|*.*|文件 (*.bin)|*.bin|文件(*.dfu)|*.dfu|"; //文件过虑的类型
CFileDialog openFileDlg(isOpen, defaultDir, fileName, OFN_HIDEREADONLY | OFN_READONLY, filter, NULL);
openFileDlg.GetOFN().lpstrInitialDir = (LPCWSTR)"E:\\FileTest\\test.doc";
#endif
INT_PTR result = openFileDlg.DoModal();
//CString filePath = defaultDir + "\\test.doc";
CString filePath;
WCHAR *pwFileName = NULL;
#ifdef WIN32
char *cFileName = NULL;
#else
char cFileName[128] = {0x00};
#endif
if (result == IDOK) {
filePath = openFileDlg.GetPathName();
}
CWnd::SetDlgItemText(IDC_EDIT_file, filePath);
//读取要升级的文件
if (filePath.GetLength()==0)
{
printf("Please select a valid file to upgrade.\r\n");
return;
}
else