A “wizard” is a GX that uses a series of dialogs, often with different branches depending on selected parameters. Examples include the NEWMAP GX, for creating a new map, and IPJSET GX, for defining projections. It is even possible to call one wizard from another (as NEWMAP calls IPJSET). Wizard dialogs generally have “Back” and “Next” buttons, except for the last dialog, which usually has “Back” and “Finish” buttons. Control may terminate with the last dialog in the series, or be returned to the first dialog. The following is an outline of a simple wizard with two subdialogs, with control returned to the main dialog on completion. There is an “Options” button in the main dialog, which begins the wizard.
Set up some predefined values before the main code block; ensure that the buttons in the resource file contain the same values.
#define BACK 0 #define NEXT 1 #define FINISH 2 #define OPTIONS 1 #define DONE 99 #define MAIN_FORM 100 #define WIZARD1_FORM 101 #define WIZARD2_FORM 102
Put the following “while” structure within the interactive block. The “//--- Set info...” and “//--- Get info...” comments indicate code that has been removed for the sake of brevity.
i = MAIN_FORM; while (i != DONE) { switch (i) { case MAIN_FORM: // Main Dialog has âÂÂOkâ and âÂÂOptionsâ buttons Diag = Create_DGW("MAIN"); // --- Set info.... iD = iRunDialogue_DGW(Diag); if (iD == -1) Cancel_SYS(); // --- Get Info... Destroy_DGW(Diag); if(iD==0) i = DONE; else if(iD==OPTIONS) i = WIZARD1_FORM; break; case WIZARD1_FORM: // Wizard 1 has âÂÂBackâ and âÂÂNextâ buttons Diag = Create_DGW("MAIN"); // --- Set info... iD = iRunDialogue_DGW(Diag); if(iD == -1) { i = MAIN_FORM; break; } // --- Get Info... Destroy_DGW(Diag); if(iD==BACK) i = MAIN_FORM; else if(iD==NEXT) i = WIZARD2_FORM; break; case WIZARD2_FORM: // Wizard 2 has âÂÂBackâ and âÂÂFinishâ buttons Diag = Create_DGW("MAIN"); // --- Set info.... iD = iRunDialogue_DGW(Diag); if(iD == -1) { i = MAIN_FORM; break; } // --- Get Info... Destroy_DGW(Diag); if(iD==BACK) i = WIZARD1_FORM; else if(iD==FINISH) i = MAIN; break; case default: Abort_SYS(âÂÂIâÂÂm lostâÂÂ); } // end while(i!=DONE)
Note that the “Cancel” return from the wizard dialogs returns control to the MAIN form, instead of exiting directly with a Cancel_SYS call. Breaking before the “Set info” commands ensures that no changes are made when the dialog is cancelled out of. Changes made by previous dialogs within the wizard are retained, however.