CtrlClear Example

InstallShield 2019 » InstallScript Language Reference

Note • To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the CtrlClear, CtrlGetText, and CtrlSetText

* functions.

*

* This example script displays a custom dialog that contains

* edit boxes for a user name, company name, and serial number.

* It also contains three buttons: Clear All, Done, and Cancel.

* On initialization of the dialog, the script calls

* CtrlSetText to place default text into each edit control.

*

* Button Operations

*

* Clear All      Calls CtrlClear to clear all edit boxes.

*

* Done           Calls CtrlGetText to retrieve edit box values.

*                If all fields contain data, the dialog

*                closes and the values from the edit boxes are

*                displayed in a message box.

*

* Cancel         Closes the dialog.  Edit box values are

*                not retrieved or displayed.

*

* The "custom" dialog used in this script is actually the

* Sd dialog that is displayed by the built-in function

* SdRegisterUserEx. Because this dialog is stored

* in the file _isres.dll, which is already compressed in

* the installation, it can be used in a script as a custom

* dialog.

*

\*--------------------------------------------------------------*/

 

// Initial values to display in the edit boxes.

#define USER_NAME    "Your Name"

#define COMPANY_NAME "Your Company"

#define SERIAL_NUM   "123"

 

// Dialog and control IDs.

#define RES_DIALOG_ID     12002   // ID of the custom dialog

#define RES_EDIT_NAME       301   // ID of the User Name edit box

#define RES_EDIT_COMPANY    302   // ID of the Company Name edit box

#define RES_EDIT_SERIAL     303   // ID of the Serial Number edit box

#define RES_PBUT_DONE         1   // ID of dialog's Next button

#define RES_PBUT_CANCEL       9   // ID of dialog's Cancel button

#define RES_PBUT_CLEAR       12   // ID of dialog's Back button

 

   STRING szDialogName, svName, svCompany, svSerial;

   NUMBER nResult, nCmdValue;

   BOOL bDone;

   HWND hwndDlg;

 

#include "ifx.h"

 

function OnBegin()

begin

 

   // Specify a name to identify the custom dialog in this installation.

   szDialogName   = "CustomDialog";

 

   // Define the dialog.  Pass a null string in the second parameter

   // to get the dialog from _isuser.dll or _isres.dll.  Pass a null

   // string in the third parameter because the dialog is identified

   // by its ID in the fourth parameter.

   nResult = EzDefineDialog (szDialogName, "", "", RES_DIALOG_ID);

 

   if (nResult < 0) then

      // Report an error; then terminate.

      MessageBox ("Error in defining dialog", SEVERE);

      abort;

   endif;

 

   // Initialize the indicator used to control the loop.

   bDone = FALSE;

 

   // Loop until done.

   repeat

 

      // Display the dialog and return the next dialog event.

      nCmdValue = WaitOnDialog (szDialogName);

 

      // Respond to the event.

      switch (nCmdValue)

 

         case IDCANCEL:

            // The user clicked the window's Close button.

            Do (EXIT);

 

         case DLG_ERR:

            MessageBox ("Unable to display dialog. Setup canceled.", SEVERE);

            abort;

 

         case DLG_INIT:

            // Initialize the back, next, and cancel button enable/disable states

            // for this dialog and replace %P, %VS, %VI with

            // IFX_PRODUCT_DISPLAY_NAME, IFX_PRODUCT_DISPLAY_VERSION, and

            // IFX_INSTALLED_DISPLAY_VERSION, respectively, on control IDs 700-724 and 202.

            hwndDlg = CmdGetHwndDlg(szDialogName);

            SdGeneralInit(szDialogName, hwndDlg, 0, "");

 

            // Set the static text of the buttons.

            CtrlSetText (szDialogName, RES_PBUT_CLEAR, "Clear &All");

            CtrlSetText (szDialogName, RES_PBUT_DONE, "&Done");

 

            // Initialize the edit controls.

            CtrlSetText (szDialogName, RES_EDIT_NAME, USER_NAME);

            CtrlSetText (szDialogName, RES_EDIT_COMPANY, COMPANY_NAME);

            CtrlSetText (szDialogName, RES_EDIT_SERIAL, SERIAL_NUM);

 

         case RES_PBUT_CLEAR:

            // Clear all edit controls.

            CtrlClear (szDialogName, RES_EDIT_NAME);

            CtrlClear (szDialogName, RES_EDIT_COMPANY);

            CtrlClear (szDialogName, RES_EDIT_SERIAL);

 

         case RES_PBUT_DONE:

            // Retrieve the text from edit boxes.

            CtrlGetText (szDialogName, RES_EDIT_NAME, svName);

            CtrlGetText (szDialogName, RES_EDIT_COMPANY, svCompany);

            CtrlGetText (szDialogName, RES_EDIT_SERIAL, svSerial);

 

            // Verify that all three boxes have data.

            if (StrLength (svName) = 0) ||

               (StrLength (svCompany) = 0) ||

               (StrLength (svSerial) = 0) then

                  MessageBox ("All fields must be completed.", WARNING);

            else

               bDone = TRUE;

            endif;

 

        case RES_PBUT_CANCEL:

            // The user clicked the Cancel button.

            Do (EXIT);

       endswitch;

 

   until bDone;

 

   // Close the dialog.

   EndDialog (szDialogName);

 

   // Free the dialog from memory.

   ReleaseDialog (szDialogName);

 

   // If the dialog was closed with the Done button,

   // display the text from the edit controls.

   if (nCmdValue = RES_PBUT_DONE) then

      SprintfBox (INFORMATION, "User Info",

                  "Name: %s\n\nCompany: %s\n\nSerial: %s",

                  svName, svCompany,svSerial);

   endif;

 

end;