下面的代码有问题:
HANDLE hFile;
DWORD bytesRead;
OPENFILENAME ofn;
DWORD problem;
WCHAR title[260];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = (LPWSTR)title;
ofn.nMaxFile = sizeof(title);
ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == false)
{
problem = CommDlgExtendedError();
return false;
}在GetOpenFileName中,它只是简单地转到problem = CommDlgExtendedError();,而不设置一个对话框。
发布于 2016-03-27 17:22:10
您必须为lpstrFile结构成员分配一个内存,并将nMaxFile设置为其大小。此外,缓冲区的第一个字符应设置为\0,以防止文件名初始化。MSDN示例:
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';https://stackoverflow.com/questions/36250254
复制相似问题