?
Solved

C++ File Dialogs & IO

Posted on 1998-04-15
7
Medium Priority
?
235 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
Independent Software Vendors: 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 600 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month10 days, 4 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