I'm using Nsis for install my project. I need to change richEdit background color. I try SetCtlColors method but it doesn't make any changes. Here is my code:
; handle variables
Var hCtl_FirstDialog
Var hCtl_FirstDialog_RichText1
Var hCtl_FirstDialog_Button1
; dialog create function
Function fnc_FirstDialog_Create
; === FirstDialog (type: Dialog) ===
nsDialogs::Create 1018
Pop $hCtl_FirstDialog
${If} $hCtl_FirstDialog == error
Abort
${EndIf}
!insertmacro MUI_HEADER_TEXT "Dialog title..." "Dialog subtitle..."
; === RichText1 (type: RichText) ===
nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 12.51u 14.77u 261.32u 92.92u ""
Pop $hCtl_FirstDialog_RichText1
; RichText1 ControlCustomScript
nsRichEdit::Load $hCtl_FirstDialog_RichText1 D:\temp\NsisProject\EULA.rtf
SetCtlColors $hCtl_FirstDialog_RichText1 ccff00 ccff00
; === Button1 (type: Button) ===
${NSD_CreateButton} 225.11u 118.77u 49.37u 14.15u "Button1"
Pop $hCtl_FirstDialog_Button1
${NSD_OnClick} $hCtl_FirstDialog_Button1 FillText
FunctionEnd
; dialog show function
Function fnc_FirstDialog_Show
Call fnc_FirstDialog_Create
nsDialogs::Show
FunctionEnd
The richedit control does not support SetCtlColors, you must use its documented messages to set the text format:
!include nsDialogs.nsh
!include WinMessages.nsh
!define /ifndef /math EM_SETBKGNDCOLOR ${WM_USER} + 67
!define /ifndef /math EM_SETCHARFORMAT ${WM_USER} + 68
!define /ifndef /math EM_SETTEXTEX ${WM_USER} + 97
!define /ifndef ST_SELECTION 2
!define /ifndef CFM_COLOR 0x40000000
!define /ifndef SCF_DEFAULT 0x0000
!define /ifndef SCF_ALL 0x0004
Var hRichEd
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 12.51u 14.77u 261.32u 92.92u ""
Pop $hRichEd
SendMessage $hRichEd ${EM_SETBKGNDCOLOR} 0 0x00ffcc
!if 1 ; Set default
System::Call '*(i 60, i ${CFM_COLOR}, i0,i0,i0, i 0xcc00ff, i, &m32)p.r0' ; Note: 60 is the ANSI size
SendMessage $hRichEd ${EM_SETCHARFORMAT} ${SCF_ALL} $0
System::Free $0
${nsD_SetText} $hRichEd "Text goes here"
!else ; Import RTF
System::Call '*(i${ST_SELECTION},i0)p.r0'
SendMessage $hRichEd ${EM_SETTEXTEX} $0 "STR:{\rtf1\ansi\deff0{\colortbl;\red115\green0\blue25;}\cf1 Text goes here}" ; www.pindari.com/rtf1.html
System::Free $0
SendMessage $hRichEd ${EM_REPLACESEL} 0 "STR: and more text here"
!endif
nsDialogs::Show
FunctionEnd
Page Custom MyPageCreate
Related
I use the MUI_PAGE_INSTFILES. And this page has normally a finish-button, but I have a custom page after it. But I want that you could still finish the installer before the custom page and the next page is only optional. I could also show more code if wished.
!include "MUI2.nsh"
!insertmacro MUI_PAGE_LICENSE $(license)
!insertmacro MUI_PAGE_INSTFILES
Page custom TestSettings
At the moment I have a previous-, next- and cancel-button at the instfile page. But I want a prev-, next- and finish-button.
NSIS was never designed to support this but with the ButtonEvent plug-in you can make it work. I'm just not sure if it makes sense because if the last page is important then some users might skip the page by accident because they are not paying attention.
!include MUI2.nsh
!insertmacro MUI_PAGE_LICENSE $(license)
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstFilesLeave
!insertmacro MUI_PAGE_INSTFILES
Page custom TestSettings
!insertmacro MUI_LANGUAGE English
!include WinMessages.nsh
!include nsDialogs.nsh
Function InstFilesLeave
GetDlgItem $0 $hWndParent 2
ShowWindow $0 0
System::Call 'USER32::GetWindowRect(pr0,#r1)' ; NSIS 3+
System::Call 'USER32::MapWindowPoints(p0,p $hWndParent, p $1, i 2)'
System::Call '*$1(i.r2,i.r3,i.r4,i.r5)'
IntOp $4 $4 - $2
IntOp $5 $5 - $3
!define IDC_MYFINISHBTN 1337
System::Call 'USER32::CreateWindowEx(i 0, t "BUTTON", t "&Finish", i ${DEFAULT_STYLES}|${WS_TABSTOP}, ir2, ir3, i r4, i r5, p $hWndParent, p ${IDC_MYFINISHBTN}, p 0, p 0)p.r1'
SendMessage $0 ${WM_GETFONT} "" "" $0
SendMessage $1 ${WM_SETFONT} $0 1
GetFunctionAddress $0 OnFinishButton
ButtonEvent::AddEventHandler ${IDC_MYFINISHBTN} $0
FunctionEnd
Var JustFinish
Function OnFinishButton
StrCpy $JustFinish 1
SendMessage $hWndParent ${WM_COMMAND} 1 ""
FunctionEnd
Function TestSettings
StrCmp $JustFinish "" +2
Return
GetDlgItem $0 $hWndParent ${IDC_MYFINISHBTN}
ShowWindow $0 0
GetDlgItem $0 $hWndParent 2
ShowWindow $0 1
!insertmacro MUI_HEADER_TEXT "Configure" "Blah blah blah"
nsDialogs::Create 1018
Pop $0
; ...
nsDialogs::Show
FunctionEnd
If your custom page just contains a couple of checkboxes then you can use the MUI Finish page with custom texts instead.
I'm trying to crate an installation with a custom form for settings:
configform.nsdInc:
; =========================================================
; This file was generated by NSISDialogDesigner 1.4.2.0
; http://coolsoft.altervista.org/nsisdialogdesigner
;
; Do not edit it manually, use NSISDialogDesigner instead!
; =========================================================
; handle variables
Var hCtl_configForm
Var hCtl_configForm_imgQuality
Var hCtl_configForm_wpctrlPort
Var hCtl_configForm_wpctrlIp
Var hCtl_configForm_atmCmdPort
Var hCtl_configForm_atmCmdIp
Var hCtl_configForm_Label3
Var hCtl_configForm_Label2
Var hCtl_configForm_Label1
Var T0
Var T1
Var T2
Var T3
Var T4
!include nsDialogs.nsh
; dialog create function
Function fnc_configForm_Create
; === configForm (type: Dialog) ===
nsDialogs::Create 1018
Pop $hCtl_configForm
${If} $hCtl_configForm == error
Abort
${EndIf}
!insertmacro MUI_HEADER_TEXT "Dialog title..." "Dialog subtitle..."
; === imgQuality (type: ComboBox) ===
${NSD_CreateComboBox} 77.67u 43.69u 63.85u 12.92u ""
Pop $hCtl_configForm_imgQuality
${NSD_CB_AddString} $hCtl_configForm_imgQuality "15"
....
${NSD_CB_AddString} $hCtl_configForm_imgQuality "97"
; === wpctrlPort (type: Text) ===
${NSD_CreateText} 235.65u 24u 57.92u 12.31u ""
Pop $hCtl_configForm_wpctrlPort
; === wpctrlIp (type: Text) ===
${NSD_CreateText} 77.67u 24u 154.03u 12.31u ""
Pop $hCtl_configForm_wpctrlIp
; === atmCmdPort (type: Text) ===
${NSD_CreateText} 235.65u 3.69u 57.92u 12.31u ""
Pop $hCtl_configForm_atmCmdPort
; === atmCmdIp (type: Text) ===
${NSD_CreateText} 77.67u 3.69u 154.03u 12.31u ""
Pop $hCtl_configForm_atmCmdIp
; === Label3 (type: Label) ===
${NSD_CreateLabel} 7.9u 44.92u 65.82u 11.69u "Image quality:"
Pop $hCtl_configForm_Label3
; === Label2 (type: Label) ===
${NSD_CreateLabel} 7.9u 25.85u 65.82u 11.69u "WPCTRL IP\Port:"
Pop $hCtl_configForm_Label2
; === Label1 (type: Label) ===
${NSD_CreateLabel} 7.9u 5.54u 65.82u 11.69u "ATMCMD IP\Port:"
Pop $hCtl_configForm_Label1
FunctionEnd
; dialog show function
Function fnc_configForm_Show
Call fnc_configForm_Create
nsDialogs::Show
FunctionEnd
Function fnc_save_config
${NSD_GetText} hCtl_configForm_atmCmdIp $T0
${NSD_GetText} hCtl_configForm_atmCmdPort $T1
${NSD_GetText} hCtl_configForm_wpctrlIp $T2
${NSD_GetText} hCtl_configForm_wpctrlPort $T3
${NSD_GetText} hCtl_configForm_imgQuality $T4
FileOpen $5 "$INSTDIR\M3Remote.xml" w
FileWrite $5 "<Settings><Login>Remote</Login> <Communications><WP><Ip>"
FileWrite $5 $T2
FileWrite $5 "</Ip><Port>"
FileWrite $5 $T3
FileWrite $5 "</Port>"
......
FileWrite $5 "ru-RU"
FileClose $5
FunctionEnd
A main .nsi script:
; Script generated by the HM NIS Edit Script Wizard.
SetCompressor /SOLID LZMA
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "MMMFFF"
!define PRODUCT_VERSION 1.0
!define PRODUCT_PUBLISHER "AAAA"
!define PRODUCT_WEB_SITE "http://e.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\M3Remote"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_DISTRIBUTION_FILE "MMMFFF_setup_${PRODUCT_VERSION}.exe"
RequestExecutionLevel admin
!define TARGETDIR "install"
!addplugindir "${TARGETDIR}"
; MUI 1.67 compatible
!include "MUI.nsh"
!include nsDialogs.nsh
; MUI Settings
!define MUI_ABORTWARNING
; Welcome page
!insertmacro MUI_PAGE_WELCOME
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "C:\Program Files\Lanit\M3Remote"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!include "configForm.nsdinc"
Page custom fnc_configForm_Show fnc_save_config
!insertmacro MUI_PAGE_FINISH
; Language files
!insertmacro MUI_LANGUAGE "Russian"
; MUI end
!include LogicLib.nsh
!include NsisXml.nsh
Name "M3Remote ${PRODUCT_VERSION}" ; название кнопки инсталлятора на панели задач
Caption "Установка M3Remote ${PRODUCT_VERSION}" ; заголовок окна инсталлятора
OutFile "M3Remote_setup_${PRODUCT_VERSION}.exe" ; имя файла инсталлятора
InstallDir "C:\Program Files\Lanit\M3Remote"
;------------------------------------------------------------------------------------------
Section Filecopy
CreateDirectory $INSTDIR
CreateDirectory $INSTDIR\Logs
WriteUninstaller "$INSTDIR\uninst.exe"
SetOutPath $INSTDIR
File /r binary\*
.........
SectionEnd
Function un.onUninstSuccess
.....
FunctionEnd
Function un.onInit
....
FunctionEnd
Section uninstall
...............
SectionEnd
The problem is, that I'm completely can't get out what's the problem with
${NSD_GetText}
, because it aways returns an empty string.
And I'm stuck!
You are not passing in a valid Window handle to ${NSD_GetText} because you forgot the $ prefix on the variable names. Change ${NSD_GetText} hCtl_configForm_atmCmdIp $T0 to ${NSD_GetText} $hCtl_configForm_atmCmdIp $T0 etc.
Can anyone explain to me, why ${NSD_GetState} $Checkbox is not working ?
I lost about 4 hours trying to find out what is wrong. I tried diffrent variants but in THIS script they are not working.
Actualy it is my first attempt to make a nsis installer, so I even dont know where should I look for mistake or I just dont understand the logic of this language.
From Russia with love :)
And sorry for my bad english
!define NAME "Simple LiveUSB installer"
!define FILENAME "USB"
!define VERSION "v0.1"
Name "${NAME} ${VERSION}"
OutFile "${FILENAME}.exe"
SetCompressor LZMA
ShowInstDetails hide
XPStyle on
!include MUI2.nsh
!include FileFunc.nsh
!include nsDialogs.nsh
;!include LogicLib.nsh
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\HEADER2.bmp"
!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\media-floppy.ico"
Page custom drivePage
Page custom Var123
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "Russian"
LangString DrivePage_Title ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Title2 ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Text ${LANG_RUSSIAN} "TEXT"
LangString DrivePage_Text2 ${LANG_RUSSIAN} "Format"
LangString DrivePage_Input ${LANG_RUSSIAN} "Choose"
Var Label
Var Label2
Var Checkbox
;Var Checkbox_State
Var DestDriveHW
Var DestDrive
# Functions #######################################
Function drivePage
!insertmacro MUI_HEADER_TEXT $(DrivePage_Title) $(DrivePage_Title2)
nsDialogs::Create 1018
${If} $DestDrive == ""
GetDlgItem $6 $HWNDPARENT 1
EnableWindow $6 0
${EndIf}
${NSD_CreateLabel} 0 0 100% 160 $(DrivePage_Text)
Pop $Label
${NSD_CreateLabel} 10 182 100% 15 $(DrivePage_Input)
Pop $Label2
${NSD_CreateDroplist} 10 200 13% 20 ""
Pop $DestDriveHw
${NSD_OnChange} $DestDriveHw db_select.onchange
${GetDrives} "FDD" driveListFiller
${If} $DestDrive != ""
${NSD_CB_SelectString} $DestDriveHw $DestDrive
${EndIf}
${NSD_CreateCheckbox} 80 203 100% 10u $(DrivePage_Text2)
Pop $Checkbox
${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox_State
${EndIf}
nsDialogs::Show
FunctionEnd
Function db_select.onchange
Pop $DestDriveHw
${NSD_GetText} $DestDriveHw $0
StrCpy $DestDrive "$0"
GetDlgItem $6 $HWNDPARENT 1
EnableWindow $6 1
FunctionEnd
Function driveListFiller
SendMessage $DestDriveHw ${CB_ADDSTRING} 0 "STR:$9"
Push 1
FunctionEnd
Function Var123
Pop $Checkbox
MessageBox mb_ok "FIN Checkbox_State=$Checkbox_State Checkbox=$Checkbox"
${NSD_GetState} $Checkbox $0
${If} $0 <> 0
MessageBox mb_ok "Custom checkbox was checked... N=$0"
${EndIf}
${If} $0 == 0
MessageBox mb_ok "Custom checkbox ZERO... N=$0"
${EndIf}
Functionend
# Section #######################################
Section "" main
InitPluginsDir
File /oname=$PLUGINSDIR\syslinux.cfg "${NSISDIR}\plugins\syslinux.cfg"
File /oname=$PLUGINSDIR\syslinux.exe "${NSISDIR}\plugins\syslinux.exe"
File /oname=$PLUGINSDIR\nsExec.dll "${NSISDIR}\plugins\nsExec.dll"
StrCpy $R0 $DestDrive -1
;ExpandEnvStrings $0 %COMSPEC%
;nsExec::Exec '"$0" /c echo. | format $R0 /q /x /v:LiveUSB /fs:fat32'
nsExec::Exec '$PLUGINSDIR\syslinux.exe -maf -d boot\syslinux $R0'
;SendMessage $Checkbox ${BM_GETSTATE} 0 0 $0
;${If} $0 != 0
; MessageBox MB_OK checked!
;${EndIf}
;Pop $Checkbox
;MessageBox mb_ok "FIN Checkbox_State=$Checkbox_State Checkbox=$Checkbox"
;${NSD_GetState} $Checkbox $0
;${If} $0 <> 0
; MessageBox mb_ok "Custom checkbox was checked... N=$0"
;${EndIf}
CopyFiles $PLUGINSDIR\syslinux.cfg "$R0\syslinux.cfg"
SectionEnd
There is so much unrelated code in your example that it is a bit hard to understand what you really want to do.
If you want to retrieve the state of a checkbox on another page then you must save the state because the checkbox control is destroyed when you leave the page.
!include nsDialogs.nsh
Var hwndCheckbox
Var CheckboxState
Page Custom myPageWithCombobox myPageWithComboboxLeaveCallback
Page Custom myPageWithComboState
Function .onInit
StrCpy $CheckboxState ${BST_CHECKED} ; Set the initial state. This is optional but useful if you use $CheckboxState in a section when the installer is silent
FunctionEnd
Function myPageWithCombobox
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckbox} 80 203 100% 10u $(DrivePage_Text2)
Pop $hwndCheckbox
${NSD_SetState} $hwndCheckbox $CheckboxState ; Reuse the existing state so it is correct when the back button is used
nsDialogs::Show
FunctionEnd
Function myPageWithComboboxLeaveCallback
${NSD_GetState} $hwndCheckbox $CheckboxState ; Save the state so we can retrieve it on the next page
FunctionEnd
Function myPageWithComboState
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 160 CheckboxState=$CheckboxState
Pop $0
nsDialogs::Show
FunctionEnd
I have written a custom page where i want to change the label text on the fly .I tried following code but some how I could not bale to change the text .
Function Maintainance
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "The $CurrentVersion complete installation folder is available at the below link"
Pop $Label
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $0 1006
SendMessage $1 ${WM_SETTEXT} 0 "STR:new value 111111"
nsDialogs::Show
FunctionEnd
Any pointer on this will be a help.
The custom page is not visible until you call nsDialogs::Show. Any dynamic action has to happen after that with a timer or in response to a user action:
Page Custom MyPageCreate
Page InstFiles
!include nsDialogs.nsh
var mylabel
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 12u "Hello"
Pop $mylabel
${NSD_CreateButton} 0 50% 50% 12u "Change"
Pop $0
${NSD_OnClick} $0 ChangeIt
nsDialogs::Show
FunctionEnd
Function ChangeIt
System::Call kernel32::GetTickCount()i.r0
SendMessage $mylabel ${WM_SETTEXT} 0 "STR:World! $0"
FunctionEnd
Is it possible to add a window(a Label) to an existing MUI page; like the installer page, welcome page?
I would like to add a new label to the installer page. My code below adds a new Static window to the window but its never shown/sits above other windows. I know the window exists because I can see it using WinSpy++ but it sits behind another window. Also the new window has a funny style "Style: 50000000 (hidden, enabled)" whilst other normal static windows have the style "Style: 5000008C (visible, enabled)".
How can I get my label(Static Window) to show?
!include nsdialogs.nsh
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW instshow
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
OutFile "test.exe"
Function instshow
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $2 $0 1016
System::Call 'USER32::CreateWindowEx(i0,t "STATIC",t "Some option",i ${WS_CHILD}|${WS_VISIBLE},i100,i100,i100,i20,i$2,i666,i0,i0) $R2'
System::Call `user32::SetWindowPos(i $R2, i ${HWND_TOP}, i 0, i 0, i 0, i 0, i ${SWP_NOSIZE}|${SWP_NOMOVE})` # attempt to push new label to front
# Attempt to refresh new labels parent window
GetDlgItem $R0 $HWNDPARENT 1016
ShowWindow $R0 ${SW_HIDE}
ShowWindow $R0 ${SW_SHOW}
# Attempt to refresh new label
ShowWindow $R2 ${SW_HIDE}
ShowWindow $R2 ${SW_SHOW}
FunctionEnd
Section "Dummy"
SectionEnd
Ok heres how to do it. Thanks for the advice Anders
!include nsdialogs.nsh
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW instshow
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
OutFile "test.exe"
Function instshow
FindWindow $0 "#32770" "" $HWNDPARENT
System::Call 'USER32::CreateWindowEx(i0,t "STATIC",t "Some text",i ${WS_CHILD}|${WS_VISIBLE},i100,i100,i100,i20,i $0,i222,i0,i0) $R2'
GetDlgItem $1 $0 1027
GetDlgItem $2 $0 222
SendMessage $1 ${WM_GETFONT} 0 0 $3
SendMessage $2 ${WM_SETFONT} $3 1
FunctionEnd
Section "Dummy"
SectionEnd