CtrlSetText 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 CtrlSetText, CtrlGetText, and CtrlSelectText

* functions.

*

* This example script displays a custom dialog with two

* edit boxes to obtain a user name and company name.  The

* script calls CtrlSetText to place initial values into the

* edit boxes and CtrlSelectText to select the contents of the

* first edit box.  When the user clicks the Next button, the

* script calls CtrlGetText to retrieve the contents of the edit

* boxes so that they can be displayed in a message box after

* the custom dialog is closed.

*

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

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

* function SdRegisterUser.  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     12001   // ID of 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 RES_EDITNAME        301   // ID of edit box

#define RES_EDITCOMPANY     302   // ID of edit box

 

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

#include "Ifx.h"

 

export prototype ExFn_CtrlSetText(HWND);

 

function ExFn_CtrlSetText(hMSI)

    STRING szDialogName, svName, svCompany;

    NUMBER nResult, nCmdValue;

    BOOL   bDone;

    HWND   hwndDlg;

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 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 DLG_CLOSE:

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

 

                // Put initial values into the edit boxes.

                CtrlSetText (szDialogName, RES_EDITNAME, "Your name");

                CtrlSetText (szDialogName, RES_EDITCOMPANY, "Your company");

 

                // Select the Name edit box.

                CtrlSelectText (szDialogName, RES_EDITNAME);

            case RES_PBUT_NEXT:

                // Get the contents of the edit boxes.

                CtrlGetText (szDialogName, RES_EDITNAME, svName);

                CtrlGetText (szDialogName, RES_EDITCOMPANY, svCompany);

 

                // Verify that both edit boxes have data.

                if (StrLength(svName) = 0) || (StrLength(svCompany) = 0) then

                    MessageBox ("Both fields must be completed.", INFORMATION);

                else

                    bDone = TRUE;

                endif;

            case RES_PBUT_CANCEL:

                // The user clicked the Cancel button.

                Do (EXIT);

            case RES_PBUT_BACK:

                bDone = TRUE;

        endswitch;

 

    until bDone;

 

    // Close the dialog.

    EndDialog (szDialogName);

 

    // Remove the dialog from memory.

    ReleaseDialog (szDialogName);

 

    // If dialog is closed with Next button, display name and company.

    if nCmdValue = RES_PBUT_NEXT then

        MessageBox (svName + "\n" + svCompany, INFORMATION);

    endif;

 

end;

See Also