Solved

C++ File Dialogs & IO

Posted on 1998-04-15
7
212 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
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.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
notReplace  challenge 53 141
move a line in eclipse 3 107
NotAlone Challenge 20 84
Change to event 1 117
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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