CtrlGetCurSel Example

InstallShield 2016 » 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 CtrlGetCurSel and CtrlSetCurSel functions.

*

* This example script displays a custom dialog that has an

* edit box and a list box.  After the dialog is initialized,

* the script places the names of folders that reside in the

* root of the Windows disk into the dialog's list box.  It

* then calls CtrlSetCurSel to make "Windows" the selected folder.

*

* Each time the user selects a folder name from the list box,

* the script calls CtrlGetCurSel to get the selected item so

* that it can be placed into the edit box.  When the dialog

* is closed with the Done button, the currently selected item

* is displayed in a message box.

*

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

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

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

*

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

 

// The folder that will be preselected in the list box.

#define PRESELECTED_FOLDER "windows"

 

// Dialog and control IDs.

#define RES_DIALOG_ID       12008  // 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 RES_DIALOG_EDITBOX    301  // ID of the edit box

#define RES_DIALOG_LISTBOX    401  // ID of the list box

#define RES_STA_DESC          710  // ID of the text at top of dialog

 

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

#include "Ifx.h"

 

export prototype ExFn_CtrlGetCurSel(HWND);

 

function ExFn_CtrlGetCurSel(hMSI)

    STRING  szDialogName, svSelection, szDesc;

    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;

    

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

 

                // Set the window title.

                SetWindowText (hwndDlg, "Select Folder");

 

                // Set the message that appears at the top of the dialog.

                szDesc = "Specify an existing folder from the root of drive "

                         + WINSYSDISK + "\nThen press Next to continue.";

                CtrlSetText (szDialogName,  RES_STA_DESC, szDesc);

 

                // Fill the dialog's list box with the names of all folders

                // that reside in the root of the Windows drive.

                CtrlDir (szDialogName, RES_DIALOG_LISTBOX,

                        WINSYSDISK + "\\*.*", DLG_DIR_DIRECTORY);

 

                // Select the preselected folder.

                CtrlSetCurSel (szDialogName, RES_DIALOG_LISTBOX,

                              PRESELECTED_FOLDER);

 

                // Put the name of the preselected folder into the edit box.

                CtrlSetText (szDialogName, RES_DIALOG_EDITBOX, PRESELECTED_FOLDER);

            case RES_DIALOG_LISTBOX:

                // Get the current listbox selection.

                CtrlGetCurSel (szDialogName, RES_DIALOG_LISTBOX, svSelection);

 

                // Strip off the brackets.

                StrSub (svSelection, svSelection, 1, StrLength(svSelection) - 2);

 

                // Put the current selection in the edit box.

                CtrlSetText (szDialogName, RES_DIALOG_EDITBOX, svSelection);

            case RES_PBUT_BACK:

                bDone = TRUE;

            case RES_PBUT_NEXT:

                // Get the selection from the edit box.

                CtrlGetText (szDialogName, RES_DIALOG_EDITBOX, svSelection);

 

                // Verify that the edit box contains the name of a

                // folder that exists in the root of the Windows disk.

                if Is (PATH_EXISTS, WINSYSDISK + "\\"+ svSelection) then

                    bDone = TRUE;

                else

                    MessageBox ("Folder does not exist.", WARNING);

                endif ;

            case RES_PBUT_CANCEL:

                // The user clicked the Cancel button.

                Do (EXIT);

        endswitch;

 

    until bDone;

 

    // Close the custom dialog.

    EndDialog (szDialogName);

 

    // Remove the custom dialog from memory.

    ReleaseDialog (szDialogName);

 

    // If the edit box was closed with the Done button,

    // display the selected item.

    if (nCmdValue = RES_PBUT_NEXT) then

        MessageBox ("You selected " + svSelection + ".", INFORMATION);

    endif;

 

end;