The file dialogs are a bit sensitive to the contents of the OPENFILENAME structure. (Note that when you declare a structure its contents are undefined.)
It is best to set the OPENFILENAME structure to all ZEROES to ensure NULLS in all the unused fields.
Put this line immediately after "// Initialize OPENFILENAME" line in your code:
memset(&ofn, 0, sizeof(OPENFILENAME));
This should solve your problem and I recommend you do this with all file dialogs.
BlakJak :]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is the code i use:
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn))
hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
0, (LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
I have tried using OPENFILENAME_SIZE_VERSION_400 but it is not defined, how can i fix this problem?
The file dialogs are a bit sensitive to the contents of the OPENFILENAME structure. (Note that when you declare a structure its contents are undefined.)
It is best to set the OPENFILENAME structure to all ZEROES to ensure NULLS in all the unused fields.
Put this line immediately after "// Initialize OPENFILENAME" line in your code:
memset(&ofn, 0, sizeof(OPENFILENAME));
This should solve your problem and I recommend you do this with all file dialogs.
BlakJak :]
szFile must contain empty string.
strcpy(szFile,"") or szFile[0]=0
The Last Post Worked, THANKS!!
It worked, THANKS!