void CWriteWnd::OpenFileDialog()
{
OPENFILENAME ofn;
TCHAR szFile[MAX_PATH] = _T(""); ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = *this;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = NULL;
ofn.nFilterIndex = ;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = ;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; GetOpenFileName(&ofn);//如果用户指定了一个文件名且点击OK按钮,返回值为非零值。如果用户取消或关闭Save对话框或错误出现,返回值为零。
if (GetOpenFileName(&ofn))
{
//std::vector<wstring> vctString(1, szFile);//保存添加文件的路径
}
else
{
DWORD dwError = NOERROR;
dwError = CommDlgExtendedError();
}
}

注:The error codes returned by CommDlgExtendedError are defined in the Cderr.h file.

05-11 10:53