CtrlDir 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 CtrlDir function.

*

* This example script displays a file listing in a custom

* dialog.  The directory listing is created by a call to

* CtrlDir, which builds the list and places it into the

* custom dialog's list box control.  The user can then select

* an item from the list with the keyboard or mouse.  If the

* dialog is closed with the Next button, the 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 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.

*

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

 

// Dialog and control IDs.

#define RES_DIALOG_ID        12033   // 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_LISTBOX     401   // ID of list box

#define RES_STA_MSG_ABOVE      710   // ID of static message above list

#define RES_STA_MSG_BELOW      711   // ID of static message below list

 

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

#include "Ifx.h"

 

export prototype ExFn_CtrlDir(HWND);

 

function ExFn_CtrlDir(hMSI)

    STRING  szDialogName, svSelection;

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

 

    // Report an error; then terminate.

    if (nResult < 0) then

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

        abort;

    endif;

 

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

 

                // Set the messages that appear above and below the list box.

                CtrlSetText (szDialogName, RES_STA_MSG_ABOVE,

                            "Files found in the root directory of the Windows drive:");

                CtrlSetText (szDialogName, RES_STA_MSG_BELOW,

                            "Select a file; then click the Next button");

 

                // Create a list of all files in the root directory of the

                // drive on which Windows resides and put it into the dialog's

                // list box control.

                if (CtrlDir (szDialogName, RES_DIALOG_LISTBOX, WINDISK^"*.*",

                            DLG_DIR_FILE) < 0) then

                    MessageBox ("CtrlDir failed.", SEVERE);

                    bDone = TRUE;

                endif;

            case RES_PBUT_CANCEL:

                 // The user clicked the Cancel button.

                 Do (EXIT);

            case RES_PBUT_NEXT:

                  // Get the current selection so it can be displayed.

                  CtrlGetCurSel (szDialogName, RES_DIALOG_LISTBOX, svSelection);

                  bDone = TRUE;

            case RES_PBUT_BACK:

                  bDone = TRUE;

        endswitch;

 

    until bDone;

 

    // Close the dialog.

    EndDialog (szDialogName);

 

    // Free the dialog from memory;

    ReleaseDialog (szDialogName);

 

    // If the Next button was used to close the dialog,

    // display the item that was selected from the list box.

    if (nCmdValue = RES_PBUT_NEXT) then

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

    endif;

 

end;