CtrlGetMLEText Example

InstallShield 2024 » 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 CtrlSetMLEText and CtrlGetMLEText functions.

*

* This example script displays a custom dialog that contains

* a multi-line edit box.  The script creates a list of all

* program folders on the target system and then calls

* CtrlSetMLEText to place that list into the dialog's multi-

* line edit box.  The dialog also contains a Save button that

* enables the end user to save the folder names to a text file.

* When that option is selected, the script calls CtrlGetMLEText

* to get the folder names from the multi-line edit box.

*

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

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

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

*

* Notes: The multi-line edit box is defined as read-only

*        in the resource; its contents cannot be edited.

*

*        The script changes the static text of the dialog

*        box's Next button and disables the Back button in order

*        to make the dialog fit the needs of the example.

*

*        The function GetGroupNameList may return an error

*        if the target system is running under a shell other

*        than the Explorer shell.

*

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

 

// Dialog and control IDs.

#define RES_DIALOG_ID        12007   // ID of the custom dialog

#define RES_PBUT_BACK           12   // ID of Next button

#define RES_PBUT_DONE            9   // ID of Cancel button

#define RES_PBUT_SAVE            1   // ID of Back button

#define RES_DIALOG_EDITBOX     301   // ID of edit box

#define RES_TEXT               711   // ID of text above edit box

 

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

#define DESC_TEXT "Click Save to store the list of program folder names in a disk file."

 

// The program names will be saved in the root of the current

// drive if the end user clicks the Save button.

#define FOLDER_LIST_FILE "\\ISExampl.txt"

 

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

#include "Ifx.h"

 

export prototype ExFn_CtrlGetMLEText(HWND);

 

function ExFn_CtrlGetMLEText(hMSI)

    STRING szDialogName;

    NUMBER nCmdValue, nResult;

    BOOL   bSave, bDone;

    LIST   listFolders;

    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 while 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.

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

 

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

                _WinSubEnableControl (hwndDlg, RES_PBUT_BACK, 0);

 

                //Set the dialog's static text.

                CtrlSetText (szDialogName, RES_TEXT, DESC_TEXT);

                CtrlSetText (szDialogName, RES_PBUT_SAVE, "&Save");

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

 

                // Create a string list to store the program folder names.

                listFolders = ListCreate (STRINGLIST);

 

                if (listFolders = LIST_NULL) then

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

                    bDone = TRUE;

                else

                    // Get the folder names into a list.

                    nResult = GetGroupNameList (listFolders);

 

                    if (nResult = 0) then

                        // Put the folder names into the

                        // dialog's multi-line edit box.

                        nResult = CtrlSetMLEText (szDialogName, RES_DIALOG_EDITBOX,

                                                 listFolders);

                    elseif (nResult != 0) then

                        // Handle error from GetGroupNameList or CtrlSetMLEText.

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

                        bDone = TRUE;

                    endif;

 

                    // Destroy the listID string list.

                    ListDestroy (listFolders);

                endif;

            case RES_PBUT_SAVE :

                // Initialize indicator to save program file names.

                bSave = FALSE;

 

                if (AskYesNo("Save list as " + FOLDER_LIST_FILE + "?", YES)) then

                    // Check for existing file.

                    if (Is (FILE_EXISTS, FOLDER_LIST_FILE) = 1) then

                        // Query end user to overwrite existing file.

                        if (AskYesNo ("Overwrite existing " + FOLDER_LIST_FILE +

                                     "?", YES)) then

                            bSave = TRUE;

                        endif;

                    else

                        bSave = TRUE;

                    endif;

                endif;

 

                if bSave = TRUE then

                    // Create a string list to store list from dialog.

                    listFolders = ListCreate (STRINGLIST);

                    

                    if (listFolders = LIST_NULL) then

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

                    else

                        // Get the folder names from the

                        // dialog's multi-line edit box.

                        nResult = CtrlGetMLEText (szDialogName, RES_DIALOG_EDITBOX,

                                                 listFolders);

                        // Save the list to a text file.

                        ListWriteToFile (listFolders, FOLDER_LIST_FILE);

 

                        // Destroy the listID string list.

                        ListDestroy (listFolders);

                    endif;

                endif;

            case RES_PBUT_DONE:

                bDone = TRUE;

        endswitch;

 

    until bDone;

 

    // Close the custom dialog.

    EndDialog (szDialogName);

    

    // Remove the custom dialog from memory.

    ReleaseDialog (szDialogName);

 

end;