2007-07-14 09:40:06 +00:00
Name " nsDialogs Example "
OutFile " nsDialogs Example.exe "
2017-09-25 16:37:49 +00:00
Caption " $(^Name) "
2007-07-14 09:40:06 +00:00
2019-03-06 19:00:49 +00:00
Unicode True
2007-07-14 09:40:06 +00:00
XPStyle on
2012-10-16 09:43:36 +00:00
RequestExecutionLevel user
2019-03-06 19:00:49 +00:00
!include nsDialogs.nsh
!include LogicLib.nsh
!include WinCore.nsh ; MAKELONG
2017-09-25 16:37:49 +00:00
LicenseText " All the action takes place on the next page... " " Start "
SubCaption 0 " : Ready? "
2007-07-14 09:40:06 +00:00
Page license
Page custom nsDialogsPage
2017-09-25 16:37:49 +00:00
Page custom LBPage
Page custom RangesPage
2017-09-29 18:56:30 +00:00
Page custom NotifyPage
2021-08-04 17:24:05 +00:00
Page custom RadioPage RadioLeave
2017-04-25 13:09:41 +00:00
! pragma warning disable 8000 ; "Page instfiles not used, no sections will be executed!"
2007-07-14 09:40:06 +00:00
Var BUTTON
Var EDIT
Var CHECKBOX
Function nsDialogsPage
2008-12-12 18:45:53 +00:00
nsDialogs :: Create 1018
2007-07-14 09:40:06 +00:00
Pop $0
GetFunctionAddress $0 OnBack
2008-12-12 18:45:53 +00:00
nsDialogs :: OnBack $0
2007-07-14 09:40:06 +00:00
${NSD_CreateButton} 0 0 100% 12u Test
Pop $BUTTON
GetFunctionAddress $0 OnClick
2008-12-12 18:45:53 +00:00
nsDialogs :: OnClick $BUTTON $0
2007-07-14 09:40:06 +00:00
${NSD_CreateText} 0 35 100% 12u hello
Pop $EDIT
GetFunctionAddress $0 OnChange
2008-12-12 18:45:53 +00:00
nsDialogs :: OnChange $EDIT $0
2017-09-28 12:11:08 +00:00
${NSD_Edit_SetCueBannerText} $EDIT 0 " Type 'hello there' and get a free surprise "
2007-07-14 09:40:06 +00:00
${NSD_CreateCheckbox} 0 - 50 100% 8u Test
Pop $CHECKBOX
GetFunctionAddress $0 OnCheckbox
2008-12-12 18:45:53 +00:00
nsDialogs :: OnClick $CHECKBOX $0
2007-07-14 09:40:06 +00:00
${NSD_CreateLabel} 0 40u 75% 40u " * Type `hello there` above.$\n* Click the button.$\n* Check the checkbox.$\n* Hit the Back button. "
Pop $0
nsDialogs :: Show
FunctionEnd
Function OnClick
2007-11-27 20:56:31 +00:00
Pop $0 # HWND
2007-07-14 09:40:06 +00:00
MessageBox MB_OK clicky
FunctionEnd
Function OnChange
2007-11-27 20:56:31 +00:00
Pop $0 # HWND
2013-09-06 23:48:59 +00:00
System :: Call user32 :: GetWindowText ( p$EDIT , t.r0, i${NSIS_MAX_STRLEN} )
2007-07-14 09:40:06 +00:00
${If} $0 == " hello there "
MessageBox MB_OK " right back at ya "
${EndIf}
FunctionEnd
Function OnBack
MessageBox MB_YESNO " are you sure? " IDYES + 2
Abort
FunctionEnd
Function OnCheckbox
2007-11-27 20:56:31 +00:00
Pop $0 # HWND
2007-07-14 09:40:06 +00:00
MessageBox MB_OK " checkbox clicked "
2017-09-25 16:37:49 +00:00
FunctionEnd
!macro BeginControlsTestPage title
nsDialogs :: Create 1018
Pop $0
${NSD_SetText} $hWndParent " $(^Name): ${title} "
!macroend
!macro CreateButton x y w h txt var handler data
${NSD_CreateButton} ${x} ${y} ${w} ${h} " ${txt} "
Pop ${var}
nsDialogs :: SetUserData ${var} ${data}
${NSD_OnClick} ${var} ${handler}
!macroend
Function LBPage
!insertmacro BeginControlsTestPage " ListBox "
2007-07-14 09:40:06 +00:00
2017-09-25 16:37:49 +00:00
${NSD_CreateSortedListBox} 1u 0 - 2u 70u " "
Pop $1
${NSD_LB_AddString} $1 " Foo "
${NSD_LB_AddString} $1 " Bar "
StrCpy $9 1
${NSD_CreateText} 1u 75u - 2u 12u " New item #$9 "
Pop $EDIT
!insertmacro CreateButton 1u 90u 50u 12u " Add (&Sorted) " $0 LBAction Add
2017-09-29 14:34:13 +00:00
!insertmacro CreateButton 53u 90u 50u 12u " &Prepend " $0 LBAction Prepend
!insertmacro CreateButton 105u 90u 50u 12u " &Append " $0 LBAction Append
!insertmacro CreateButton 160u 90u 50u 12u " &Delete Last " $0 LBAction DL
!insertmacro CreateButton 215u 90u 50u 12u " &Clear " $0 LBAction Clear
2017-09-25 16:37:49 +00:00
nsDialogs :: Show
FunctionEnd
Function LBAction
Pop $0
nsDialogs :: GetUserData $0
Pop $0
${NSD_GetText} $EDIT $8
${Select} $0
${Case} " Add "
${NSD_LB_AddString} $1 $8
${Case} " Prepend "
${NSD_LB_PrependString} $1 $8
${Case} " Append "
${NSD_LB_AppendString} $1 $8
${Case} " DL "
${NSD_LB_GetCount} $1 $8
${If} $8 U> 0
IntOp $8 $8 - 1
${NSD_LB_DelItem} $1 $8
${EndIf}
Return
2017-09-29 14:34:13 +00:00
${Case} " Clear "
2017-09-29 17:41:00 +00:00
${NSD_LB_Clear} $1
2017-09-29 14:34:13 +00:00
Return
2017-09-25 16:37:49 +00:00
${EndSelect}
IntOp $9 $9 + 1
${NSD_SetText} $EDIT " New item #$9 "
FunctionEnd
Function RangesPage
!insertmacro BeginControlsTestPage " Ranges "
${NSD_CreateHTrackBar} 1 0 - 2 20u " "
Pop $1
${NSD_TrackBar_SetRangeMax} $1 10
${NSD_TrackBar_SetTicFreq} $1 1
${NSD_TrackBar_SetPos} $1 3
StrCpy $9 20 ; Progress pos
${NSD_CreateProgressBar} 1 25u - 2 8u " "
Pop $2
${NSD_CreateTimer} RangesTimer 1000
2017-09-26 12:01:16 +00:00
${NSD_CreateNumber} 1 40u 50u 12u " 42 "
Pop $3
${NSD_CreateUpDown} 0 0 0 0 " "
Pop $4
${NSD_UD_SetBuddy} $4 $3
${MAKELONG} $5 $0 50 0 ; 0..50
${NSD_UD_SetPackedRange} $4 $5
2017-09-25 16:37:49 +00:00
nsDialogs :: Show
FunctionEnd
Function RangesTimer
IntOp $9 $9 + 5
${IfThen} $9 > 100 ${|} StrCpy $9 0 ${|}
${NSD_ProgressBar_SetPos} $2 $9
2007-07-14 09:40:06 +00:00
FunctionEnd
2017-09-25 16:37:49 +00:00
2017-09-29 18:56:30 +00:00
Function NotifyPage
!insertmacro BeginControlsTestPage " WM_NOTIFY "
2020-04-23 18:31:23 +00:00
nsDialogs :: CreateControl " ${__NSD_RichEdit_CLASS_20A} " " ${__NSD_RichEdit_STYLE} " " ${__NSD_RichEdit_EXSTYLE} " 1 1 - 2 50u " " ; Forcing ANSI control, see forums.winamp.com/showthread.php?p=3169999
2017-09-29 18:56:30 +00:00
Pop $9
${NSD_OnNotify} $9 OnNotify
2018-11-27 22:15:26 +00:00
IntOp $8 ${ENM_LINK} | ${ENM_KEYEVENTS}
${NSD_RichEd_SetEventMask} $9 $8
2017-09-29 18:56:30 +00:00
SendMessage $9 ${EM_AUTOURLDETECT} 1 0
2018-11-27 22:15:26 +00:00
${NSD_SetText} $9 " {\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard http://nsis.sf.net\par {\b Click the link!}\par\par Type something and I will block every other character...} "
2017-09-29 18:56:30 +00:00
2020-04-23 18:31:23 +00:00
${NSD_InitCommonControlsEx} ${ICC_DATE_CLASSES}
${NSD_CreateDatePicker} 1% 55u 48% 12u " "
Pop $1
${NSD_OnNotify} $1 onDateTimeNotify
${NSD_CreateLabel} 51% 56u 48% 12u " Change the date... "
Pop $9
/ *
${NSD_CreateCalendar} 1% 23% 150u 90u " "
Pop $1
${NSD_AddStyle} $1 ${MCS_NOTODAY}
System :: Call 'USER32::SendMessage(p$1, i${MCM_GETMINREQRECT}, p0, @r2)'
System :: Call '*$2(i,i,i.r2,i.r3)'
#System::Call 'USER32::SendMessage(p$1, i${MCM_GETMAXTODAYWIDTH}, p0, *i0r4)'
#${IfThen} $4 > $2 ${|} StrCpy $2 $4 ${|}
System :: Call 'USER32::SetWindowPos(p$1,p0,i,i,ir2,ir3,i0x16)'
* /
2017-09-29 18:56:30 +00:00
nsDialogs :: Show
FunctionEnd
Function OnNotify
Pop $1 ; HWND
Pop $2 ; Code
Pop $3 ; NMHDR*
2018-11-27 22:15:26 +00:00
${If} $2 = ${EN_LINK}
System :: Call '*$3(p,p,p,p.r2,p,p,i.r4,i.r5)' ; Extract from ENLINK*
${IfThen} $2 <> ${WM_LBUTTONDOWN} ${|} Return ${|}
IntOp $2 $5 - $4
System :: Call '*(ir4,ir5,l,&t$2,i)p.r2' ; Create TEXTRANGE and a text buffer
${If} $2 P< > 0
IntPtrOp $3 $2 + 16 ; Find buffer
System :: Call '*$2(i,i,p$3)' ; Set buffer in TEXTRANGE
SendMessage $1 ${EM_GETTEXTRANGE} " " $2 $4
${If} $4 <> 0
System :: Call 'SHELL32::ShellExecute(p$hWndParent, p0, pr3, p0, p0, i 1)'
${EndIf}
System :: Free $2
${EndIf}
${ElseIf} $2 = ${EN_MSGFILTER}
Var /Global Toggle
System :: Call '*$3(p,i,i,i.r4)' ; MSGFILTER->msg
${If} $4 = ${WM_CHAR}
IntOp $Toggle $Toggle ^ 1
${If} $Toggle & 1
${NSD_Return} 1
${EndIf}
2017-09-29 18:56:30 +00:00
${EndIf}
${EndIf}
FunctionEnd
2020-04-23 18:31:23 +00:00
Function onDateTimeNotify
Pop $1 ; HWND
Pop $2 ; Code
Pop $3 ; NMHDR*
${If} $2 = ${DTN_DATETIMECHANGE}
System :: Call 'USER32::SendMessage(p$1, i${DTM_GETSYSTEMTIME}, p0, @r3)i.r0'
${If} $0 = ${GDT_VALID}
System :: Call '*$3(&i2.R1, &i2.R2, &i2, &i2.R3, &i2, &i2, &i2, &i2)' ; SYSTEMTIME
StrCpy $0 " $R1 /$R2/$R3 "
${Else}
StrCpy $0 " N/A "
${EndIf}
${NSD_SetText} $9 $0
${EndIf}
FunctionEnd
2021-08-04 17:24:05 +00:00
Function RadioPage
!insertmacro BeginControlsTestPage " Radio buttons "
; Group 1
${NSD_CreateFirstRadioButton} 4u 0 40% 6% " NPR "
Pop $1
${NSD_OnClick} $1 onStationChanged
${NSD_CreateAdditionalRadioButton} 4u 12% 40% 6% " BBC "
Pop $2
${NSD_OnClick} $2 onStationChanged
${NSD_CreateLabel} 4u 30u 80% 12u " "
Pop $3
; Group 2
${NSD_CreateFirstRadioButton} 4u 50u 50% 12u " FM "
Pop $4
${NSD_CreateAdditionalRadioButton} 4u 64u 50% 12u " AM "
Pop $5
SendMessage $4 ${BM_CLICK} " " " " ; Must select a default
SendMessage $2 ${BM_CLICK} " " " " ; Must select a default
nsDialogs :: Show
FunctionEnd
Function onStationChanged
Pop $0
${NSD_GetText} $0 $0
${If} $0 == " NPR "
${NSD_SetText} $3 " America, f*(# yeah! "
${Else}
${NSD_SetText} $3 " Keep Calm and Carry On "
${EndIf}
FunctionEnd
Function RadioLeave
${NSD_GetChecked} $5 $0
${If} $0 <> 0
MessageBox MB_YESNO " Are you sure you want to keep living in the past? " IDYES + 2
Abort
${EndIf}
FunctionEnd
2007-07-14 09:40:06 +00:00
Section
SectionEnd