(Resending using Courier font; hopefully more readable. Mitch)
Here's some help (I hope). Create a starter program with a simple form with
a button. Have the button execute the code in step #3 below when it is
tapped. This example is highly simplified to show you how the Progress
manager works in a very basic way. Once you understand this, the SDK should
make more sense. The code was cut & pasted from a program I wrote but I had
to edit it somewhat to make this example. Please let me know if you have
any problem running it. By the way, the code I'm providing was written with
Gnu C Compiler in mind.
Good luck!
Mitch
1) Include a reference to Progress.h in your program. You'll need to refer
to structures named PrgCallbackData and ProgressPtr that are defined in
Progress.h.
2) You'll need a callback function. The following callback will let your
program display a series of six progress messages while your progress is
running. You are not stuck with these messages. You can play around with
the code and have any messages you want displayed. The "stage" value is
sent to this function via the PrgCallbackData structure which you populate
in the PrgUpdateDialog function. It gives you a way to decide what message
you want to display.
/* Callback function start
*********************************************************/
static Boolean MyCallback (PrgCallbackData *callbackData)
{
#ifdef __GNUC__ // I need this because I am using GCC.
CALLBACK_PROLOGUE
#endif
if (callbackData->stage == 1)
StrCopy (callbackData->textP, "Stage 1");
if (callbackData->stage == 2)
StrCopy (callbackData->textP, "Stage 2");
if (callbackData->stage == 3)
StrCopy (callbackData->textP, "Stage 3");
if (callbackData->stage == 4)
StrCopy (callbackData->textP, "Stage 4");
if (callbackData->stage == 5)
StrCopy (callbackData->textP, "Stage 5");
if (callbackData->stage == 6)
StrCopy (callbackData->textP, "Done!");
#ifdef __GNUC__
CALLBACK_EPILOGUE
#endif
return (true); // See the SDK. Need to return "true" in most cases.
}
/* End of callback function
****************************************************/
3) Have the following code execute when you tap the form button. As the
progess dialog is updated it will display a series of messages and end with
"Done!". I think in most instances you will want to make the dialog
disappear automatically as soon as your process ends, but in this case I
leave it up. Tap the cancel button to get rid of it.
/* start of function
****************************************************************/
EventType event;
ProgressPtr pPrg;
Word wStage = 0;
Boolean booDone = false;
// Start the progress dialog. Identifies the callback function.
pPrg = PrgStartDialog ("Work in progress....", * MyCallback);
// Here is the "event loop" that the SDK refers to.
// Within the loop you check for events. If no event is in the queue,
// you drop into a sub-loop and do some work. If there is an event,
// you pass it to the PrgHandleEvent function. In this example, a
// likely event that will be passed to it will be a tap on the "cancel"
// button on the progress dialog. If there's a system event,
// PrgHandleEvent will hand it off to the system event manager.
while (!booDone)
{
EvtGetEvent (&event, 50); // checks for an event every 1/2 second.
if ((event.eType == nilEvent) && (wStage < 6))
{
// This is where your long running process would do some work.
// In this case, I'm not doing anything other than updating the
// progress dialog. You might have to do some clever thinking to
// reorganize the flow of your process so it can be broken up into
chunks.
wStage++; // Creating a value for stage that we can pass to the
callback.
// Next populate the PrgCallbackData data structure. The SDK talks
// about the parameters in a straightforward way so I won't
// go into them here.
PrgUpdateDialog (pPrg, 0, wStage, NULL, false);
// This will call your callback function and do the actual update
of the dialog.
PrgHandleEvent (pPrg, &event);
}
else
{
// If you tap on the cancel button on the progress dialog, it will
be handled here.
PrgHandleEvent (pPrg, &event);
if (PrgUserCancel (pPrg))
{
PrgStopDialog (pPrg, true); // Erase the progress dialog.
booDone = !booDone;
}
}
}
/* End of function ****************************************************/