OpenFile Dialog Box
I am trying to write an app that will allow the user to open up a file and load it into my program. The file that will be loaded will probably be just a standard .txt file.
I would like to use the Windows standard OpenFile Dialog box, but I am having trouble getting the box to open.
I create a OPENFILENAME testfile, and then pass that to the function GetOpenFileName(&testfile); The window is never displayed, and I am out of ideas. If somebody could please help me that would be great. Thanks in advance.
Have you initialised the members of the OPENFILENAME struct?
Here is one way to do it.
//Common control dialog
CString name=("default") //Default text file
CString path=("C:\\windows\\desktop\\"+name); //Default directory
//The actual meat of the code
//Use TRUE to open FALSE to save
CFileDialog theFileDialog(TRUE,"TXT",path,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,"txt files(*.txt)|*.txt||");
I have tried to initialize the struct, but I am not sure if I have everything in there that I need. Here is my struct
test.hwndOwner = NULL;
test.lpstrFilter = "All Files (*.*)\0*.*\0";
test.lpstrCustomFilter = NULL;
test.nMaxCustFilter = NULL;
test.nFilterIndex = 1;
test.nMaxFile = 256;
test.lpstrFileTitle = NULL;
test.nMaxFileTitle = NULL;
test.lpstrInitialDir = NULL;
test.lpstrTitle = NULL;
test.Flags = OFN_LONGNAMES;
after that I call GetOpenFileName(&test) and I never see my dialog box. Did I forget to initialize something??
You have to initialise the lStructSize member with the size of the struct -
Thanks zen!! I didnt realized that it needed that sizeof(struct) it works now. Would I do the same thing for a Save As dialog box? I am assuming so