cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Displaying a File Browse Dialog in an InstallScript Project

Displaying a File Browse Dialog in an InstallScript Project

Summary

Include a file browse dialog in an InstallScript project.

Synopsis

Applies to InstallScript projects. The following article explains how to include a file browse dialog into your InstallScript project.


Discussion

A file browse dialog can be displayed during setup by calling the Windows API GetOpenFileNameA. Follow these steps to use this API in your installation script.

brwsdlg.h

brwsdlg.txt

(After downloading this file, change the file extenion to .rul.)

InstallShield 11, 10.5, X or DevStudio

  1. Open the Installation Designer view.

  2. Under Behavior and Logic, select InstallScript.

  3. Right-click on your setup.rul file and select Import Script File.

  4. Now insert the files brwsdlg.h and brwsdlg.rul into your project. Go to step 2 below.

Legacy Professional

  1. Insert the files brwsdlg.h and brwsdlg.rul into your project by clicking on the scripts tab. Right-click on your setup.rul file and select Import Files.

  2. Click on your setup.rul file to bring up your script in the right hand window and insert the following code to your script, after the #include "ifx.h" statement.

    #include "brwsdlg.h"
    #include "brwsdlg.rul"

    Add the following sample script to call the API to display the file browse dialog.

    function OnBegin()
    // FileBrowseDlg requires the szFile parameter be explicitly sized
    // and that the size be passed as the second parameter.
    STRING szFile[512], svDir, svFileList, svTemp;
    NUMBER nResult, nReturn;
    BOOL bMultiSel, bDerefLinks;
    LIST listFiles;

    begin
    // If I want to support multiple selection, set bMultiSel to TRUE
    // and pass in a valid string list.
    bMultiSel = TRUE;
    bDerefLinks = FALSE;
    listFiles = ListCreate(STRINGLIST);
    // Open the file browse dialog.
    nResult = FileBrowseDlg( szFile, 512, "All files (*.*)\0*.txt\0\0", "Select File", "c:\\", bMultiSel, listFiles, bDerefLinks );
    if nResult = 0 then
    if bMultiSel then
    // If I chose multiple selection, I must parse the info, which is stored
    // in list. First item will be dir, all others are individual filenames.
    nReturn = ListGetFirstString(listFiles, svTemp);
    while nReturn != END_OF_LIST
    svFileList = svFileList + svTemp + "\n";
    nReturn = ListGetNextString(listFiles, svTemp);
    endwhile;
    MessageBox("Directory (first item) and selected files:\n\n" + svFileList, 0);
    else
    // No multiple selection, so a single file/path was set.
    MessageBox("Selected file:\n\n" + szFile, 0);
    endif;
    endif;
    ListDestroy(listFiles);
    end;

Note: This is only a sample. You can call the above script from any InstallShield event, such as OnBegin or OnEnd, or a function that is called from an InstallShield event.


Additional Information

For information on how to include InstallScript in InstallScript MSI and Basic MSI projects, see the InstallShield Help Library topic Using InstallScript.

For further information on the GetOpenFileName() API, see the MSDN article GetOpenFileName Function.

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Oct 02, 2007 05:25 PM
Updated by: