CtrlSetState Example

InstallShield 2015 ยป 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 CtrlGetState and CtrlSetState functions.


* This example script displays a custom dialog that contains

* four check boxes.  The script calls CtrlSetState to set the

* first two check boxes to checked.  The last two are unchecked

* by default.  When the end user clicks the Next button, the

* script calls CtrlGetState to retrieve the state of each

* each check box.  The script then displays a message box that

* reports which check boxes were selected.


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

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

* function SdAskOptions.  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.




// Dialog and control IDs.

#define  RES_DIALOG_ID     12020   // ID of the custom dialog

#define  RES_PBUT_NEXT         1   // ID of Next button

#define  RES_PBUT_CANCEL       9   // ID of Cancel button

#define  RES_PBUT_BACK        12   // ID of Back button

#define  ID_OP1_CHECK        501   // ID of Option 1 check box

#define  ID_OP2_CHECK        502   // ID of Option 2 check box

#define  ID_OP3_CHECK        503   // ID of Option 3 check box

#define  ID_OP4_CHECK        504   // ID of Option 4 check box

#define  ID_STA_DESC         711   // ID of static text description



// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"


export prototype ExFn_CtrlSetState(HWND);


function ExFn_CtrlSetState(hMSI)

    STRING  szDialogName, szMsg;

    NUMBER  nResult, nCmdValue, hwndDlg;

    BOOL    bDone;



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

    szDialogName = "ExDialog";


    // 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);




    // Initialize the indicator used to control the loop.

    bDone = FALSE;




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

        nCmdValue = WaitOnDialog (szDialogName);


        // Respond to the event.

        switch (nCmdValue)

            case DLG_CLOSE:

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

                Do (EXIT);

            case DLG_ERR:

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


            case DLG_INIT:

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

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


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

                hwndDlg = CmdGetHwndDlg(szDialogName);

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


                // Set the window title.

                SetWindowText (hwndDlg, "Select Options");


                // Set static text description displayed above check boxes.

                CtrlSetText (szDialogName, ID_STA_DESC,

                            "Select and/or clear options.  Then click Next.");


                // Options are cleared by default, so select Options 1 and 2.

                if (CtrlSetState (szDialogName, ID_OP1_CHECK, BUTTON_CHECKED) < 0) then

                    MessageBox ("First call to CtrlSetState failed.", SEVERE);

                    bDone = TRUE;

                elseif (CtrlSetState(szDialogName, ID_OP2_CHECK, BUTTON_CHECKED) <  0) then

                    MessageBox ("Second call to CtrlSetState failed.", SEVERE);

                    bDone = TRUE;



            case RES_PBUT_NEXT:

                bDone = TRUE;

            case RES_PBUT_CANCEL:

                // The user clicked the Cancel button.

                Do (EXIT);

            case RES_PBUT_BACK:

                bDone = TRUE;



    until bDone;


    // Build message if end user clicked Next button.

    if (nCmdValue = RES_PBUT_NEXT) then

        // Start building the message to display to the end user.

        szMsg = "You selected the following items:\n\n";


        // If first option is selected, add line to message.

        if (CtrlGetState (szDialogName, ID_OP1_CHECK) = BUTTON_CHECKED) then

            szMsg = szMsg + "Option 1\n";



        // If second option is selected, add line to message.

        if (CtrlGetState (szDialogName, ID_OP2_CHECK) = BUTTON_CHECKED) then

            szMsg = szMsg + "Option 2\n";



        // If third option is selected, add line to message.

        if (CtrlGetState (szDialogName, ID_OP3_CHECK) = BUTTON_CHECKED) then

            szMsg = szMsg + "Option 3\n";



        // If fourth option is selected, add line to message.

        if (CtrlGetState (szDialogName, ID_OP4_CHECK) = BUTTON_CHECKED) then

            szMsg = szMsg + "Option 4\n";




    // Close the custom dialog.

    EndDialog (szDialogName);


    // Remove the custom dialog from memory.

    ReleaseDialog (szDialogName);


    // Display message if dialog was closed with Next button.

    if (nCmdValue = RES_PBUT_NEXT) then

        MessageBox (szMsg, INFORMATION);