Closing the dialogs

At this point, we have set things so that the main dialog can launch the Options and the About dialogs when the user clicks on a specific control or select a specific menu item. All that is left now is to provide a way to close these secondary dialogs, and provide a way to close the application itself.

Use the Code Finder dialog again to jump back to the ShowDIALOG1Proc function, and locate the %IDCANCEL handler therein. Replace the MSGBOX statement with a DIALOG END statement, as follows:

CASE %IDCANCEL

  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN

    DIALOG END CBHNDL, 0 ' Close the application

  END IF

This change will cause the main dialog (and hence the whole application) to close when the Cancel button is clicked, or the File | Close menu item is selected. The application closes when this occurs because the program resumes execution after the DIALOG SHOW MODAL statement in the ShowDIALOG1 function, which then returns back to PBMAIN. Since PBMAIN contains no other code, the application will automatically close when the END FUNCTION statement is reached.

Now for the secondary dialogs. In the ShowDIALOG2Proc function, replace the MSGBOX statements in the %IDOK and %IDCANCEL handlers as follows:

CASE %IDOK

  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN

    DIALOG END CBHNDL, 1 ' Signal OK (1)

  END IF

 

CASE %IDCANCEL

  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN

    DIALOG END CBHNDL, 0 ' Signal Cancel (0)

  END IF

An finally, in the ShowDIALOG3Proc function, modify the %IDOK handler as follows:

CASE %IDOK, %IDCANCEL

  IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN

    DIALOG END CBHNDL, 0

  END IF

That concludes the creation of the basic framework for our three-dialog application. You can now save the code, compile and run it! Be sure to investigate how easy the secondary dialogs can be opened and closed from the main dialog.

From here, the project would be completed by the addition of the actual "computational" code, however that is beyond the scope of this documentation. Nevertheless, in addition to the pre-built framework code for this project, you will also find the code for the complete application in the PowerBASIC Forms example file set.

If you examine it, you will find the completed application has been built completely on the Graphical User Interface framework code created in this chapter.

 

See Also

Dialog Tutorial

Menu Tutorial