简体   繁体   中英

winapi openfiledialog c++

I use mingw, c++ I would like to open multiple files, something like this:

OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));

ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "TXT\0"
        "*.txt\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;
ofn.lpstrDefExt = "txt";

But how can I get the filenameS? If I check the szFileName variable, it only contains the folder name.

From the documentation :

If the user selects more than one file, the lpstrFile buffer returns the path to the current directory followed by the file names of the selected files. The nFileOffset member is the offset, in bytes or characters, to the first file name

the directory and file name strings are NULL separated, with an extra NULL character after the last file name.

From your question:

If I check the szFileName variable, it only contains the folder name.

Keep checking one character past the terminating '\\0' .

Each time the following character isn't another '\\0' , that's the start of a new filename.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM