Background color of MUI_STARTMENUPAGE_TEXT_TOP in NSIS - background-color

How to change the Background color of MUI_STARTMENUPAGE_TEXT_TOP in NSIS?
The function SetCtlColor is not working.
I even tried to find the ItemID,but could not find the correct ID.

!include MUI.nsh
Var MySMDir
!define MUI_STARTMENUPAGE_TEXT_TOP "Blah blah"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW OnStartmenuPageShow
!insertmacro MUI_PAGE_STARTMENU SMD $MySMDir
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function OnStartmenuPageShow
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog
GetDlgItem $0 $0 0x3EB
/* Uncomment to use MUI specific ways of finding the control
!if "${MUI_SYSVERSION}" >= 2.0
GetDlgItem $0 $mui.StartMenuPage 0x3EB
!else
GetDlgItem $0 $MUI_HWND 0x3EB
!endif */
SetCtlColors $0 774411 aaccff
FunctionEnd

Related

NSIS: call MUI_PAGE_LICENSE from function but get "XPStyle not valid" error

I have a custom dialog with an "License terms and conditions." checkbox where the Text to the checkbox is actually a link which is suppose to show the License Dialog.
; === LicenseLink (type: Link) ===
${NSD_CreateLink} 132.96u 100.92u 107.29u 14.15u "License terms and conditions."
Pop $hCtl_welcome_LicenseLink
${NSD_OnClick} $hCtl_welcome_LicenseLink ShowLicense
Now in the function "ShowLicense" I tried calling
!insertmacro MUI_PAGE_LICENSE
but get an error:
Error: command XPStyle not valid in Function
evidently I'm approaching this wrong and I can't interpret the error. Would be happy for any ideas on how to resolve this.
Thanks!
You cannot call !insertmacro MUI_PAGE_LICENSE dynamically, the number of pages is determined at compile time.
You can however skip pages to achieve this:
InstallDir "$Temp\Test"
!include MUI2.nsh
!include nsDialogs.nsh
!include WinMessages.nsh
!include LogicLib.nsh
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicensePage
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
Page Custom InfoPageCreate InfoPageValidate
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Var ShowLicensePage
Function SkipLicensePage
${IfThen} $ShowLicensePage = 0 ${|} Abort ${|} ; Skip it the first time
FunctionEnd
Function OnShowLicense
SendMessage $hWndParent ${WM_COMMAND} 3 "" ; Click the (hidden) back button
FunctionEnd
Var InstDirCtl
Function InfoPageCreate
StrCpy $ShowLicensePage 1
GetDlgItem $0 $hWndParent 3
ShowWindow $0 0 ; Hide the back button
!insertmacro MUI_HEADER_TEXT "Blah blah" "blah blah blah"
nsDialogs::Create 1018
Pop $0
${NSD_CreateText} 0 13u 100% 12u "$InstDir"
Pop $InstDirCtl
${NSD_CreateLink} 2u 40u -4u 12u "License"
Pop $0
${NSD_OnClick} $0 OnShowLicense
nsDialogs::Show
FunctionEnd
Function InfoPageValidate
${NSD_GetText} $InstDirCtl $InstDir
FunctionEnd

How to set the checkbox by default checked in the windows installer Finish page using NSIS

I wanted to set the checkbox as checked by default in the windows installer Finish page using NSIS. For that I used the below code snipped. But it is not even displaying the checkbox in the Finish page. Please help me on this.
Var Checkbox
Var CheckState ; Stored globally so we remember the choice if the user presses the back button and goes back to our page
!define CheckHeight 28
!macro CreateNativeControl hParent cls style exstyle x y w h text ; Note: Only supports pixel coordinates
System::Call 'USER32::CreateWindowEx(i ${exstyle}, t "${cls}", ts, i ${style}, i ${x}, i ${y}, i ${w}, i ${h}, p ${hParent}, i0, i0, i0)p.s' "${text}"
!macroend
!define MUI_PAGE_CUSTOMFUNCTION_SHOW FinishShow
!insertmacro MUI_PAGE_FINISH
Function FinishShow
System::Call *(i,i,i,i)p.r0 ; NSIS 2.51+
System::Call 'USER32::GetWindowRect(p$mui.FinishPage.Text, pr0)'
System::Call 'USER32::MapWindowPoints(i0,p$mui.FinishPage,p$0,i2)'
System::Call '*$0(i.r2,i.r3,i.r4,i.r5)'
System::Free $0
IntOp $5 $5 - ${CheckHeight}
System::Call 'USER32::SetWindowPos(i$mui.FinishPage.Text,i,i,i,i$4,i$5,i0x6)'
; Create and initialize the checkbox
IntOp $5 $3 + $5 ; y = TextTop + TextHeight
!insertmacro CreateNativeControl $mui.FinishPage ${__NSD_CheckBox_CLASS} "${__NSD_CheckBox_STYLE}" "${__NSD_CheckBox_EXSTYLE}" 0 $5 300 ${CheckHeight} "CheckboxTest"
Pop $Checkbox
SendMessage $mui.FinishPage ${WM_GETFONT} 0 0 $0
SendMessage $Checkbox ${WM_SETFONT} $0 1
System::Call 'USER32::SetWindowPos(i$Checkbox,i0,i,i,i,i,i0x33)'
${IfThen} $CheckState == "" ${|} StrCpy $CheckState 1 ${|}
${NSD_SetState} $Checkbox $CheckState
FunctionEnd
The finish page has built-in support for two optional check-boxes:
!include MUI2.nsh
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN ""
!define MUI_FINISHPAGE_RUN_TEXT "Run Foo"
!define MUI_FINISHPAGE_RUN_FUNCTION MyRunFoo
;define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME "$InstDir\Bar.exe"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Run Bar"
;define MUI_FINISHPAGE_SHOWREADME_FUNCTION
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
Function MyRunFoo
; Exec '"$InstDir\Foo.exe"'
FunctionEnd
Section
SectionEnd
Your example code is also missing a important call to !insertmacro MUI_LANGUAGE.
The function specified by MUI_FINISHPAGE_RUN_FUNCTION is only executed if the checkbox is checked. This is normal expected behavior.
If you want to do custom handling you can do it in the leave page:
!include nsDialogs.nsh
!include LogicLib.nsh
!include MUI2.nsh
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN ""
!define MUI_FINISHPAGE_RUN_TEXT "Blah blah"
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE FinishLeave
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
Function FinishLeave
${NSD_GetState} $mui.FinishPage.Run $0 ; or $mui.FinishPage.ShowReadme
${If} $0 <> 0
MessageBox mb_ok "Checkbox checked"
${Else}
MessageBox mb_ok "Checkbox not checked"
${EndIf}
FunctionEnd

Added link to MUI_PAGE_INSTFILES does not show

I'm trying to create a downloader that also has a "Download manually" link, but the link does not seem to show.
I tried to follow instructions from this post but can't seem to make it work.
I'm copying the script here in case anyone can point out what I might be missing - I'm a noob in NSIS scripting, sorry.
!include "MUI2.nsh"
!define NAME "instfileslink"
Name "${NAME}"
OutFile "${NAME}.exe"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyInstFilesShow
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Var hCtl_test_Link1
Section
Section
inetc::get /caption "Downloading package" "http://speedtest.ftp.otenet.gr/files/test100Mb.db" "test100Mb.db" /end
Pop $R0
StrCmp $R0 "OK" 0 dlfailed
Quit
dlfailed:
DetailPrint "Download failed: $R0"
Abort
SectionEnd
Function fnLinkClicked
ExecShell "open" "http://speedtest.ftp.otenet.gr/files/test100Mb.db"
FunctionEnd
Function MyInstFilesShow
${NSD_CreateLink} 120u 175u 100% 10u "Download manually"
Pop $hCtl_test_Link1
${NSD_OnClick} $hCtl_test_Link1 fnLinkClicked
FunctionEnd
You cannot use NSDialogs controls (${NSD_Create*}) outside a NSDialogs dialog!
You can use ChangeUI/MUI_UI to add controls to a built-in page or you can add the dynamically at run-time by manually creating a window. You need to use the ButtonEvent plug-in to catch the click events:
!include "MUI2.nsh"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyInstFilesShow
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
!include nsDialogs.nsh ; For style defines
ShowInstDetails hide
Function MyInstFilesShow
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog
System::Call 'USER32::CreateWindowEx(i0, t "STATIC", t "Download manually", i${WS_CHILD}|${WS_VISIBLE}|${SS_NOTIFY}, i 100, i 200, i 300, i 50, p $0, i 0x666, p 0, p 0)p.s'
Pop $0
SetCtlColors $0 0000ff transparent
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $1 fnLinkClicked
ButtonEvent::AddEventHandler 0x666 $1
FunctionEnd
Function fnLinkClicked
ExecShell "open" "http://speedtest.ftp.otenet.gr/files/test100Mb.db"
FunctionEnd

Making MUI_PAGE_DIRECTORY page field readonly?

Is it possible to make the the destination folder field in MUI_PAGE_DIRECTORY page readonly and disable the browse button?
InstallDir "$ProgramFiles\Whatever"
!include MUI2.nsh
!include WinMessages.nsh
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW RestrictDirPage
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Function RestrictDirPage
!if "${MUI_SYSVERSION}" >= 2.0
SendMessage $mui.DirectoryPage.Directory ${EM_SETREADONLY} 1 0
EnableWindow $mui.DirectoryPage.BrowseButton 0
!else
FindWindow $0 '#32770' '' $HWNDPARENT
GetDlgItem $1 $0 0x3FB
SendMessage $1 ${EM_SETREADONLY} 1 0
GetDlgItem $1 $0 0x3E9
EnableWindow $1 0
!endif
FunctionEnd

Is there a way to change the DirText font in NSIS script

In my NSIS script i want to change the text of DirText string to RED in MUI_PAGE_DIRECTORY, How can i do this?
Please suggest.
PS: Using GetDlgItem i am able to modify the Text box and title bar only.
!include MUI.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW OnDirPageShow
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function OnDirPageShow
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 0x3EE
SetCtlColors $1 ff0055 transparent
FunctionEnd

Resources