Old 6th March 2017, 11:39   #1
ascTim
Junior Member
 
Join Date: May 2015
Posts: 32
Unhappy NSDialogs GetText problems

Hey there.

It looks like I'm too confused after reading the manual to use the NSD_GetText function.

I want to create a custom page that asks for a Text input. And this text should be written into the registry.
The MessageBox on the last line gives an empty box, so it seems like it's not working.

Can anybody help me out?

PHP Code:
Var Dialog
Var Label
Var Text
Var DB

Function SETTINGS

    nsDialogs
::Create 1018
    Pop $Dialog

    
${If} $Dialog == error
        Abort
    
${EndIf}

    ${
NSD_CreateLabel0 0 11012u "What's the name of your database?"
    
Pop $Label

    
${NSD_CreateText0 13u 2512u "database_name"
    
Pop $Text

    nsDialogs
::Show
    
    
${NSD_GetText1018 $DB
    
    MessageBox MB_OK 
"$DB#my test if it works

FunctionEnd 
ascTim is offline   Reply With Quote
Old 6th March 2017, 14:39   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,588
The page does not exist after the show function ends, use the page leave callback function.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 7th March 2017, 08:23   #3
ascTim
Junior Member
 
Join Date: May 2015
Posts: 32
How do I do that exactly? I'm kinda unexperienced with custom pages...
ascTim is offline   Reply With Quote
Old 7th March 2017, 13:03   #4
Coby
Junior Member
 
Join Date: Feb 2016
Posts: 40
PHP Code:
# INFO #

Name `Test`
OutFile Test.exe
InstallDir $PROGRAMFILES
\Test

# COMPRESSOR #

SetCompressor /SOLID /FINAL lzma

# RUNTIME #

RequestExecutionLevel "USER"

# HIDE # SHOW #

ShowInstDetails nevershow
ShowUninstDetails NeverShow

# INCLUDES #

!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "nsDialogs.nsh"
!Include "WinMessages.nsh"
!include "WordFunc.nsh"
!include "FileFunc.nsh"

# STYLE & ICON #

BrandingText ` `

# PAGE #

!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit
Page custom 
"Page.Test" "Page.Test.Leave" 
Page instfiles "" "InstFilesPageShow"
Page custom "Page.Complete"

# LANGUAGE #

!insertmacro MUI_LANGUAGE English

# INIT #

Function .onInit
  InitPluginsDir
  SetOverwrite 
try
  
AllowSkipFiles off
FunctionEnd

# GUI #

Function onGUIInit
  MoveAnywhere
::Hook

  System
::Call user32::SetWindowLong(i$HWNDPARENT,i-16,0x9480084C)i.R0
  GetDlgItem 
$0 $HWNDPARENT 1034
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1035
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1036
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1037
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1038
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1039
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1256
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1028
  ShowWindow 
$${SW_HIDE}

  
System::Call user32::GetSystemMetrics(i0)i.r1
  System
::Call user32::GetSystemMetrics(i1)i.r2
  IntOp 
$$656
  IntOp 
$$2
  IntOp 
$$495
  IntOp 
$$2
  System
::Call user32::MoveWindow(i$HWNDPARENT,i$1,i$2,i656,i495,1)

  
System::Alloc 16
  System
::Call user32::GetWindowRect(i$HWNDPARENT,isR0)
  
System::Call *$R0(i.R1,i.R2,i.R3,i.R4)
  
IntOp $R3 $R3 $R1
  IntOp $R4 $R4 
$R2
  System
::Call gdi32::CreateRoundRectRgn(i0,i0,iR3,iR4,i9,i9)i.r0
  System
::Call user32::SetWindowRgn(i$HWNDPARENT,ir0,i1)
  
System::Free $R0
  System
::Call User32::GetDesktopWindow()i.R0

  SetCtlColors $HWNDPARENT 
"0xFFFFFF" "0xFF8C00"
FunctionEnd

# WELCOME #

Function "Page.Test"

  
var /GLOBAL Dialog
  
var /GLOBAL Lbl.Welcome
  
var /GLOBAL Btn_Close
  
var /GLOBAL Btn_Next
  
var /GLOBAL Lbl.Database
  
var /GLOBAL PATH_DATABASE 
  
var /GLOBAL DATABASE
  
var /GLOBAL Lbl.Show.Database
  
var /GLOBAL GroupBox

  GetDlgItem 
$0 $HWNDPARENT 1
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 2
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 3
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1990
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1991
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1992
  ShowWindow 
$${SW_HIDE}

  
System::Call "user32::SetWindowPos(i$HWNDPARENT,i,i,i,i 656,i 495,i 0x16)"
  
nsDialogs::Create /NOUNLOAD 1044
  Pop $Dialog 
  
${If} $Dialog == error 
    Abort 
  
${EndIf} 
  
System::Call "user32::MoveWindow(i$Dialog,i0,i0,i 656,i 495,i0)"

  
SetCtlColors $Dialog "0xFFFFFF" "0xFF8C00"

  
# WELCOME #

  
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 21604"Welcome!" 
  
Pop $Lbl.Welcome

  CreateFont 
$"$(^Font)" 14 300
  SendMessage $Lbl
.Welcome ${WM_SETFONT} $0 0

  SetCtlColors $Lbl
.Welcome "0xFFFFFF" "0xFF8C00"

  
# CLOSE #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 95144"x"
  
Pop $Btn_Close
  StrCpy 
$1 $Btn_Close
  GetFunctionAddress 
$".onClick.Close"
  
nsDialogs::onClick /NOUNLOAD $$3

  SetCtlColors $Btn_Close 
"0xFFFFFF" "0xFF8C00"

  
# DATABASE #

  
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 415603"What's the name of your database?" 
  
Pop $Lbl.Database 

  SetCtlColors $Lbl
.Database "0xFFFFFF" "0xFF8C00"

  
nsDialogs::CreateControl /NOUNLOAD EDIT 0x40000000|0x10000000|0x04000000|0x00010000|0x00000080 0 420605"" 
  
Pop $PATH_DATABASE 
  Strcpy 
$1 $PATH_DATABASE
  GetFunctionAddress 
$".onChange.Database"
  
nsDialogs::OnChange $$3

  SendMessage $PATH_DATABASE 
${WM_SETTEXT"STR:Please type here your name of database ..."

  
CreateFont $"$(^Font)" 14 300
  SendMessage $PATH_DATABASE 
${WM_SETFONT} $0 0

  SetCtlColors $PATH_DATABASE 
"0xFFFFFF" "0xffa332"

  
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 6521303"" 
  
Pop $Lbl.Show.Database 

  SetCtlColors $Lbl
.Show.Database "0xFFFFFF" "0xFF8C00"

  
# NEXT #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 3592256"$(^NextBtn)"
  
Pop $Btn_Next
  StrCpy 
$1 $Btn_Next
  GetFunctionAddress 
$".onClick.Next"
  
nsDialogs::onClick /NOUNLOAD $$3

  EnableWindow $Btn_Next 0

  SetCtlColors $Btn_Next 
"0xFFFFFF" "0xFF8C00"

  
# Groupbox #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 289680""
  
Pop $GroupBox

  SetCtlColors $GroupBox 
"0xFFFFFF" "0xFF8C00"

  
nsDialogs::Show 

FunctionEnd

# DATABASE #

Function ".onChange.Database"
  
Pop $PATH_DATABASE
  
${NSD_GetText$PATH_DATABASE $0
  StrCpy $DATABASE 
"$0"
    
SendMessage $Lbl.Show.Database ${WM_SETTEXT"STR:Database: $DATABASE"
  
${If} $DATABASE != "1"
    
EnableWindow $Btn_Next 1
  
${Else}
    
EnableWindow $Btn_Next 0
  
${EndIf}
FunctionEnd

# NEXT #

Function ".onClick.Next"
  
StrCpy $R9 1
  SendMessage $HWNDPARENT 0x408 1 0
  Abort
FunctionEnd

# LEAVE #

Function "Page.Test.Leave" 
  
${NSD_GetText$PATH_DATABASE $0
  
${If} $!= "$DATABASE"
     
MessageBox MB_OK "The database $DATABASE has been added successfully!"
  
${EndIf}
FunctionEnd

# CLOSE #

Function ".onClick.Close"
  
SendMessage $HWNDPARENT ${WM_CLOSE0 0
FunctionEnd

Function "InstFilesPageShow"
    
FindWindow $R2 "#32770" "" $HWNDPARENT

    ShowWindow 
$${SW_HIDE}
    
GetDlgItem $1 $R2 1027
    ShowWindow 
$${SW_HIDE}

    
GetDlgItem $0 $HWNDPARENT 1
    EnableWindow 
$0 0
    ShowWindow 
$${SW_HIDE}
    
GetDlgItem $0 $HWNDPARENT 2
    EnableWindow 
$0 0
    ShowWindow 
$${SW_HIDE}
    
GetDlgItem $0 $HWNDPARENT 3
    EnableWindow 
$0 0
    ShowWindow 
$${SW_HIDE}

    
# ...:: SIZE WINDOW ::... #

    
StrCpy $R0 $R2
    System
::Call "user32::MoveWindow(i R0, i 0, i 0, i 656, i 495) i r2"

    
# ...:: SHOW DETAILS ::... #

    
GetDlgItem $1 $R2 1027
    StrCpy 
$$1
    System
::Call user32::SetWindowPos(i$1,i0,i620,i6,i0,i0,i0x0001)
    
System::Call user32::SetWindowPos(i$1,i0,i0,i0,i22,i22,i0x0002)
    
System::Call "user32::SetWindowText(i $1, t $\"x")"
    ShowWindow $1 
${SW_SHOW}
    EnableWindow $1 1
    SetCtlColors $1 "
0xFFFFFF" "0xFF8C00"

    # ...:: PROGRESSBAR ::... #

    GetDlgItem 
$R0 $R2 1004
    SetCtlColors 
$R2 "0xFFFFFF" "0xFF8C00"
    System::Call "
user32::MoveWindow(i R0i 25i 400i 605i 6i r2"

    # ...:: DETAILPRINT ::... #

    GetDlgItem 
$R1 $R2 1006
    SetCtlColors 
$R1 "0xFFFFFF" "0xFF8C00"
    System::Call "
user32::MoveWindow(i R1i 25i 370i 605i 20i r2"
    CreateFont $1 "
$(^Font)" "$(^FontSize)"
    SendMessage 
$R1 ${WM_SETFONT} $1 0

    # ...:: SHOW DETAIL::... #

    GetDlgItem 
$R8 $R2 1016
    SetCtlColors 
$R8 "0xFFFFFF" "0xFF8C00"
    System::Call "
user32::MoveWindow(i R8i 25i 80i 605i 250i r2"

    # ...:: SKIN PROGRESS ::... #

    FindWindow 
$R2 "#32770" "" $HWNDPARENT
    
GetDlgItem $5 $R2 1004

    
# ...:: TITLE ::... #

    
FindWindow $R0 "#32770" "" $HWNDPARENT
    System
::Call 'User32::CreateWindowEx(i 0, t "STATIC", t "Welcome!", i ${WS_CHILD}|${WS_VISIBLE}|${WS_EX_TRANSPARENT}, i 10, i 8, i 580, i 35, i R0, i 0, i 0, i 0) i.R1'
    
CreateFont $"$(^Font)" "18" "500"
    
SendMessage $R1 ${WM_SETFONT} $1 0
    SetCtlColors $R1 
"0xFFFFFF" "0xFF8C00"

    
# ...:: GROUPBOX ::... #

    
FindWindow $R0 "#32770" "" $HWNDPARENT
    System
::Call 'User32::CreateWindowEx(i0,t"BUTTON",t"",i${BS_GROUPBOX}|${WS_CHILD}|${WS_VISIBLE},i10,i40,i635,i400,i$R0,i0X1042,i0,i0) i.R4'

    
SetCtlColors $R4 "0xFFFFFF" "0xFF8C00"
FunctionEnd

# SECTION #

Section "MAIN" SEC01

 DetailPrint 
`Installing ... Please wait ...`

 
Sleep 500
 Sleep 500
 Sleep 500
 Sleep 500
 Sleep 1000
 Sleep 500
 Sleep 500
 Sleep 500
 Sleep 500

 Sleep 500
 Sleep 500
 Sleep 500
 Sleep 500
 Sleep 1000
 Sleep 500
 Sleep 500
 Sleep 500
 Sleep 500

 Setautoclose 
"True"
SectionEnd

#...:: FINISH ::... #

Function "Page.Complete"

  
var /GLOBAL Lbl.Finish
  
var /GLOBAL Btn_Exit

  GetDlgItem 
$0 $HWNDPARENT 1
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 2
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 3
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1990
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1991
  ShowWindow 
$${SW_HIDE}
  
GetDlgItem $0 $HWNDPARENT 1992
  ShowWindow 
$${SW_HIDE}

  
System::Call "user32::SetWindowPos(i$HWNDPARENT,i,i,i,i 656,i 495,i 0x16)"
  
nsDialogs::Create /NOUNLOAD 1044
  Pop $Dialog 
  
${If} $Dialog == error 
    Abort 
  
${EndIf} 
  
System::Call "user32::MoveWindow(i$Dialog,i0,i0,i 656,i 495,i0)"

  
SetCtlColors $Dialog "0xFFFFFF" "0xFF8C00"

  
# FINISH #

  
nsDialogs::CreateControl /NOUNLOAD STATIC 0x40000000|0x10000000|0x04000000|0x00000100 0x00000020 21604"Completed!" 
  
Pop $Lbl.Finish

  CreateFont 
$"$(^Font)" 14 300
  SendMessage $Lbl
.Finish ${WM_SETFONT} $0 0

  SetCtlColors $Lbl
.Finish "0xFFFFFF" "0xFF8C00"

  
# CLOSE #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 95144"x"
  
Pop $Btn_Close
  StrCpy 
$1 $Btn_Close
  GetFunctionAddress 
$".OnClick.Finish"
  
nsDialogs::onClick /NOUNLOAD $$3

  SetCtlColors $Btn_Close 
"0xFFFFFF" "0xFF8C00"

  
# EXIT #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00010000 0 3592256"$(^CloseBtn)"
  
Pop $Btn_Exit
  StrCpy 
$1 $Btn_Exit
  GetFunctionAddress 
$".OnClick.Finish"
  
nsDialogs::onClick /NOUNLOAD $$3

  SetCtlColors $Btn_Exit 
"0xFFFFFF" "0xFF8C00"

  
# Groupbox #

  
nsDialogs::CreateControl /NOUNLOAD BUTTON 0x40000000|0x10000000|0x04000000|0x00000007 0x00000080 289680""
  
Pop $GroupBox

  SetCtlColors $GroupBox 
"0xFFFFFF" "0xFF8C00"

  
nsDialogs::Show

FunctionEnd

# ...:: Finish ::... #

Function ".OnClick.Finish"
  
SendMessage $HWNDPARENT 0x408 1 0
FunctionEnd

# END #

Function .onGUIEnd
FunctionEnd 
Coby is offline   Reply With Quote
Old 7th March 2017, 15:12   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,588
PHP Code:
Var Dialog 
Var Label 
Var Text 
Var DB 

Function .onInit
StrCpy $DB 
"database_name"  initial value
FunctionEnd

!include nsDialogs.nsh
Function SETTINGS 
    nsDialogs
::Create 1018 
    Pop $Dialog 

    
${If} $Dialog == error 
        Abort 
    
${EndIf} 

    ${
NSD_CreateLabel0 0 11012u "What's the name of your database?" 
    
Pop $Label 
    
${NSD_CreateText0 13u 2512u "$DB
    
Pop $Text 

    nsDialogs
::Show 

    MessageBox MB_OK 
"$DB#my test if it works 
FunctionEnd  

Function SETTINGS_Leave
    
${NSD_GetText$Text $DB 
FunctionEnd

Page Custom SETTINGS SETTINGS_Leave
Page Components
Page InstFiles 
---

Why do you always make things complicated Coby? This is your final warning, post relevant and minimal code or get banned.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 8th March 2017, 15:54   #6
ascTim
Junior Member
 
Join Date: May 2015
Posts: 32
I see, this works perfectly!

Thanks for the help!
ascTim is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump