?
Solved

Save, Open, Print Dialog Boxes

Posted on 1998-06-02
14
Medium Priority
?
283 Views
Last Modified: 2013-11-19
Hello,
I need some help with getting Save, Open, and Print Dialog Boxes to work in an MFC Dialog based program.  Or if this is not possible please let me know.  Thank You.
0
Comment
Question by:hartman2
[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
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1315936
It's quite possible. Just use CFileDialog and CPrintDialog.

.B ekiM


0
 

Author Comment

by:hartman2
ID: 1315937
I need to know what the actual code has to be.  Because I am not familiar with that function.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1315938
Search the MFC Samples for it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hartman2
ID: 1315939
Where are the MFC Samples
0
 
LVL 23

Expert Comment

by:chensu
ID: 1315940
They come with your Visual C++.
0
 

Author Comment

by:hartman2
ID: 1315941
To bemore clear I have the code but I don't understand how to set
BOOL bOpenFileDialog
to true or false.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1315942
bOpenFileDialog   Set to TRUE to construct a File Open dialog box or FALSE to construct a File Save As dialog box.

0
 

Accepted Solution

by:
MaxP earned 200 total points
ID: 1315943
A simple example, usable, but not very sophisticated:

      HANDLE      FileHandle;
      BYTE*      pBytes;
      CString      FileName;

Now open a FileDialog for "Save As" (1st parameter FALSE)

      CFileDialog FileDialog( FALSE, ".bmp", NULL, NULL,
                        "Bitmap Files (*.bmp)|*.bmp||",
                        NULL );

      if (FileDialog.DoModal() != IDOK) return; // means User pressed "Cancel"

      FileName = FileDialog.GetPathName();

Now you've got your Filename; open the file and get a handle to it.

      FileHandle = CreateFile(FileName,
                        GENERIC_READ | GENERIC_WRITE,
                        (DWORD) 0,
                        (LPSECURITY_ATTRIBUTES) NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        (HANDLE) NULL );

      if (FileHandle == INVALID_HANDLE_VALUE)
      {
            MessageBox("Failed to create file!", "OK", MB_OK);
            return;
      }

Now write your data.
0
 

Author Comment

by:hartman2
ID: 1315944
This is an excellent answer.  Thank you very much.
0
 

Expert Comment

by:MaxP
ID: 1315945
Less than excellent, but thank you anyway. Maybe you should take a look at the documentation for CFileDialog, and its member variables (m_ofn, especially), for a more failsafe and detailed approach.
0
 

Author Comment

by:hartman2
ID: 1315946
MaxP
To save data into the file that is created would I just use the serialize command and then the IOstoring command or is there a better/ easier why to do it.
0
 

Expert Comment

by:MaxP
ID: 1315947
Depends on the kind of data you want to write to your file. Given the FileHandle as in the example above, you might just use WriteFile(FileHandle, etc.). Seems the easiest approach to me if you write e.g. a Bitmap-File.

0
 

Author Comment

by:hartman2
ID: 1315948
I am saving text and numbers to the file.  What should I do in your opinion.
0
 

Expert Comment

by:MaxP
ID: 1315949
I'm really not familiar with serialization, I haven't used it up to now. In my therefore not very expert opinion, it seems a good method for storing objects in a file.
What you seem to be about to do is just store plain data, using your own file format. So, if you're sure about your format (e.g., how will your program know what kind of data is where when it attempts to read the file?), I would probably write it as plain data 'as is'.
I'd recommend to seriously consider the possible variations of reading that file again before deciding how to write it. The data amount shoud be one topic of your considerations, as well as possible write or read errors and how to handle them.
But I'm afraid I can't even guess what could be the best way for you before knowing a few details about your program.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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