Change caption of installer at runtime: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(initial) |
m (→Sample) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
<highlight-nsis> | <highlight-nsis> | ||
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Your text" | SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Your text" | ||
</highlight-nsis> | |||
This can be abstracted as a [[Macro_vs_Function|Macro]] through: | |||
<highlight-nsis> | |||
!include "WinMessages.nsh" | |||
!define SetTitleBar "!insertmacro SetTitleBar" | |||
!macro SetTitlebar Str | |||
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:${Str}" | |||
!macroend | |||
</highlight-nsis> | </highlight-nsis> | ||
Line 17: | Line 26: | ||
!include WinMessages.nsh | !include WinMessages.nsh | ||
!define SetTitleBar "!insertmacro SetTitleBar" | |||
!macro SetTitlebar Str | |||
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:${Str}" | |||
!macroend | |||
Caption "My Installer" | Caption "My Installer" | ||
Line 31: | Line 45: | ||
Section "Section 2" | Section "Section 2" | ||
${SetTitleBar} "We are waiting... [Section 2]" | |||
Sleep 5000 | Sleep 5000 | ||
${SetTitleBar} "Ok, that's enough." | |||
SectionEnd | SectionEnd | ||
Function .onSelChange | Function .onSelChange | ||
IntOp $1 $1 + 1 | IntOp $1 $1 + 1 | ||
${SetTitleBar} "Changed sections $1 times" | |||
FunctionEnd | FunctionEnd | ||
Line 47: | Line 61: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Code Examples]] | [[Category:Code Examples]] | ||
Please note that you have to call this function in every page's opening (or pre) function, as otherwise the titlebar will be reset to the default set by Caption commands. | |||
Additionally, the above function will only change the titlebar of the main installer window. Any messageboxes, error dialogs, etc. that may present themselves during installation will use the title set by Caption commands. |
Latest revision as of 02:29, 11 May 2008
Author: bholliger (talk, contrib) |
Description
This sample describes how to change the window title of the installer at runtime. It is based on this Forum-Thread. Thx rsegal.
The main code is
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Your text"
This can be abstracted as a Macro through:
!include "WinMessages.nsh" !define SetTitleBar "!insertmacro SetTitleBar" !macro SetTitlebar Str SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:${Str}" !macroend
Have a look at the following sample.
Sample
Outfile 'test.exe' InstallDir '$PROGRAMFILES\Test' !include WinMessages.nsh !define SetTitleBar "!insertmacro SetTitleBar" !macro SetTitlebar Str SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:${Str}" !macroend Caption "My Installer" page components page directory page instfiles Section "Section 1" SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:We are waiting... [Section 1]" Sleep 5000 SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Ok, that's enough." SectionEnd Section "Section 2" ${SetTitleBar} "We are waiting... [Section 2]" Sleep 5000 ${SetTitleBar} "Ok, that's enough." SectionEnd Function .onSelChange IntOp $1 $1 + 1 ${SetTitleBar} "Changed sections $1 times" FunctionEnd Function .onInit StrCpy $1 "0" FunctionEnd
Please note that you have to call this function in every page's opening (or pre) function, as otherwise the titlebar will be reset to the default set by Caption commands.
Additionally, the above function will only change the titlebar of the main installer window. Any messageboxes, error dialogs, etc. that may present themselves during installation will use the title set by Caption commands.