Debian Codegraph @

Contrib/nsDialogs/example.nsi

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