open file dialog box

Started by
13 comments, last by Ferinorius 22 years, 6 months ago
here is what I have to put into my code:

OPENFILENAME ofn;       // common dialog box structure
char szFile[260];       // buffer for filename
HWND hwnd;              // owner window
HANDLE hf;              // file handle

// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
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;
 
but I get 40 plus errors. I know that they MUST originate at the OPENFILENAME ofn; section. I included the proper header files, and still my definition of this structure isn''t working. What is my problem that it gives me dozens of "missing ;" syntax errors even though there is no obvious and stupid errors?

C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(60) : error C2143: syntax error : missing '';'' before ''.''
C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(60) : error C2501: ''ofn'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(60) : error C2371: ''ofn'' : redefinition; different basic types
        C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(45) : see declaration of ''ofn''
C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(60) : error C2143: syntax error : missing '';'' before ''.''
C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(61) : error C2143: syntax error : missing '';'' before ''.''
C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(61) : error C2501: ''ofn'' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\Map Editor\Editor.cpp(61) : error C2371: ''ofn'' : redefinition; different basic types
        
and so on and so on.....
Advertisement
Include commdlg.h.

[Resist Windows XP''s Invasive Production Activation Technology!]
i did, and I also included winuser.h and i even copied the dang code straight from the MSDN library sample to see if it would work and nothing. i seriously doubt that it is Windows XP''s fault as well.
Is there any specific .libs that need to be added beyond WINMM? This is stumping me. It isnt like i really need it or anything, but it sure would be nice!

Neo-Toshi - The City That Never Sleeps

Edited by - Ferinorius on October 1, 2001 10:31:22 PM
Winmm.lib is for the multimedia stuff, you have to link to comdlg32.lib, but that shouldn''t be causing these errors. Wish I could help more.

[Resist Windows XP''s Invasive Production Activation Technology!]
Didn''t you forget to put your code inside some function? Your error messages look like those which you get when trying to write some code outside of any functions - where global variable definitions are written.
I used that exact same code. It compiled and built fine, but no dialog box came up. What''s the problem?
that is aggrivating me. I dont know why it''s not working. Maybe im not supposed to use an open dialoue box right this minute. Heh.

Neo-Toshi - The City That Never Sleeps
Change

char szFile[260]; // buffer for filename

to

char szFile[260] = ""; // buffer for filename

This solves the problem on my computer.
"I used that exact same code. It compiled and built fine, but no dialog box came up. What''s the problem?"

You have to call GetOpenFileName(&ofn) to actually get the Open File dialog box.

This topic is closed to new replies.

Advertisement