我有一个 VS2010 C++ 应用程序,它以非常普通的方式使用 Windows 通用文件对话框。我的公司刚刚将我的工作站更新为带有 Windows 7 的不错的四核 CPU,而我以前的系统仍在运行 XP。当我在 Visual Studio 调试器中运行我的应用程序时,任何调用 CFD 的尝试似乎都会以静默方式失败,代码不会向输出窗口抛出明显错误,也不会出现对话框。在调试器之外,一切正常。我每次都以几乎相同的方式调用对话框。
CString theFilterList = "CSV Import Files (*.csv)|*.csv";
theFilterList = theFilterList + "|All files (*.*)|*.*||";
// construct the common dialog
CFileDialog fileDlg(TRUE, NULL, NULL,OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, theFilterList,this);
POSITION pos;
// Initialize m_ofn structure
fileDlg.m_ofn.lpstrTitle = "Please select a UP supplied CSV file to prepare to load into SCT.";
// Create buffer for file names.
const DWORD bufferSize = (MAX_MULTISELECT_FILENAMES * MAX_FILENAMESIZE) + 1;
TCHAR* filenamesBuffer = new TCHAR[bufferSize];
// Initialize beginning and end of buffer.
filenamesBuffer[0] = NULL;
filenamesBuffer[bufferSize-1] = NULL;
// Attach buffer to OPENFILENAME member.
fileDlg.m_ofn.lpstrFile = filenamesBuffer;
fileDlg.m_ofn.nMaxFile = bufferSize;
if ( fileDlg.DoModal() != IDOK)
{
theCSVFilenameList.RemoveAll();
return;
}
pos = fileDlg.GetStartPosition();
while( pos )
{
theCSVFilenameList.Add(fileDlg.GetNextPathName( pos ));
}