IntroductionNSIS 2 makes it is possible to create installers with a custom user interface. The Modern UI is an interface with a style like the wizards of recent Windows versions. This new interface also features new pages (Welcome, Finish, Start Menu) and a description area on the components page. The interface and the graphics can be customized using the provided settings. Using the Modern UI macros and language files, writing scripts with a modern interface is easy. This document contains information about writing Modern UI scripts and a reference of all settings. Important: Because the Modern UI has its own macro system, its own default settings and a lot of new features, the interface configuration works differently. So you should not use commands like LicenseText, Icon, CheckBitmap, InstallColors etc. ScreenshotsHow to useThe Modern UI has a macro system, so all the code to control the interface has already been written for you. If you want to start a new Modern UI script or upgrade an older script with the Classic UI, follow the steps below. Taking a look at the example scripts will also help you to learn more about the Modern UI. SyntaxSome defines (e.g. MUI_COMPONENTSPAGE_SMALLDESC) don't need a value, they are true/false settings. Others (e.g. MUI_UI) can be used to define a specific value. Parameters are specified in this format: required (option1 | option2) [optional] Parameters for defined settings should be in one string: !define MUI_COMPONENTSPAGE_SMALLDESC ;No value !define MUI_UI "myUI.exe" ;Value !define MUI_INSTFILESPAGE_COLORS "FFFFFF 000000" ;Multiple settings If you want a certain value (e.g. a text) to be language-specific, set a language string (using LangString) and define $(STRINGNAME) as value. Use a license language string (LicenseLangString) for the license text. If you want to add " to a Modern UI string, you should always escape it using $\" because the Modern UI macros use " to separate parameters. 1. Header file!include "MUI.nsh" MUI.nsh is in the Include directory, so you don't have to specify a path. 2. Interface ConfigurationInterface settings should be set before inserting page macros. Page interface settings apply to all pages of a certain type. Interface SettingsGeneral Interface SettingsMUI_ICON icon_file MUI_UNICON icon_file MUI_HEADERIMAGE MUI_HEADERIMAGE_BITMAP bmp_file MUI_HEADERIMAGE_BITMAP_NOSTRETCH MUI_HEADERIMAGE_BITMAP_RTL bmp_file MUI_HEADERIMAGE_BITMAP_RTL_NOSTRETCH MUI_HEADERIMAGE_UNBITMAP bmp_file MUI_HEADERIMAGE_UNBITMAP_NOSTRETCH MUI_HEADERIMAGE_UNBITMAP_RTL bmp_file MUI_HEADERIMAGE_UNBITMAP_RTL_NOSTRETCH MUI_HEADERIMAGE_RIGHT MUI_BGCOLOR (color:
RRGGBBR hexadecimal) MUI_HEADER_TRANSPARENT_TEXT Interface Resource SettingsMUI_UI ui_file MUI_UI_HEADERIMAGE ui_file MUI_UI_HEADERIMAGE_RIGHT ui_file MUI_UI_COMPONENTSPAGE_SMALLDESC ui_file MUI_UI_COMPONENTSPAGE_NODESC ui_file Welcome/Finish Page Interface SettingsMUI_WELCOMEFINISHPAGE_BITMAP bmp_file MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH Welcome/Finish Page InstallOptions INI SettingsMUI_WELCOMEFINISHPAGE_INI ini_file Uninstaller Welcome/Finish Page SettingsMUI_UNWELCOMEFINISHPAGE_BITMAP bmp_file MUI_UNWELCOMEFINISHPAGE_BITMAP_NOSTRETCH Uninstaller Welcome/Finish Page Interface INI SettingsMUI_UNWELCOMEFINISHPAGE_INI ini_file License Page Interface SettingsMUI_LICENSEPAGE_BGCOLOR (/windows | /grey | (color: RRGGBB
hexadecimal)) Components Page Interface SettingsMUI_COMPONENTSPAGE_CHECKBITMAP bitmap_file MUI_COMPONENTSPAGE_SMALLDESC MUI_COMPONENTSPAGE_NODESC Installation Page Interface SettingsMUI_INSTFILESPAGE_COLORS (/windows | (foreground color: RRGGBB hexadecimal)
(background color: RRGGBB hexadecimal)) MUI_INSTFILESPAGE_PROGRESSBAR ("" | colored | smooth) Installer Finish Page Interface SettingsMUI_FINISHPAGE_NOAUTOCLOSE Uninstaller Finish Page Interface SettingsMUI_UNFINISHPAGE_NOAUTOCLOSE Abort Warning SettingsMUI_ABORTWARNING MUI_ABORTWARNING_TEXT text Uninstaller Abort Warning SettingsMUI_UNABORTWARNING MUI_UNABORTWARNING_TEXT text 3. PagesInsert the following macros to set the pages you want to use. The pages will appear in the order you insert them in your script. You can also insert custom Page commands between the macros to add custom pages. More info about custom pages... You can add multiple pages of certain types (for example, if you want the user to specify multiple folders). Examples: !insertmacro MUI_PAGE_LICENSE "License.rtf" !insertmacro MUI_PAGE_COMPONENTS Var STARTMENU_FOLDER !insertmacro MUI_PAGE_STARTMENU "Application" $STARTMENU_FOLDER You will need the page ID for the Start Menu Folder page when using the Start Menu Folder macros. The Start Menu Folder will be stored in the specified variable. Installer Pages Uninstaller Pages Page SettingsPage Settings apply to a single page and should be set before inserting a page macro. If you have multiple pages of one type and you want to set a setting for all them, put the setting before each page macro. Example: ;Add a directory page to let the user specify a plug-ins folder ;Store the folder in $PLUGINS_FOLDER Var PLUGINS_FOLDER !define MUI_DIRECTORYPAGE_VARIABLE $PLUGINS_FOLDER !insertmacro MUI_PAGE_DIRECTORY Note: There is no difference between installer and uninstaller page settings. General Page SettingsMUI_PAGE_HEADER_TEXT text MUI_PAGE_HEADER_SUBTEXT text Welcome Page SettingsMUI_WELCOMEPAGE_TITLE title MUI_WELCOMEPAGE_TITLE_3LINES MUI_WELCOMEPAGE_TEXT text License Page SettingsMUI_LICENSEPAGE_TEXT_TOP text MUI_LICENSEPAGE_TEXT_BOTTOM text MUI_LICENSEPAGE_BUTTON button_text MUI_LICENSEPAGE_CHECKBOX MUI_LICENSEPAGE_CHECKBOX_TEXT text MUI_LICENSEPAGE_RADIOBUTTONS MUI_LICENSEPAGE_RADIOBUTTONS_TEXT_ACCEPT
text MUI_LICENSEPAGE_RADIOBUTTONS_TEXT_DECLINE
text Components Page SettingsMUI_COMPONENTSPAGE_TEXT_TOP text MUI_COMPONENTSPAGE_TEXT_COMPLIST text MUI_COMPONENTSPAGE_TEXT_INSTTYPE text MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_TITLE
text MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO
text Directory Page SettingsMUI_DIRECTORYPAGE_TEXT_TOP text MUI_DIRECTORYPAGE_TEXT_DESTINATION text MUI_DIRECTORYPAGE_VARIABLE variable MUI_DIRECTORYPAGE_VERIFYONLEAVE Start Menu Folder Page SettingsPut the code to write the shortcuts (using CreateShortcut) between the MUI_STARTMENU_WRITE_BEGIN and MUI_STARTMENU_WRITE_END macros: !insertmacro MUI_STARTMENU_WRITE_BEGIN page_id ...create shortcuts... !insertmacro MUI_STARTMENU_WRITE_END The page ID should be the ID of the page on which the user has selected the folder for the shortcuts you want to write. MUI_STARTMENUPAGE_TEXT_TOP text MUI_STARTMENUPAGE_TEXT_CHECKBOX text MUI_STARTMENUPAGE_DEFAULTFOLDER folder MUI_STARTMENUPAGE_NODISABLE MUI_STARTMENUPAGE_REGISTRY_ROOT root For the uninstaller, use the MUI_STARTMENU_GETFOLDER macro to get the Start Menu folder: !insertmacro MUI_STARTMENU_GETFOLDER page_id $R0 Delete "$SMPROGRAMS\$R0\Your Shortcut.lnk" Installation Page SettingsMUI_INSTFILESPAGE_FINISHHEADER_TEXT
text MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT
text MUI_INSTFILESPAGE_ABORTHEADER_TEXT text MUI_INSTFILESPAGE_ABORTHEADER_SUBTEXT
text Finish Page SettingsMUI_FINISHPAGE_TITLE title MUI_FINISHPAGE_TITLE_3LINES MUI_FINISHPAGE_TEXT text MUI_FINISHPAGE_TEXT_LARGE MUI_FINISHPAGE_BUTTON text MUI_FINISHPAGE_TEXT_REBOOT text MUI_FINISHPAGE_TEXT_REBOOTNOW text MUI_FINISHPAGE_TEXT_REBOOTLATER text MUI_FINISHPAGE_RUN exe_file MUI_FINISHPAGE_RUN_TEXT text MUI_FINISHPAGE_RUN_PARAMETERS parameters MUI_FINISHPAGE_RUN_NOTCHECKED MUI_FINISHPAGE_RUN_FUNCTION function_name MUI_FINISHPAGE_SHOWREADME file/url MUI_FINISHPAGE_SHOWREADME_TEXT text MUI_FINISHPAGE_SHOWREADME_NOTCHECKED MUI_FINISHPAGE_SHOWREADME_FUNCTION function_name MUI_FINISHPAGE_LINK link_text MUI_FINISHPAGE_LINK_LOCATION file/url MUI_FINISHPAGE_LINK_COLOR (color: RRGGBB hexadecimal) MUI_FINISHPAGE_NOREBOOTSUPPORT Uninstall Confirm Page SettingsMUI_UNCONFIRMPAGE_TEXT_TOP text MUI_UNCONFIRMPAGE_TEXT_LOCATION text Advanced Page SettingsYou can add custom code to the page functions of your Modern UI pages. More info... 4. Custom functionsIf you want add your own code to functions inserted by the Modern UI (e.g. the .onGUIInit function and the page functions), create your own function and let the Modern UI functions call them. 5. Language filesInsert the Modern UI language files for the languages to want to include. !insertmacro MUI_LANGUAGE "English" The Modern UI language files load the NLF language files, so you should not use LoadLanguageFile. Language Selection DialogIf you want the installer to display a language selection dialog (have a look at the MultiLanguage.nsi example), insert the MUI_LANGDLL_DISPLAY macro in the .onInit function: Function .onInit !insertmacro MUI_LANGDLL_DISPLAY FunctionEnd You can also use this macro for the uninstaller, in the un.onInit function. Language Selection Dialog SettingsTo remember the user's preference, you can define a registry
key. MUI_LANGDLL_REGISTRY_ROOT root For the uninstaller, insert the MUI_UNGETLANGUAGE macro in un.onInit to get the stored language preference: Function un.onInit !insertmacro MUI_UNGETLANGUAGE FunctionEnd Language Selection Dialog Interface SettingsTo customize the language selection dialog interface, use these defines before inserting the MUI_LANGDLL_DISPLAY macro. MUI_LANGDLL_WINDOWTITLE text MUI_LANGDLL_INFO text MUI_LANGDLL_ALWAYSSHOW 6. Reserve filesIf you are using solid compression, it's important that files which are being extracted in init- or page functions function are located before other files in the data block, because this will make your installer faster. If there are File commands in your sections or functions above the init- or page functions, add the reserve file macros above your sections and functions. ReserveFile "ioFile.ini" ;Your own InstallOptions INI files !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ;InstallOptions plug-in !insertmacro MUI_RESERVEFILE_LANGDLL ;Language selection dialog 7. Your own sections and functionsAdd your installer sections and functions. See the NSIS Users Manual for details. Information about section code and function code for Start Menu shortcut creation and language selection can be found above. 8. Section descriptionsThe descriptions of sections will be displayed on the components page, when the user hovers the mouse over a section. If you don't want to use descriptions, use the MUI_COMPONENTSPAGE_NODESC interface setting. To set a description for a section, you have to add an additional parameter to the Section commmand with a name for the define that should contain the section number. Section "Section Name 1" Section1 ... SectionEnd Use these macros to set the descriptions: LangString DESC_Section1 ${LANG_ENGLISH} "Description of section 1." LangString DESC_Section2 ${LANG_ENGLISH} "Description of section 2." !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${Section1} $(DESC_Section1) !insertmacro MUI_DESCRIPTION_TEXT ${Section2} $(DESC_Section2) !insertmacro MUI_FUNCTION_DESCRIPTION_END For the uninstaller, use the MUI_UNFUNCTION_DESCRIPTION_BEGIN and MUI_UNFUNCTION_DESCRIPTION_END macros. Custom pagesIf you want add your custom pages to your installer, you should insert your own page commands between the page macros. !insertmacro MUI_PAGE_WELCOME Page custom FunctionName ;Custom page !insertmacro MUI_PAGE_COMPONENTS ;Uninstaller !insertmacro MUI_UNPAGE_CONFIRM UninstPage custom un.FunctionName ;Custom page !insertmacro MUI_UNPAGE_INSTFILES Using InstallOptions for custom pagesInstallOptions is a plug-in that displays custom pages that you can create using INI files. Have a look at the InstallOptions documentation for info about creating InstallOptions INI files. First, you have to extract your InstallOptions INI File in the .onInit function (un.onInit for the uninstaller) using the MUI_INSTALLOPTIONS_EXTRACT macro: Function .onInit !insertmacro MUI_INSTALLOPTIONS_EXTRACT "ioFile.ini" FunctionEnd If your INI File is located in another directory, use MUI_INSTALLOPTIONS_EXTRACT_AS. The second parameter is the filename for the temporary plug-ins directory, use this filename as parameter for the other InstallOptions macros. Function .onInit !insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "..\ioFile.ini" "ioFile.ini" FunctionEnd You can call Instal Options in the function defined with the Page or UninstPage command using the MUI_INSTALLOPTIONS_DISPLAY macro. Use the MUI_HEADER_TEXT macro to set the text on the page header: LangString TEXT_IO_TITLE ${LANG_ENGLISH} "Install Options Page Title" LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "A subtitle" Function FunctionName ;FunctionName defined with Page command !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)" !insertmacro MUI_INSTALLOPTIONS_DISPLAY "ioFile.ini" FunctionEnd For custom fonts and colors, macros for the initDialog and show functions of InstallOptions are also available: Var HWND Var DLGITEM Var FONT LangString TEXT_IO_TITLE ${LANG_ENGLISH} "Install Options Page Title" LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "A subtitle" Function FunctionName ;FunctionName defined with Page command !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)" !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ioFile.ini" Pop $HWND ;HWND of dialog GetDlgItem $DLGITEM $HWND 1200 ;1200 + Field number - 1 ;$DLGITEM contains the HWND of the first field CreateFont $FONT "Tahoma" 10 700 SendMessage $DLGITEM ${WM_SETFONT} $FONT 0 !insertmacro MUI_INSTALLOPTIONS_SHOW FunctionEnd If you need the InstallOptions return value (success, back, cancel, error), use the MUI_INSTALLOPTIONS_DISPLAY_RETURN or MUI_INSTALLOPTIONS_SHOW_RETURN macro. The return value will be added to the stack, so you can use the Pop command to get it. Use these macros to read or write INI file values: !insertmacro MUI_INSTALLOPTIONS_READ $VAR "ioFile.ini" "Field #" "Name" !insertmacro MUI_INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Name" "Value" For example, you can use the MUI_INSTALLOPTIONS_READ macro in a section to get the user input: !insertmacro MUI_INSTALLOPTIONS_READ $R0 "ioFile.ini" "Field 1" "State" For more details about InstallOptions, validation of user input etc., check the InstallOptions documentation. Customize standard dialogsTo change elements on the dialogs, use customized UI resource files (see Interface Configuration). You can change your copies of the original files (in the Contrib\UIs folder) by using an application such as Resource Hacker. The 'Please wait while Setup is loading...' text on the splash
screen that is being displayed while the installer is starting
(Verifying installer, Unpacking data) can be changed by using a
customized UI resource file (MUI_UI setting) with a modified dialog
111. To modify the Welcome dialog and Finish dialog, use a custom INI file (MUI_SPECIALINI setting) or write to the INI file in the custom page functions. Customize Modern UI FunctionsIf you want add your own code to functions inserted by the Modern UI, such as the .onGUIInit function and the Page functions, create your own function and let the Modern UI functions call them. Use the defines to define the name of your functions. Example: !define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit Function myGUIInit ...your own code... FunctionEnd General Custom FunctionsThese defines should be set before inserting the language macros. MUI_CUSTOMFUNCTION_GUIINIT function Page Custom FunctionsThese defines should be set before inserting a page macro. MUI_PAGE_CUSTOMFUNCTION_PRE function Notes:
Welcome/Finish Page Custom FunctionsThis define should be inserted before a single Welcome or Finish page. MUI_WELCOMEFINISHPAGE_CUSTOMFUNCTION_INIT function This Init function is called before the InstallOptions INI file for the page is written, so you can use it to initialize any variables used in the page settings. ExamplesBasic: Basic.nsi Version history
CreditsMade by Joost Verburg. HelpPlease post questions at the NSIS Forum. LicenseThe zlib/libpng license applies to the Modern UI. License TermsCopyright © 2002-2006 Joost Verburg This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any distribution. |