?
Solved

Trying to create a "File Open" dialog which is opened in response to a button clicked in a View

Posted on 2003-03-13
3
Medium Priority
?
273 Views
Last Modified: 2010-04-01
Hi,

As the title states -- I have a view (actually several) that I have a button that I hope will open a 'file open' dialog so the user can use it to locate the file he/she is looking for.  I have added the button and used VC++ to map the button click to run the following function:

void CAlbumView::OnAddCover()
{
                                                                                               
        OPENFILENAME ofn;       // common dialog box structure
        char szFile[260];       // buffer for file name
        HWND hwnd = NULL;              // 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;
                                                                                               
// Display the Open dialog box.
                                                                                               
        if (::GetOpenFileName(&ofn)==TRUE)
                hf = CreateFile(ofn.lpstrFile, GENERIC_READ, 0, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
}

(Something I copyed from MSDN)

-- So the problem?

The dialog box never shows.  I am sure the code is beening executed, but nothing is happening...  :{

Anyone have any idea why not?

Nasa
0
Comment
Question by:nasa000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 8133652
Have you tried to call "GetLastError()" after calling "GetOpenFilename()" when the call fails?
0
 
LVL 1

Accepted Solution

by:
yukapapa earned 1000 total points
ID: 8133744
Hi nasa000.

The OPENFILENAME::lpstrFile must point to an initialized string buffer. If the initizlization is not necessary, the first character in the buffer pointed by lpstrFile must be '\0'.

Try to define szFile as char szFile[260] = "".

I could not find out any other problems from your code.

bye.
0
 

Author Comment

by:nasa000
ID: 8133858
Thanks yukapapa,

making the

char szFile[260] = "".


change fixted the problem


Thanks Again
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question