I tried searching the forum to see if I could find the answer, but I keep getting the following error: "Fatal error: Maximum execution time of 30 seconds exceeded in /www4/codeguru/codeguru/forum/search.php on line 398
"
I also tried searching the net and could not find the info I am looking for, and tried seraching this forum several times but kept getting the error I stated previously.
Anyway, I want to retrieve the file name and path info using the standard Windows Open File dialog, in a dialog based app.
I used the MFC app wizard and created the dialog based app skeleton. I then added the menu resources for File and Open to the dialog, and bound the Open command to an OnFileOpen() function. Now I don't now what to put in this function to get it to do what I want.
I want it to bring up the standard windows Open File Dialog, so that I can browse the files and folders, select the file that I want, and have it return the path and file name info, so I can then open the file for reading and grab some information from the file, etc.
Can anyone help me with this, or provide a link that has this information. And please remeber that I am a newbie to Visual C++, and take that into account when providing any information.
Thanks for the reply. One more thing... I looked it up on MSDN and tried adding it to my code but it is not working (I click on File -> Open and nothing happens, except the form seems to flash once, real quick). I know the Menu item is not the problem, because I tried adding a messagebox to the code just to make sure, and the messagebox did pop up when I clicked on open.
My OS is Windows XP Pro and here is what I did using the information from MSDN.
Added WINDOWS.H, COMMDLG.H, and COMDLG32.LIB to my project.
Added the following code to my OnOpenFile function:
**********************************************
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
Hi tawright915,
Thanks again for the quick reply. Your code works perfectly.
I copied that code staright from MSDN, I wonder why they skipped the code that allows you to choose the file, and went straight to opening the file that you (never) chose.
The link for that code is: MSDN Link Under "Opening a File" (Show Example).
Thanks for correctling the code and adding your comments
If you wouldn't mind one more small question.
I noticed that you did not include WINDOWS.H, and COMMDLG.H and COMDLG32.LIB in your project, and it works fine. Are they automatically included or something? Sorry for all the questions, but I as I stated before, I am new to Visual C++ and am just trying to make sense of it all.
Oops, never mind, I think figured it out. I looked at the StdAfx.h file, and noticed that one of the includes was "MFC support for Windows Common Controls", so I assume that the GetOpenFileName function and realted stuff are probably in there.
Makes sense since it must use that function in the MFC SDI apps.
Anyway, thanks again for the help...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.