我正在尝试在 C++ 中使用 .NET 类 OpenFileDialog 并遇到一个奇怪的错误。我的基本代码如下。
OpenFileDialog^ openFileDialog = gcnew OpenFileDialog;
openFileDialog->InitialDirectory = "c:\\";
openFileDialog->Filter = "Bitmap|*.bmp|All Files|*.*";
openFileDialog->FilterIndex = 1;
openFileDialog->RestoreDirectory = true;
if (openFileDialog->ShowDialog() == DialogResult::OK)
MessageBox::Show(openFileDialog->FileName, "Information", MessageBoxButtons::OK, MessageBoxIcon::Information);
当代码到达这一点时,对话框将按预期打开。但是,如果我像用户一样切换“文件类型”下拉菜单,对话框窗口中列出的文件和目录就会消失(与过滤器无关)。如果我转到父目录,然后重新输入相同的子目录,则文件和目录会正确显示,并按预期过滤。有谁知道为什么我会得到这个奇怪的错误?
仅供参考,我使用的是 Windows XP 64 位 SP2,使用 Visual Studio 2010 for .NET 4 构建。