CtrlSetList Example

InstallShield 2018 » 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 CtrlSetList function.

*

* This example script displays a custom dialog that

* contains a list box.  After the dialog is initialized,

* the script calls CtrlSetList to place a list of

* InstallShield background color constants into the custom dialog’s

* list box.

*

* The user can view the background that corresponds to a

* color constant either by double-clicking the constant or by

* selecting it and clicking the Set button.

*

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

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

* function SdSetupTypeEx.  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. Note that the script changes the dialog's

* static text and disables the Back button to make the dialog

* meet the requirements of the example.

*

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

 

// Dialog controls.

#define RES_DIALOG_ID        12033   // ID of the custom dialog

#define RES_PBUTTON_SET          1   // ID of Next button

#define RES_PBUTTON_DONE         9   // ID of Cancel button

#define RES_PBUTTON_BACK        12   // ID of Back button

#define RES_DIALOG_LISTBOX     401   // ID of edit box.

#define RES_TEXT_ABOVE         710   // ID of text above edit box

#define RES_TEXT_BELOW         711   // ID of text below edit box

 

// Description to display above and below the multi-line edit box.

#define DESC_TEXT_ABOVE "View the background colors that can be produced with InstallShield's predefined constants."

#define DESC_TEXT_BELOW "To change the background color, select a color; then click the Set button. Or double-click the color name."

 

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

#include "Ifx.h"

 

    // Script-defined function to create color list.

    prototype CreateColorList ();

 

    // Script-defined functions to change background color.

    prototype SetBackgroundColor (STRING);

    

export prototype ExFn_CtrlSetList(HWND);

 

function ExFn_CtrlSetList(hMSI)

    STRING szDialogName, svCurSel;

    NUMBER nCmdValue, nResult;

    BOOL   bDone;

    LIST   listBackgroundColors;

    HWND   hwndDlg;

begin

 

    Enable ( BACKGROUND );

    

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

 

    // Call script-defined function to create color list.

    listBackgroundColors = CreateColorList ();

    

    if (listBackgroundColors = LIST_NULL) then

        MessageBox ("Unable to create list of background colors", SEVERE);

        abort;

    endif;

    

    // Initialize indicator used to control the loop.

    bDone = FALSE;

    

    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.

                bDone = TRUE;

            case DLG_ERR:

                MessageBox ("Dialog failed", SEVERE);

                bDone = TRUE;

            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 window title.

                SetWindowText (hwndDlg, "View Program Folders");

 

                //Set the dialog's static text.

                CtrlSetText (szDialogName, RES_TEXT_ABOVE, DESC_TEXT_ABOVE);

                CtrlSetText (szDialogName, RES_TEXT_BELOW, DESC_TEXT_BELOW);

                CtrlSetText (szDialogName, RES_PBUTTON_SET, "&Set");

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

 

                 // Disable the Back button using a call from Winsub.

                _WinSubEnableControl (hwndDlg, RES_PBUTTON_BACK, 0);

 

                // Place the list of colors into the dialog's list box.

                nResult = CtrlSetList (szDialogName, RES_DIALOG_LISTBOX,

                                      listBackgroundColors);

                if (nResult != 0) then

                    // Handle error from CtrlSetList.

                    MessageBox ("Unable to create folder name list.", SEVERE);

                    bDone = TRUE;

                endif;

 

                // Destroy the color list.

                ListDestroy (listBackgroundColors);

            case RES_DIALOG_LISTBOX:

                // If the end user double-clicked a color, display it.

                if (CtrlGetSubCommand (szDialogName) = LISTBOX_ENTER) then

                    CtrlGetCurSel (szDialogName, RES_DIALOG_LISTBOX, svCurSel);

                    SetBackgroundColor (svCurSel);

                endif;

            case RES_PBUTTON_DONE:

                bDone = TRUE;

            case RES_PBUTTON_SET :

                // Display the selected color.

                CtrlGetCurSel (szDialogName, RES_DIALOG_LISTBOX, svCurSel);

                SetBackgroundColor (svCurSel);

        endswitch;

 

    until bDone;

 

end;

 

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

*

* Script-defined functions begin here.

*

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

 

// CreateColorList returns a list of background color constants.

function CreateColorList ()

  LIST listBkColors;

begin

  // Create a list to hold the colors constants;

  listBkColors = ListCreate (STRINGLIST);

 

  // Build the list of color constants.

  if (listBkColors != LIST_NULL) then

    ListAddString (listBkColors, "BK_BLUE", AFTER);

    ListAddString (listBkColors, "BK_GREEN", AFTER);

    ListAddString (listBkColors, "BK_MAGENTA", AFTER);

    ListAddString (listBkColors, "BK_ORANGE", AFTER);

    ListAddString (listBkColors, "BK_RED", AFTER);

    ListAddString (listBkColors, "BK_YELLOW", AFTER);

    ListAddString (listBkColors, "BK_SOLIDBLACK", AFTER);

    ListAddString (listBkColors, "BK_SOLIDBLUE", AFTER);

    ListAddString (listBkColors, "BK_SOLIDGREEN", AFTER);

    ListAddString (listBkColors, "BK_SOLIDMAGENTA", AFTER);

    ListAddString (listBkColors, "BK_SOLIDORANGE", AFTER);

    ListAddString (listBkColors, "BK_SOLIDPINK", AFTER);

    ListAddString (listBkColors, "BK_SOLIDRED", AFTER);

    ListAddString (listBkColors, "BK_SOLIDWHITE", AFTER);

    ListAddString (listBkColors, "BK_SOLIDYELLOW", AFTER);

  endif;

 

  // Return the pointer to the list.

  return listBkColors;

end;

 

// SetBackgroundColor sets the background to the color

// specified by szColor.

function SetBackgroundColor (szColor)

  NUMBER nColor;

begin

  // Determine which color the end user selected.

  if szColor = "BK_BLUE" then

    nColor = BK_BLUE;

  elseif szColor = "BK_GREEN" then

    nColor = BK_GREEN;

  elseif szColor = "BK_MAGENTA" then

    nColor = BK_MAGENTA;

  elseif szColor = "BK_ORANGE" then

    nColor = BK_ORANGE;

  elseif szColor = "BK_RED" then

    nColor = BK_RED;

  elseif szColor = "BK_YELLOW" then

    nColor = BK_YELLOW;

  elseif szColor = "BK_SOLIDBLACK" then

    nColor = BK_SOLIDBLACK;

  elseif szColor = "BK_SOLIDBLUE" then

    nColor = BK_SOLIDBLUE;

  elseif szColor = "BK_SOLIDGREEN" then

    nColor = BK_SOLIDGREEN;

  elseif szColor = "BK_SOLIDMAGENTA" then

    nColor = BK_SOLIDMAGENTA;

  elseif szColor = "BK_SOLIDORANGE" then

    nColor = BK_SOLIDORANGE;

  elseif szColor = "BK_SOLIDPINK" then

    nColor = BK_SOLIDPINK;

  elseif szColor = "BK_SOLIDRED" then

    nColor = BK_SOLIDRED;

  elseif szColor = "BK_SOLIDWHITE" then

    nColor = BK_SOLIDWHITE;

  elseif szColor = "BK_SOLIDYELLOW" then

    nColor = BK_SOLIDYELLOW;

  endif;

 

  // Set the background to the selected color.

  SetColor (BACKGROUND, nColor);

end;