Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Revisiting the predefined saveas/open dialog box

Posted on 1998-08-18
Medium Priority
Last Modified: 2010-04-01
Question by:kittles
  • 3
LVL 22

Accepted Solution

nietod earned 200 total points
ID: 1170644
Yes!  use CFileDialog.  You aren't asking for any capability that isn't already present in CFileDialog.
LVL 22

Expert Comment

ID: 1170645
You can access the OPENFILENAME structure in the m_ofn member of the CFileDialog object prior to opening the dialog.  In this structure you need to set  the lpstrInitialDir tot he directory you want to default to and lpstrFile to the file name and extension you want to default to.

Let me know if you have questions.

Author Comment

ID: 1170646
(FALSE,  // TRUE for Open or FALSE Save As
                        NULL,  (is this where I insert the m_OFN member?)
                        this);  // the parent window is your dialog box

This is my code. From the help documentation this appears to be where I would modify the m_ofn structures you suggested such as lpstrInitialDir & lpszFileName. Is that correct? If so, and I manage to insert the file name I want and the path.. how then do I remove all of the unwanted elements such as the large window where the user choses the file they want, and leave only an edit box for typing in the file name desired? etc. Do I use  dwflags? My documentations says the following:
"dwFlags   A combination of one or more flags that allow you to customize the dialog box. For a description of these flags, see the OPENFILENAME structure in the Win32 SDK documentation. If you modify the m_ofn.Flags structure member, use a bitwise-OR operator in your changes to keep the default behavior intact."

I do not understand the part about a bitwise or operator, and I do not have any win32 sdk documentation that tells me how to do this. The only thing I can find in the MFC library on OPENFILENAME is the different commands to be used to modify the dialog box. Can I use these in the code above? Or must I do more as they suggest above= with the bitwise operator etc?
Thank you very much for answering so quickly & for your patience!

LVL 22

Expert Comment

ID: 1170647
>> how then do I remove all of the unwanted elements such as the large
>> window where the user choses the file they want, and leave only an
>> edit box for typing in the file name desired?

I didn't realize you wanted to do that.  I beleive that can be done using the lpTemplateName member of the OPENFILENAME structure.  However, I have no experience doing so, if you go really want to go that route you should reject this answer and see what else you can find.  But first consider if that is really a good idea.  Windows tries to present a common interface to the user.  This makes it easier and faster for them to use the software and makes them feel more comfortable.  If you aren't going to follow that interface, you had better have a good reason, one that outweights the issues I just mentioned.

>> I do not understand the part about a bitwise or operator
The | operator is the bitwise or operator.  You can make an integer value that is a combination of flags using | like


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

572 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