example.nsi 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. Name "nsDialogs Example"
  2. OutFile "nsDialogs Example.exe"
  3. Caption "$(^Name)"
  4. Unicode True
  5. XPStyle on
  6. RequestExecutionLevel user
  7. !include nsDialogs.nsh
  8. !include LogicLib.nsh
  9. !include WinCore.nsh ; MAKELONG
  10. LicenseText "All the action takes place on the next page..." "Start"
  11. SubCaption 0 ": Ready?"
  12. Page license
  13. Page custom nsDialogsPage
  14. Page custom LBPage
  15. Page custom RangesPage
  16. Page custom NotifyPage
  17. Page custom RadioPage RadioLeave
  18. !pragma warning disable 8000 ; "Page instfiles not used, no sections will be executed!"
  19. Var BUTTON
  20. Var EDIT
  21. Var CHECKBOX
  22. Function nsDialogsPage
  23. nsDialogs::Create 1018
  24. Pop $0
  25. GetFunctionAddress $0 OnBack
  26. nsDialogs::OnBack $0
  27. ${NSD_CreateButton} 0 0 100% 12u Test
  28. Pop $BUTTON
  29. GetFunctionAddress $0 OnClick
  30. nsDialogs::OnClick $BUTTON $0
  31. ${NSD_CreateText} 0 35 100% 12u hello
  32. Pop $EDIT
  33. GetFunctionAddress $0 OnChange
  34. nsDialogs::OnChange $EDIT $0
  35. ${NSD_Edit_SetCueBannerText} $EDIT 0 "Type 'hello there' and get a free surprise"
  36. ${NSD_CreateCheckbox} 0 -50 100% 8u Test
  37. Pop $CHECKBOX
  38. GetFunctionAddress $0 OnCheckbox
  39. nsDialogs::OnClick $CHECKBOX $0
  40. ${NSD_CreateLabel} 0 40u 75% 40u "* Type `hello there` above.$\n* Click the button.$\n* Check the checkbox.$\n* Hit the Back button."
  41. Pop $0
  42. nsDialogs::Show
  43. FunctionEnd
  44. Function OnClick
  45. Pop $0 # HWND
  46. MessageBox MB_OK clicky
  47. FunctionEnd
  48. Function OnChange
  49. Pop $0 # HWND
  50. System::Call user32::GetWindowText(p$EDIT,t.r0,i${NSIS_MAX_STRLEN})
  51. ${If} $0 == "hello there"
  52. MessageBox MB_OK "right back at ya"
  53. ${EndIf}
  54. FunctionEnd
  55. Function OnBack
  56. MessageBox MB_YESNO "are you sure?" IDYES +2
  57. Abort
  58. FunctionEnd
  59. Function OnCheckbox
  60. Pop $0 # HWND
  61. MessageBox MB_OK "checkbox clicked"
  62. FunctionEnd
  63. !macro BeginControlsTestPage title
  64. nsDialogs::Create 1018
  65. Pop $0
  66. ${NSD_SetText} $hWndParent "$(^Name): ${title}"
  67. !macroend
  68. !macro CreateButton x y w h txt var handler data
  69. ${NSD_CreateButton} ${x} ${y} ${w} ${h} "${txt}"
  70. Pop ${var}
  71. nsDialogs::SetUserData ${var} ${data}
  72. ${NSD_OnClick} ${var} ${handler}
  73. !macroend
  74. Function LBPage
  75. !insertmacro BeginControlsTestPage "ListBox"
  76. ${NSD_CreateSortedListBox} 1u 0 -2u 70u ""
  77. Pop $1
  78. ${NSD_LB_AddString} $1 "Foo"
  79. ${NSD_LB_AddString} $1 "Bar"
  80. StrCpy $9 1
  81. ${NSD_CreateText} 1u 75u -2u 12u "New item #$9"
  82. Pop $EDIT
  83. !insertmacro CreateButton 1u 90u 50u 12u "Add (&Sorted)" $0 LBAction Add
  84. !insertmacro CreateButton 53u 90u 50u 12u "&Prepend" $0 LBAction Prepend
  85. !insertmacro CreateButton 105u 90u 50u 12u "&Append" $0 LBAction Append
  86. !insertmacro CreateButton 160u 90u 50u 12u "&Delete Last" $0 LBAction DL
  87. !insertmacro CreateButton 215u 90u 50u 12u "&Clear" $0 LBAction Clear
  88. nsDialogs::Show
  89. FunctionEnd
  90. Function LBAction
  91. Pop $0
  92. nsDialogs::GetUserData $0
  93. Pop $0
  94. ${NSD_GetText} $EDIT $8
  95. ${Select} $0
  96. ${Case} "Add"
  97. ${NSD_LB_AddString} $1 $8
  98. ${Case} "Prepend"
  99. ${NSD_LB_PrependString} $1 $8
  100. ${Case} "Append"
  101. ${NSD_LB_AppendString} $1 $8
  102. ${Case} "DL"
  103. ${NSD_LB_GetCount} $1 $8
  104. ${If} $8 U> 0
  105. IntOp $8 $8 - 1
  106. ${NSD_LB_DelItem} $1 $8
  107. ${EndIf}
  108. Return
  109. ${Case} "Clear"
  110. ${NSD_LB_Clear} $1
  111. Return
  112. ${EndSelect}
  113. IntOp $9 $9 + 1
  114. ${NSD_SetText} $EDIT "New item #$9"
  115. FunctionEnd
  116. Function RangesPage
  117. !insertmacro BeginControlsTestPage "Ranges"
  118. ${NSD_CreateHTrackBar} 1 0 -2 20u ""
  119. Pop $1
  120. ${NSD_TrackBar_SetRangeMax} $1 10
  121. ${NSD_TrackBar_SetTicFreq} $1 1
  122. ${NSD_TrackBar_SetPos} $1 3
  123. StrCpy $9 20 ; Progress pos
  124. ${NSD_CreateProgressBar} 1 25u -2 8u ""
  125. Pop $2
  126. ${NSD_CreateTimer} RangesTimer 1000
  127. ${NSD_CreateNumber} 1 40u 50u 12u "42"
  128. Pop $3
  129. ${NSD_CreateUpDown} 0 0 0 0 ""
  130. Pop $4
  131. ${NSD_UD_SetBuddy} $4 $3
  132. ${MAKELONG} $5 $0 50 0 ; 0..50
  133. ${NSD_UD_SetPackedRange} $4 $5
  134. nsDialogs::Show
  135. FunctionEnd
  136. Function RangesTimer
  137. IntOp $9 $9 + 5
  138. ${IfThen} $9 > 100 ${|} StrCpy $9 0 ${|}
  139. ${NSD_ProgressBar_SetPos} $2 $9
  140. FunctionEnd
  141. Function NotifyPage
  142. !insertmacro BeginControlsTestPage "WM_NOTIFY"
  143. 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
  144. Pop $9
  145. ${NSD_OnNotify} $9 OnNotify
  146. IntOp $8 ${ENM_LINK} | ${ENM_KEYEVENTS}
  147. ${NSD_RichEd_SetEventMask} $9 $8
  148. SendMessage $9 ${EM_AUTOURLDETECT} 1 0
  149. ${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...}"
  150. ${NSD_InitCommonControlsEx} ${ICC_DATE_CLASSES}
  151. ${NSD_CreateDatePicker} 1% 55u 48% 12u ""
  152. Pop $1
  153. ${NSD_OnNotify} $1 onDateTimeNotify
  154. ${NSD_CreateLabel} 51% 56u 48% 12u "Change the date..."
  155. Pop $9
  156. /*
  157. ${NSD_CreateCalendar} 1% 23% 150u 90u ""
  158. Pop $1
  159. ${NSD_AddStyle} $1 ${MCS_NOTODAY}
  160. System::Call 'USER32::SendMessage(p$1, i${MCM_GETMINREQRECT}, p0, @r2)'
  161. System::Call '*$2(i,i,i.r2,i.r3)'
  162. #System::Call 'USER32::SendMessage(p$1, i${MCM_GETMAXTODAYWIDTH}, p0, *i0r4)'
  163. #${IfThen} $4 > $2 ${|} StrCpy $2 $4 ${|}
  164. System::Call 'USER32::SetWindowPos(p$1,p0,i,i,ir2,ir3,i0x16)'
  165. */
  166. nsDialogs::Show
  167. FunctionEnd
  168. Function OnNotify
  169. Pop $1 ; HWND
  170. Pop $2 ; Code
  171. Pop $3 ; NMHDR*
  172. ${If} $2 = ${EN_LINK}
  173. System::Call '*$3(p,p,p,p.r2,p,p,i.r4,i.r5)' ; Extract from ENLINK*
  174. ${IfThen} $2 <> ${WM_LBUTTONDOWN} ${|} Return ${|}
  175. IntOp $2 $5 - $4
  176. System::Call '*(ir4,ir5,l,&t$2,i)p.r2' ; Create TEXTRANGE and a text buffer
  177. ${If} $2 P<> 0
  178. IntPtrOp $3 $2 + 16 ; Find buffer
  179. System::Call '*$2(i,i,p$3)' ; Set buffer in TEXTRANGE
  180. SendMessage $1 ${EM_GETTEXTRANGE} "" $2 $4
  181. ${If} $4 <> 0
  182. System::Call 'SHELL32::ShellExecute(p$hWndParent, p0, pr3, p0, p0, i 1)'
  183. ${EndIf}
  184. System::Free $2
  185. ${EndIf}
  186. ${ElseIf} $2 = ${EN_MSGFILTER}
  187. Var /Global Toggle
  188. System::Call '*$3(p,i,i,i.r4)' ; MSGFILTER->msg
  189. ${If} $4 = ${WM_CHAR}
  190. IntOp $Toggle $Toggle ^ 1
  191. ${If} $Toggle & 1
  192. ${NSD_Return} 1
  193. ${EndIf}
  194. ${EndIf}
  195. ${EndIf}
  196. FunctionEnd
  197. Function onDateTimeNotify
  198. Pop $1 ; HWND
  199. Pop $2 ; Code
  200. Pop $3 ; NMHDR*
  201. ${If} $2 = ${DTN_DATETIMECHANGE}
  202. System::Call 'USER32::SendMessage(p$1, i${DTM_GETSYSTEMTIME}, p0, @r3)i.r0'
  203. ${If} $0 = ${GDT_VALID}
  204. System::Call '*$3(&i2.R1, &i2.R2, &i2, &i2.R3, &i2, &i2, &i2, &i2)' ; SYSTEMTIME
  205. StrCpy $0 "$R1/$R2/$R3"
  206. ${Else}
  207. StrCpy $0 "N/A"
  208. ${EndIf}
  209. ${NSD_SetText} $9 $0
  210. ${EndIf}
  211. FunctionEnd
  212. Function RadioPage
  213. !insertmacro BeginControlsTestPage "Radio buttons"
  214. ; Group 1
  215. ${NSD_CreateFirstRadioButton} 4u 0 40% 6% "NPR"
  216. Pop $1
  217. ${NSD_OnClick} $1 onStationChanged
  218. ${NSD_CreateAdditionalRadioButton} 4u 12% 40% 6% "BBC"
  219. Pop $2
  220. ${NSD_OnClick} $2 onStationChanged
  221. ${NSD_CreateLabel} 4u 30u 80% 12u ""
  222. Pop $3
  223. ; Group 2
  224. ${NSD_CreateFirstRadioButton} 4u 50u 50% 12u "FM"
  225. Pop $4
  226. ${NSD_CreateAdditionalRadioButton} 4u 64u 50% 12u "AM"
  227. Pop $5
  228. SendMessage $4 ${BM_CLICK} "" "" ; Must select a default
  229. SendMessage $2 ${BM_CLICK} "" "" ; Must select a default
  230. nsDialogs::Show
  231. FunctionEnd
  232. Function onStationChanged
  233. Pop $0
  234. ${NSD_GetText} $0 $0
  235. ${If} $0 == "NPR"
  236. ${NSD_SetText} $3 "America, f*(# yeah!"
  237. ${Else}
  238. ${NSD_SetText} $3 "Keep Calm and Carry On"
  239. ${EndIf}
  240. FunctionEnd
  241. Function RadioLeave
  242. ${NSD_GetChecked} $5 $0
  243. ${If} $0 <> 0
  244. MessageBox MB_YESNO "Are you sure you want to keep living in the past?" IDYES +2
  245. Abort
  246. ${EndIf}
  247. FunctionEnd
  248. Section
  249. SectionEnd