MFC SDI application: opening documents
-
Hey How do I access the files that I select when I goto "Open" in an MFC built SDI app? What is the string of the path, or how can I then open that file for reading?? AND How can I stop the default "new file" on start up, and get it to wait for a document to be specified to open? Please help a desparate newbie! :) Tim T
-
Hey How do I access the files that I select when I goto "Open" in an MFC built SDI app? What is the string of the path, or how can I then open that file for reading?? AND How can I stop the default "new file" on start up, and get it to wait for a document to be specified to open? Please help a desparate newbie! :) Tim T
-
OK! In your new app, go to the class wizard, select the object ID called "ID_FILE_OPEN". Then click on the COMMAND text in the box marked "Messages". Next, click "Add function" and it'll prompt you to name the function - probably "OnFileOpen". It will generate a member function called OnFileOpen() somewhere in your code, probably as part of your mainframe class. So, you find your OnFileOpen() function, which will be empty except for some comments like "Add your command handler code here". Add some code like this to your OnFileOpen() function: { CString strFilter; CString path; FILE *myfile; CFileDialog MyFileDialog(TRUE, "*.txt", NULL, NULL, "Text file (*.txt)|*.txt" ); /* Display the File Dialog box */ int result = MyFileDialog.DoModal(); /* Return the path (including filename) */ path = MyFileDialog.GetPathName(); /* Open it up */ myfile = fopen(path, "r"); /* etc...*/ } Haven't tested this out but it might be worth a bash. As for your second question, no idea but I've noticed that the behaviour differs between Win9x and Win NT. Hope it helps. Cheers.