Solved

C++ File Dialogs & IO

Posted on 1998-04-15
7
193 Views
Last Modified: 2013-12-26
I've done a bit of Mac Programming, and am a Reasonable  C++ programmer.

How do use the standard Dialog box for the saving and loading of Classes?

For example, in the following class, how would I implement the loadFile, and saveFile methods? Also, please provide the function you would use to initialize the toolbox.

class      myClass
{
      public:
      unknown            loadFile(unknown);
      unknown            saveFile(unknown);

      private:
      string      myString;
      int            myInt;      
};
0
Comment
Question by:rozell
  • 4
  • 3
7 Comments
 

Author Comment

by:rozell
ID: 1291745
Edited text of question
0
 

Author Comment

by:rozell
ID: 1291746
Adjusted points to 150
0
 
LVL 2

Expert Comment

by:roov
ID: 1291747
>how would I implement the loadFile methods?
short numTypes = -1;
SFTypeList typeList;
StandardFileReply reply;
StandardGetFile(nil, numTypes, typeList, &reply);
if (reply.sfGood) {
// user selected a file
 //reply.sfFile is an FSSpec (mac specification record) for the file to load
}

>how would I implement the saveFile methods?
StandardFileReply reply;
StandardPutFile("\pPlease select destination", "\pNo name", &reply);
if (reply.sfGood) {
 //reply.sfFile is an FSSpec (mac specification record) for the saved file
}

>Also, please provide the function you  would use to initialize the toolbox.
static InitToolbox()
{
      InitGraf((Ptr) &qd.thePort);
      InitFonts();
      InitWindows();
      InitMenus();
      TEInit();
      InitDialogs(nil);
      InitCursor();
}
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rozell
ID: 1291748
Good, this gets me the dialog boxes, but how do I output "myString", and "myInt" to the file, and then retrieve them? I guess this is the part that is really stumping me.
0
 
LVL 2

Expert Comment

by:roov
ID: 1291749
Well, now you'd do the following, assuming the variable mySpec containg the FSSpec you've acquired.
1. Create the file, if required:
 anErr = FSpCreate(&mySpec, fileCreator, fileType, smSystemScript);
fileTpye and fileCreator can be any 4-byte constants that are meaningful to you.
2. Open it, and receive a reference to it:
short refNum = 0;
anErr = FSpOpenDF(&mySpec, fsRdWrPerm, &refNum);
form read/write permission.
3. Read /Write using:
long count = size of my buffer;
void* mybuffer = pointer to data
anErr = FSRead(refNum, &count, buffPtr);

and:
anErr = FSWrite(refNum, &count, buffPtr);

repectivly.

4. Close the file using:
anErr = FSClose(refNum);

Hope this fill out the data...
0
 

Author Comment

by:rozell
ID: 1291750
This is working, however it doesn't appear to be a C++ approach to the problem. Typically, when saving things in C++ one wants to be able to stream the data to disk. This way the programmer doesn't need to know everything about the classes he/she wishes to write to disk.

Is it possible to stream the data to disk in this manner, and if so how.
0
 
LVL 2

Accepted Solution

by:
roov earned 200 total points
ID: 1291751
In such case, the auumption must be that you know the File Specification (fspec) of the file you intend to stream to/from.
You originally requested dialogs, so that's what you got.

If you have the fspec, you can write a basic IO class for streaming, though the standard c++ io classes work if you don't need the resource fork.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now