Solved

C++ File Dialogs & IO

Posted on 1998-04-15
7
215 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
[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
  • 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
Technology Partners: 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: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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 134
sumDigits challenge 9 172
firstChar challenge 13 135
Message not shown 5 87
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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