CtrlGetMultCurSel Example

InstallShield 2020 ยป 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 CtrlSetMultCurSel and CtrlGetMultCurSel

* functions.

*

* This script retrieves the names of all program folders

* on the target system and places them in a list.  When the

* dialog is initialized, the CtrlSetList function sets this

* list to be displayed in the list box.  The CtrlSetMultCurSel

* function is then called to highlight the user-selected

* folder.

*

* This list is then destroyed.  A new list is created when the

* Next button is clicked.  CtrlGetMultCurSel then retrieves the

* elements in the list box and assigns them to this new string

* list.  This list is then displayed in an Sd dialog.

*

* Note: In order for this script to run properly, you must set

*       the RES_DIALOG_ID and RES_DIALOG_LISTBOX constants to a

*       dialog and list box created in _isuser.dll.

*

*       The GetGroupNameList function used in this example may

*       return an error if the target system is running under a

*       shell other than Explorer.

*

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

 

// Dialog control IDs.

#define RES_DIALOG_ID                // ID of dialog itself

#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_DIALOG_LISTBOX           // ID of list box

 

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

#include "Ifx.h"

 

    export prototype ExFn_CtrlGetMultCurSel(HWND);

 

function ExFn_CtrlGetMultCurSel(hMSI)

    STRING szDialogName, szDLL, szTitle, szMsg;

    STRING szText, szDefFolder, svResultFolder;

    NUMBER nCmdValue, nResult, nControlID, nSelectFlag;

    BOOL bDone;

    LIST listID, listFolders;

    HWND hwndDlg;

begin

 

    Disable(BACKBUTTON);

 

    szDialogName = "CtrlSetMultCurSel";

    szDLL        = "";

 

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

 

    if (nResult < 0) then

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

        bDone = TRUE;

    else

        bDone = FALSE;

    endif;

 

    // Create the listID string list.

    listID = ListCreate (STRINGLIST);

 

    if (listID = LIST_NULL) then

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

    else

       MessageBox ("listID created.", INFORMATION);

    endif;

 

    // Retrieve the program folder names into a list.

    GetGroupNameList (listID);

 

    // Retrieve a folder name from the user.

    szTitle = "CtrlGetMultCurSel & CtrlSetMultCurSel";

    SelectFolder (szTitle, szDefFolder, svResultFolder);

 

    // Loop until done.

    while (bDone = FALSE)

 

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

        nCmdValue = WaitOnDialog (szDialogName);

        

        // Respond to the event.

        switch (nCmdValue)

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

 

                // The following sets the list box to the list of program folders.

                nControlID = RES_DIALOG_LISTBOX;

                CtrlSetList (szDialogName, nControlID, listID);

 

                szText = svResultFolder;

                nSelectFlag = TRUE;

 

                //Set the user-selected folder to be highlighted.

                if (CtrlSetMultCurSel (szDialogName, nControlID, szText,

                                      nSelectFlag) < 0) then

                    MessageBox ("CtrlSetMultCurSel failed.", SEVERE);

                endif;

 

                // Destroy the listID string list.

                ListDestroy (listID);

                MessageBox ("listID destroyed.", INFORMATION);

            case DLG_CLOSE:

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

                Do (EXIT);

            case RES_PBUT_NEXT:

                // Create the listFolders string list.

                listFolders = ListCreate (STRINGLIST);

 

                if (listFolders = LIST_NULL) then

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

                else

                    MessageBox ("listFolders created.", INFORMATION);

                endif;

 

                // Retrieve the highlighted elements in the list box, and

                // put them into the listFolders string list.

                if (CtrlGetMultCurSel (szDialogName, nControlID,

                                      listFolders) < 0) then

                    MessageBox ("CtrlGetMultCurSel failed.", SEVERE);

                else

                    MessageBox ("CtrlGetMultCurSel successful.", INFORMATION);

                endif;

 

                bDone = TRUE;

            case RES_PBUT_BACK:

                bDone = TRUE;

            case RES_PBUT_CANCEL:

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

                Do (EXIT);

        endswitch;

 

    endwhile;

 

    szMsg   = "The following are the elements highlighted in the list box:";

 

    // Display the list of elements highlighted.

    SdShowInfoList (szTitle, szMsg, listFolders);

    

    // Remove listFolders string list from memory.

    ListDestroy (listFolders);

    MessageBox ("listFolders destroyed.", INFORMATION);

    

    // Close the dialog.

    EndDialog (szDialogName);

    

    // Remove the dialog from memory.

    ReleaseDialog (szDialogName);

 

end;