All that remains now is to perform the initial alterations to the code so that the secondary dialogs are launched by user interaction with the main dialog. With the project saved, launch the PowerBASIC for Windows IDE through the Tools menu, or use the CTRL+F7 hot-key.
In the source code file, locate the PBMAIN function using the Code Finder (F2) or by scrolling through the code. Contained in the PBMAIN function will be the following line of code:
Highlight this line and cut it to the clipboard (CTRL+X). Locate the ShowDIALOG1Proc function, and replace the MSGBOX statement in the %IDC_BUTTON1 handler with the ShowDIALOG2 code held in the clipboard (to paste the code in, use the CTRL+V hot-key).
Once that line is moved, replace the %HWND_DESKTOP equate with the CBHNDL system variable. The %IDC_BUTTON1 handler will then look like this:
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
The above change will cause the second project dialog (the Options dialog) to be launched only when the Options button is clicked on the main dialog, or via the File | Options menu item. The CBCTLMSG test ensures that the dialog will only be triggered when a click event (%BN_CLICKED) occurs, and not through some other event, such as the button control gaining or losing focus, etc. Changing the parameter from %HWND_DESKTOP to CBHNDL causes the dialog to act as a child of the main dialog, rather than a child of the desktop window.
Next, cut the ShowDIALOG3 %HWND_DESKTOP line from the PBMAIN function, and paste it into the %IDC_ABOUT handler in the ShowDIALOG1Proc function, and again, replace the %HWND_DESKTOP equate with the CBHNDL system variable. When completed, this handler should look like this:
This change causes the About dialog to be displayed when the About top-level menu item is clicked or selected. This handler does not require a CBCTLMSG test because the handler is associated with a menu item and no other controls. Therefore, this handler will never be triggered by a control notification message, such as may occur when a control loses focus. As before, the CBHNDL change sets the main dialog as the parent of the secondary dialog.
Next Step: Closing the dialogs