1
\S1{callbacks} Callback Functions
3
You can create callback functions which have special names, that will be called by the installer at certain points in the install. Below is a list of currently available callbacks:
5
\S2{instcallbacks} Install Callbacks
7
\S3{onguiinit} .onGUIInit
9
This callback will be called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the user interface.
13
\c !include "WinMessages.nsh"
15
\c Function .onGUIInit
16
\c # 1028 is the id of the branding text control
17
\c GetDlgItem $R0 $HWNDPARENT 1028
18
\c CreateFont $R1 "Tahoma" 10 700
19
\c SendMessage $R0 ${WM_SETFONT} $R1 0
20
\c # set background color to white and text color to red
21
\c SetCtlColors $R0 FFFFFF FF0000
26
This callback will be called when the installer is nearly finished initializing. If the '.onInit' function calls \R{abort}{Abort}, the installer will quit instantly.
28
Here are two examples of how this might be used:
31
\c MessageBox MB_YESNO "This will install. Continue?" IDYES NoAbort
32
\c Abort ; causes installer to quit.
39
\c ReadINIStr $INSTDIR $WINDIR\wincmd.ini Configuration InstallDir
40
\c StrCmp $INSTDIR "" 0 NoAbort
41
\c MessageBox MB_OK "Windows Commander not found. Unable to get install path."
42
\c Abort ; causes installer to quit.
46
\S3{oninstfailed} .onInstFailed
48
This callback is called when the user hits the 'cancel' button after the install has failed (if it could not extract a file, or the install script used the \R{abort}{Abort} command).
52
\c Function .onInstFailed
53
\c MessageBox MB_OK "Better luck next time."
56
\S3{oninstsuccess} .onInstSuccess
58
This callback is called when the install was successful, right before the install window closes (which may be after the user clicks 'Close' if \R{aautoclosewindow}{AutoCloseWindow} or \R{setautoclose}{SetAutoClose} is set to false).
62
\c Function .onInstSuccess
63
\c MessageBox MB_YESNO "Congrats, it worked. View readme?" IDNO NoReadme
64
\c Exec notepad.exe ; view readme or whatever, if you want.
68
\S3{onguiend} .onGUIEnd
70
This callback is called right after the installer window closes. Use it to free any user interface related plug-ins if needed.
72
\S3{onmouseoversection} .onMouseOverSection
74
This callback is called whenever the mouse position over the sections tree has changed. This allows you to set a description for each section for example. The section id on which the mouse is over currently is stored, temporarily, in $0.
78
\c Function .onMouseOverSection
79
\c FindWindow $R0 "#32770" "" $HWNDPARENT
80
\c GetDlgItem $R0 $R0 1043 ; description item (must be added to the UI)
83
\c SendMessage $R0 ${WM_SETTEXT} 0 "STR:first section description"
86
\c SendMessage $R0 ${WM_SETTEXT} 0 "STR:second section description"
89
\S3{onrebootfailed} .onRebootFailed
91
This callback is called if \R{reboot}{Reboot} fails. \R{writeuninstaller}{WriteUninstaller}, \R{plugindlls}{plug-ins}, \R{file}{File} and \R{writeregbin}{WriteRegBin} should not be used in this callback.
95
\c Function .onRebootFailed
96
\c MessageBox MB_OK|MB_ICONSTOP "Reboot failed. Please reboot manually." /SD IDOK
99
\S3{onselchange} .onSelChange
101
Called when the selection changes on the \R{pages}{component page}. Useful for using with \R{sectionsetflags}{SectionSetFlags} and \R{sectiongetflags}{SectionGetFlags}.
103
\S3{onuserabort} .onUserAbort
105
This callback is called when the user hits the 'cancel' button, and the install hasn't already failed. If this function calls \R{abort}{Abort}, the install will not be aborted.
109
\c Function .onUserAbort
110
\c MessageBox MB_YESNO "Abort install?" IDYES NoCancelAbort
111
\c Abort ; causes installer to not quit.
115
\S3{onverifyinstdir} .onVerifyInstDir
117
This callback enables control over whether or not an installation path is valid for your installer. This code will be called every time the user changes the install directory, so it shouldn't do anything crazy with \R{messagebox}{MessageBox} or the likes. If this function calls \R{abort}{Abort}, the installation path in $INSTDIR is deemed invalid.
121
\c Function .onVerifyInstDir
122
\c IfFileExists $INSTDIR\Winamp.exe PathGood
123
\c Abort ; if $INSTDIR is not a winamp directory, don't let us install there
127
\S2{uninstcallbacks} Uninstall Callbacks
129
\S3{unonguiinit} un.onGUIInit
131
This callback will be called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the user interface.
133
Have a look at \R{onguiinit}{.onGUIInit} for an example.
135
\S3{unonInit} un.onInit
137
This callback will be called when the uninstaller is nearly finished initializing. If the 'un.onInit' function calls Abort, the uninstaller will quit instantly. Note that this function can verify and/or modify $INSTDIR if necessary.
139
Here are two examples of how this might be used:
141
\c Function un.onInit
142
\c MessageBox MB_YESNO "This will uninstall. Continue?" IDYES NoAbort
143
\c Abort ; causes uninstaller to quit.
149
\c Function un.onInit
150
\c IfFileExists $INSTDIR\myfile.exe found
151
\c Messagebox MB_OK "Uninstall path incorrect"
156
\S3{unonuninstfailed} un.onUninstFailed
158
This callback is called when the user hits the 'cancel' button after the uninstall has failed (if it used the \R{abort}{Abort command} or otherwise failed).
162
\c Function un.onUninstFailed
163
\c MessageBox MB_OK "Better luck next time."
166
\S3{unonuninstsuccess} un.onUninstSuccess
168
This callback is called when the uninstall was successful, right before the install window closes (which may be after the user clicks 'Close' if \R{setautoclose}{SetAutoClose} is set to false)..
172
\c Function un.onUninstSuccess
173
\c MessageBox MB_OK "Congrats, it's gone."
176
\S3{unonguiend} un.onGUIEnd
178
This callback is called right after the uninstaller window closes. Use it to free any user interface related plug-ins if needed.
180
\S3{unonrebootfailed} un.onRebootFailed
182
This callback is called if \R{reboot}{Reboot} fails. \R{writeuninstaller}{WriteUninstaller}, \R{plugindlls}{plug-ins}, \R{file}{File} and \R{writeregbin}{WriteRegBin} should not be used in this callback.
186
\c Function un.onRebootFailed
187
\c MessageBox MB_OK|MB_ICONSTOP "Reboot failed. Please reboot manually." /SD IDOK
190
\S3{unonuserabort} un.onUserAbort
192
This callback is called when the user hits the 'cancel' button and the uninstall hasn't already failed. If this function calls Abort, the install will not be aborted.
196
\c Function un.onUserAbort
197
\c MessageBox MB_YESNO "Abort uninstall?" IDYES NoCancelAbort
198
\c Abort ; causes uninstaller to not quit.
1
\S1{callbacks} Callback Functions
3
You can create callback functions which have special names, that will be called by the installer at certain points in the install. Below is a list of currently available callbacks:
5
\S2{instcallbacks} Install Callbacks
7
\S3{onguiinit} .onGUIInit
9
This callback will be called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the user interface.
13
\c !include "WinMessages.nsh"
15
\c Function .onGUIInit
16
\c # 1028 is the id of the branding text control
17
\c GetDlgItem $R0 $HWNDPARENT 1028
18
\c CreateFont $R1 "Tahoma" 10 700
19
\c SendMessage $R0 ${WM_SETFONT} $R1 0
20
\c # set background color to white and text color to red
21
\c SetCtlColors $R0 FFFFFF FF0000
26
This callback will be called when the installer is nearly finished initializing. If the '.onInit' function calls \R{abort}{Abort}, the installer will quit instantly.
28
Here are two examples of how this might be used:
31
\c MessageBox MB_YESNO "This will install. Continue?" IDYES NoAbort
32
\c Abort ; causes installer to quit.
39
\c ReadINIStr $INSTDIR $WINDIR\wincmd.ini Configuration InstallDir
40
\c StrCmp $INSTDIR "" 0 NoAbort
41
\c MessageBox MB_OK "Windows Commander not found. Unable to get install path."
42
\c Abort ; causes installer to quit.
46
\S3{oninstfailed} .onInstFailed
48
This callback is called when the user hits the 'cancel' button after the install has failed (if it could not extract a file, or the install script used the \R{abort}{Abort} command).
52
\c Function .onInstFailed
53
\c MessageBox MB_OK "Better luck next time."
56
\S3{oninstsuccess} .onInstSuccess
58
This callback is called when the install was successful, right before the install window closes (which may be after the user clicks 'Close' if \R{aautoclosewindow}{AutoCloseWindow} or \R{setautoclose}{SetAutoClose} is set to false).
62
\c Function .onInstSuccess
63
\c MessageBox MB_YESNO "Congrats, it worked. View readme?" IDNO NoReadme
64
\c Exec notepad.exe ; view readme or whatever, if you want.
68
\S3{onguiend} .onGUIEnd
70
This callback is called right after the installer window closes. Use it to free any user interface related plug-ins if needed.
72
\S3{onmouseoversection} .onMouseOverSection
74
This callback is called whenever the mouse position over the sections tree has changed. This allows you to set a description for each section for example. The section id on which the mouse is over currently is stored, temporarily, in $0.
78
\c Function .onMouseOverSection
79
\c FindWindow $R0 "#32770" "" $HWNDPARENT
80
\c GetDlgItem $R0 $R0 1043 ; description item (must be added to the UI)
83
\c SendMessage $R0 ${WM_SETTEXT} 0 "STR:first section description"
86
\c SendMessage $R0 ${WM_SETTEXT} 0 "STR:second section description"
89
\S3{onrebootfailed} .onRebootFailed
91
This callback is called if \R{reboot}{Reboot} fails. \R{writeuninstaller}{WriteUninstaller}, \R{plugindlls}{plug-ins}, \R{file}{File} and \R{writeregbin}{WriteRegBin} should not be used in this callback.
95
\c Function .onRebootFailed
96
\c MessageBox MB_OK|MB_ICONSTOP "Reboot failed. Please reboot manually." /SD IDOK
99
\S3{onselchange} .onSelChange
101
Called when the selection changes on the \R{pages}{component page}. Useful for using with \R{sectionsetflags}{SectionSetFlags} and \R{sectiongetflags}{SectionGetFlags}.
103
Selection changes include both section selection and installation type change.
105
\S3{onuserabort} .onUserAbort
107
This callback is called when the user hits the 'cancel' button, and the install hasn't already failed. If this function calls \R{abort}{Abort}, the install will not be aborted.
111
\c Function .onUserAbort
112
\c MessageBox MB_YESNO "Abort install?" IDYES NoCancelAbort
113
\c Abort ; causes installer to not quit.
117
\S3{onverifyinstdir} .onVerifyInstDir
119
This callback enables control over whether or not an installation path is valid for your installer. This code will be called every time the user changes the install directory, so it shouldn't do anything crazy with \R{messagebox}{MessageBox} or the likes. If this function calls \R{abort}{Abort}, the installation path in $INSTDIR is deemed invalid.
123
\c Function .onVerifyInstDir
124
\c IfFileExists $INSTDIR\Winamp.exe PathGood
125
\c Abort ; if $INSTDIR is not a winamp directory, don't let us install there
129
\S2{uninstcallbacks} Uninstall Callbacks
131
\S3{unonguiinit} un.onGUIInit
133
This callback will be called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the user interface.
135
Have a look at \R{onguiinit}{.onGUIInit} for an example.
137
\S3{unonInit} un.onInit
139
This callback will be called when the uninstaller is nearly finished initializing. If the 'un.onInit' function calls Abort, the uninstaller will quit instantly. Note that this function can verify and/or modify $INSTDIR if necessary.
141
Here are two examples of how this might be used:
143
\c Function un.onInit
144
\c MessageBox MB_YESNO "This will uninstall. Continue?" IDYES NoAbort
145
\c Abort ; causes uninstaller to quit.
151
\c Function un.onInit
152
\c IfFileExists $INSTDIR\myfile.exe found
153
\c Messagebox MB_OK "Uninstall path incorrect"
158
\S3{unonuninstfailed} un.onUninstFailed
160
This callback is called when the user hits the 'cancel' button after the uninstall has failed (if it used the \R{abort}{Abort command} or otherwise failed).
164
\c Function un.onUninstFailed
165
\c MessageBox MB_OK "Better luck next time."
168
\S3{unonuninstsuccess} un.onUninstSuccess
170
This callback is called when the uninstall was successful, right before the install window closes (which may be after the user clicks 'Close' if \R{setautoclose}{SetAutoClose} is set to false)..
174
\c Function un.onUninstSuccess
175
\c MessageBox MB_OK "Congrats, it's gone."
178
\S3{unonguiend} un.onGUIEnd
180
This callback is called right after the uninstaller window closes. Use it to free any user interface related plug-ins if needed.
182
\S3{unonrebootfailed} un.onRebootFailed
184
This callback is called if \R{reboot}{Reboot} fails. \R{writeuninstaller}{WriteUninstaller}, \R{plugindlls}{plug-ins}, \R{file}{File} and \R{writeregbin}{WriteRegBin} should not be used in this callback.
188
\c Function un.onRebootFailed
189
\c MessageBox MB_OK|MB_ICONSTOP "Reboot failed. Please reboot manually." /SD IDOK
192
\S3{unonselchange} un.onSelChange
194
Called when the selection changes on the \R{pages}{component page}. Useful for using with \R{sectionsetflags}{SectionSetFlags} and \R{sectiongetflags}{SectionGetFlags}.
196
Selection changes include both section selection and installation type change.
198
\S3{unonuserabort} un.onUserAbort
200
This callback is called when the user hits the 'cancel' button and the uninstall hasn't already failed. If this function calls Abort, the install will not be aborted.
204
\c Function un.onUserAbort
205
\c MessageBox MB_YESNO "Abort uninstall?" IDYES NoCancelAbort
206
\c Abort ; causes uninstaller to not quit.
b'\\ No newline at end of file'