调用以下函数后,我无法写入任何文件,但我尝试过c++ fstream和c的fopen出了什么问题,请提前帮助
我正在使用代码块mingw Windows 7

string openFileDialog(HWND hwnd,char *fileFilter,char *defaultExtension)
{
    string fileName = "";
    OPENFILENAME ofn;
    char szFileName[MAX_PATH] = "";
    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFilter = fileFilter;
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = defaultExtension;

    if(GetOpenFileName(&ofn)) {
        fileName.assign(szFileName);
    }

    ZeroMemory(&ofn, sizeof(ofn));
    return fileName;
}

最佳答案

如果您在对话框中更改文件夹,它将更改您当前进程的文件夹-尝试添加OFN_NOCHANGEDIR标志。

07-24 15:53