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

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

Related

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

Background color of MUI_STARTMENUPAGE_TEXT_TOP in NSIS

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

Nsis: Change Title bar for Two installations in one installer

I have two installations in one installer from:
http://nsis.sourceforge.net/Two_installations_in_one_installer
How can I customize the title bar (setup name) for the two installations?
NSIS is not really designed to do this so you have to set it manually every time a page changes:
!include MUI.nsh
!include WinMessages.nsh
Caption " "
!define MUI_PAGE_CUSTOMFUNCTION_SHOW lic1
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW inst1
!insertmacro MUI_PAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_SHOW lic2
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW inst2
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Function lic1
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Foo$(^LicenseSubCaption)"
FunctionEnd
Function inst1
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Foo$(^InstallingSubCaption)"
FunctionEnd
Function lic2
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Bar$(^LicenseSubCaption)"
FunctionEnd
Function inst2
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:Bar$(^InstallingSubCaption)"
FunctionEnd

Resources