Reputation: 1
I have a question about the GetOpenFileName()
dialog. What is the flag that I should use to prevent the user from typing a non-existing file and open it? I would like to see a warning message stating that the file does not exist.
According to Microsoft's docs, the OFN_FILEMUSTEXIST
flag should display the message, but it doesn't work in my code. What is missing in the code below?
void openfile(){
ZeroMemory(&opn, sizeof(OPENFILENAME));
opn.lStructSize = sizeof(OPENFILENAME);
opn.hwndOwner = hWnd;
opn.lpstrFile = tz1;
opn.nMaxFile = sizeof(tz1);
opn.lpstrFilter = "JPG - JPEG File\0*.JPG\0TIF - TIFF File\0*.TIF\0PNG File\0*.PNG\0BMP - Bitmat File\0*.BMP\0";
opn.nFilterIndex = 1;
opn.lpstrFileTitle = NULL;
opn.nMaxFileTitle = 0;
opn.lpstrInitialDir = NULL;
opn.hInstance = hInstance;
opn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST|OFN_NOVALIDATE;
bfile=GetOpenFileName(&opn);
}
Upvotes: 0
Views: 375