CodeClasses.iss 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. ; -- CodeClasses.iss --
  2. ;
  3. ; This script shows how to use the WizardForm object and the various VCL classes.
  4. [Setup]
  5. AppName=My Program
  6. AppVersion=1.5
  7. WizardStyle=modern
  8. CreateAppDir=no
  9. DisableProgramGroupPage=yes
  10. DefaultGroupName=My Program
  11. UninstallDisplayIcon={app}\MyProg.exe
  12. OutputDir=userdocs:Inno Setup Examples Output
  13. PrivilegesRequired=lowest
  14. ; Uncomment the following three lines to test the layout when scaling and rtl are active
  15. ;[LangOptions]
  16. ;RightToLeft=yes
  17. ;DialogFontSize=12
  18. [Files]
  19. Source: compiler:WizClassicSmallImage.bmp; Flags: dontcopy
  20. [Code]
  21. procedure ButtonOnClick(Sender: TObject);
  22. begin
  23. MsgBox('You clicked the button!', mbInformation, mb_Ok);
  24. end;
  25. procedure BitmapImageOnClick(Sender: TObject);
  26. begin
  27. MsgBox('You clicked the image!', mbInformation, mb_Ok);
  28. end;
  29. procedure FormButtonOnClick(Sender: TObject);
  30. var
  31. Form: TSetupForm;
  32. Edit: TNewEdit;
  33. OKButton, CancelButton: TNewButton;
  34. W: Integer;
  35. begin
  36. Form := CreateCustomForm();
  37. try
  38. Form.ClientWidth := ScaleX(256);
  39. Form.ClientHeight := ScaleY(128);
  40. Form.Caption := 'TSetupForm';
  41. Edit := TNewEdit.Create(Form);
  42. Edit.Top := ScaleY(10);
  43. Edit.Left := ScaleX(10);
  44. Edit.Width := Form.ClientWidth - ScaleX(2 * 10);
  45. Edit.Height := ScaleY(23);
  46. Edit.Anchors := [akLeft, akTop, akRight];
  47. Edit.Text := 'TNewEdit';
  48. Edit.Parent := Form;
  49. OKButton := TNewButton.Create(Form);
  50. OKButton.Parent := Form;
  51. OKButton.Caption := 'OK';
  52. OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
  53. OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  54. OKButton.Height := ScaleY(23);
  55. OKButton.Anchors := [akRight, akBottom]
  56. OKButton.ModalResult := mrOk;
  57. OKButton.Default := True;
  58. CancelButton := TNewButton.Create(Form);
  59. CancelButton.Parent := Form;
  60. CancelButton.Caption := 'Cancel';
  61. CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
  62. CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  63. CancelButton.Height := ScaleY(23);
  64. CancelButton.Anchors := [akRight, akBottom]
  65. CancelButton.ModalResult := mrCancel;
  66. CancelButton.Cancel := True;
  67. W := Form.CalculateButtonWidth([OKButton.Caption, CancelButton.Caption]);
  68. OKButton.Width := W;
  69. CancelButton.Width := W;
  70. Form.ActiveControl := Edit;
  71. { Keep the form from sizing vertically since we don't have any controls which can size vertically }
  72. Form.KeepSizeY := True;
  73. { Center on WizardForm. Without this call it will still automatically center, but on the screen }
  74. Form.FlipSizeAndCenterIfNeeded(True, WizardForm, False);
  75. if Form.ShowModal() = mrOk then
  76. MsgBox('You clicked OK.', mbInformation, MB_OK);
  77. finally
  78. Form.Free();
  79. end;
  80. end;
  81. procedure TaskDialogButtonOnClick(Sender: TObject);
  82. begin
  83. { TaskDialogMsgBox isn't a class but showing it anyway since it fits with the theme }
  84. case TaskDialogMsgBox('Choose A or B',
  85. 'You can choose A or B.',
  86. mbInformation,
  87. MB_YESNOCANCEL, ['I choose &A'#13#10'A will be chosen.', 'I choose &B'#13#10'B will be chosen.'],
  88. IDYES) of
  89. IDYES: MsgBox('You chose A.', mbInformation, MB_OK);
  90. IDNO: MsgBox('You chose B.', mbInformation, MB_OK);
  91. end;
  92. end;
  93. procedure CreateTheWizardPages;
  94. var
  95. Page: TWizardPage;
  96. Button, FormButton, TaskDialogButton: TNewButton;
  97. Panel: TPanel;
  98. CheckBox: TNewCheckBox;
  99. Edit: TNewEdit;
  100. PasswordEdit: TPasswordEdit;
  101. Memo: TNewMemo;
  102. ComboBox: TNewComboBox;
  103. ListBox: TNewListBox;
  104. StaticText, ProgressBarLabel: TNewStaticText;
  105. ProgressBar, ProgressBar2, ProgressBar3: TNewProgressBar;
  106. CheckListBox, CheckListBox2: TNewCheckListBox;
  107. FolderTreeView: TFolderTreeView;
  108. BitmapImage, BitmapImage2, BitmapImage3: TBitmapImage;
  109. BitmapFileName: String;
  110. RichEditViewer: TRichEditViewer;
  111. begin
  112. { TButton and others }
  113. Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'TButton and others');
  114. Button := TNewButton.Create(Page);
  115. Button.Caption := 'TNewButton';
  116. Button.Width := WizardForm.CalculateButtonWidth([Button.Caption]);
  117. Button.Height := ScaleY(23);
  118. Button.OnClick := @ButtonOnClick;
  119. Button.Parent := Page.Surface;
  120. Panel := TPanel.Create(Page);
  121. Panel.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  122. Panel.Left := Page.SurfaceWidth - Panel.Width;
  123. Panel.Height := Button.Height * 2;
  124. Panel.Anchors := [akLeft, akTop, akRight];
  125. Panel.Caption := 'TPanel';
  126. Panel.Color := clWindow;
  127. Panel.BevelKind := bkFlat;
  128. Panel.BevelOuter := bvNone;
  129. Panel.ParentBackground := False;
  130. Panel.Parent := Page.Surface;
  131. CheckBox := TNewCheckBox.Create(Page);
  132. CheckBox.Top := Button.Top + Button.Height + ScaleY(8);
  133. CheckBox.Width := Page.SurfaceWidth div 2;
  134. CheckBox.Height := ScaleY(17);
  135. CheckBox.Caption := 'TNewCheckBox';
  136. CheckBox.Checked := True;
  137. CheckBox.Parent := Page.Surface;
  138. Edit := TNewEdit.Create(Page);
  139. Edit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  140. Edit.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  141. Edit.Text := 'TNewEdit';
  142. Edit.Parent := Page.Surface;
  143. PasswordEdit := TPasswordEdit.Create(Page);
  144. PasswordEdit.Left := Page.SurfaceWidth - Edit.Width;
  145. PasswordEdit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  146. PasswordEdit.Width := Edit.Width;
  147. PasswordEdit.Anchors := [akLeft, akTop, akRight];
  148. PasswordEdit.Text := 'TPasswordEdit';
  149. PasswordEdit.Parent := Page.Surface;
  150. Memo := TNewMemo.Create(Page);
  151. Memo.Top := Edit.Top + Edit.Height + ScaleY(8);
  152. Memo.Width := Page.SurfaceWidth;
  153. Memo.Height := ScaleY(89);
  154. Memo.Anchors := [akLeft, akTop, akRight, akBottom];
  155. Memo.ScrollBars := ssVertical;
  156. Memo.Text := 'TNewMemo';
  157. Memo.Parent := Page.Surface;
  158. FormButton := TNewButton.Create(Page);
  159. FormButton.Caption := 'TSetupForm';
  160. FormButton.Top := Memo.Top + Memo.Height + ScaleY(8);
  161. FormButton.Width := WizardForm.CalculateButtonWidth([FormButton.Caption]);
  162. FormButton.Height := ScaleY(23);
  163. FormButton.Anchors := [akLeft, akBottom];
  164. FormButton.OnClick := @FormButtonOnClick;
  165. FormButton.Parent := Page.Surface;
  166. TaskDialogButton := TNewButton.Create(Page);
  167. TaskDialogButton.Caption := 'TaskDialogMsgBox';
  168. TaskDialogButton.Top := FormButton.Top;
  169. TaskDialogButton.Left := FormButton.Left + FormButton.Width + ScaleX(8);
  170. TaskDialogButton.Width := WizardForm.CalculateButtonWidth([TaskDialogButton.Caption]);
  171. TaskDialogButton.Height := ScaleY(23);
  172. TaskDialogButton.Anchors := [akLeft, akBottom];
  173. TaskDialogButton.OnClick := @TaskDialogButtonOnClick;
  174. TaskDialogButton.Parent := Page.Surface;
  175. { TComboBox and others }
  176. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TComboBox and others');
  177. ComboBox := TNewComboBox.Create(Page);
  178. ComboBox.Width := Page.SurfaceWidth;
  179. ComboBox.Anchors := [akLeft, akTop, akRight];
  180. ComboBox.Parent := Page.Surface;
  181. ComboBox.Style := csDropDownList;
  182. ComboBox.Items.Add('TComboBox');
  183. ComboBox.ItemIndex := 0;
  184. ListBox := TNewListBox.Create(Page);
  185. ListBox.Top := ComboBox.Top + ComboBox.Height + ScaleY(8);
  186. ListBox.Width := Page.SurfaceWidth;
  187. ListBox.Height := ScaleY(97);
  188. ListBox.Anchors := [akLeft, akTop, akRight, akBottom];
  189. ListBox.Parent := Page.Surface;
  190. ListBox.Items.Add('TListBox');
  191. ListBox.ItemIndex := 0;
  192. StaticText := TNewStaticText.Create(Page);
  193. StaticText.Top := ListBox.Top + ListBox.Height + ScaleY(8);
  194. StaticText.Anchors := [akLeft, akRight, akBottom];
  195. StaticText.Caption := 'TNewStaticText';
  196. StaticText.AutoSize := True;
  197. StaticText.Parent := Page.Surface;
  198. ProgressBarLabel := TNewStaticText.Create(Page);
  199. ProgressBarLabel.Top := StaticText.Top + StaticText.Height + ScaleY(8);
  200. ProgressBarLabel.Anchors := [akLeft, akBottom];
  201. ProgressBarLabel.Caption := 'TNewProgressBar';
  202. ProgressBarLabel.AutoSize := True;
  203. ProgressBarLabel.Parent := Page.Surface;
  204. ProgressBar := TNewProgressBar.Create(Page);
  205. ProgressBar.Left := ProgressBarLabel.Width + ScaleX(8);
  206. ProgressBar.Top := ProgressBarLabel.Top;
  207. ProgressBar.Width := Page.SurfaceWidth - ProgressBar.Left;
  208. ProgressBar.Height := ProgressBarLabel.Height + ScaleY(8);
  209. ProgressBar.Anchors := [akLeft, akRight, akBottom];
  210. ProgressBar.Parent := Page.Surface;
  211. ProgressBar.Position := 25;
  212. ProgressBar2 := TNewProgressBar.Create(Page);
  213. ProgressBar2.Left := ProgressBarLabel.Width + ScaleX(8);
  214. ProgressBar2.Top := ProgressBar.Top + ProgressBar.Height + ScaleY(4);
  215. ProgressBar2.Width := Page.SurfaceWidth - ProgressBar.Left;
  216. ProgressBar2.Height := ProgressBarLabel.Height + ScaleY(8);
  217. ProgressBar2.Anchors := [akLeft, akRight, akBottom];
  218. ProgressBar2.Parent := Page.Surface;
  219. ProgressBar2.Position := 50;
  220. ProgressBar2.State := npbsError;
  221. ProgressBar3 := TNewProgressBar.Create(Page);
  222. ProgressBar3.Left := ProgressBarLabel.Width + ScaleX(8);
  223. ProgressBar3.Top := ProgressBar2.Top + ProgressBar2.Height + ScaleY(4);
  224. ProgressBar3.Width := Page.SurfaceWidth - ProgressBar.Left;
  225. ProgressBar3.Height := ProgressBarLabel.Height + ScaleY(8);
  226. ProgressBar3.Anchors := [akLeft, akRight, akBottom];
  227. ProgressBar3.Parent := Page.Surface;
  228. ProgressBar3.Style := npbstMarquee;
  229. { TNewCheckListBox }
  230. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TNewCheckListBox');
  231. CheckListBox := TNewCheckListBox.Create(Page);
  232. CheckListBox.Width := Page.SurfaceWidth;
  233. CheckListBox.Height := ScaleY(97);
  234. CheckListBox.Anchors := [akLeft, akTop, akRight, akBottom];
  235. CheckListBox.Flat := True;
  236. CheckListBox.Parent := Page.Surface;
  237. CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  238. CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, True, True, nil);
  239. CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, False, True, nil);
  240. CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  241. CheckListBox.AddCheckBox('TNewCheckListBox', '', 1, True, True, False, True, nil);
  242. CheckListBox.AddCheckBox('TNewCheckListBox', '123', 2, True, True, False, True, nil);
  243. CheckListBox.AddCheckBox('TNewCheckListBox', '456', 2, False, True, False, True, nil);
  244. CheckListBox.AddCheckBox('TNewCheckListBox', '', 1, False, True, False, True, nil);
  245. CheckListBox.ItemFontStyle[5] := [fsBold];
  246. CheckListBox.SubItemFontStyle[5] := [fsBold];
  247. CheckListBox.ItemFontStyle[6] := [fsBold, fsItalic];
  248. CheckListBox.SubItemFontStyle[6] := [fsBold, fsUnderline];
  249. CheckListBox2 := TNewCheckListBox.Create(Page);
  250. CheckListBox2.Top := CheckListBox.Top + CheckListBox.Height + ScaleY(8);
  251. CheckListBox2.Width := Page.SurfaceWidth;
  252. CheckListBox2.Height := ScaleY(97);
  253. CheckListBox2.Anchors := [akLeft, akRight, akBottom];
  254. CheckListBox2.BorderStyle := bsNone;
  255. CheckListBox2.ParentColor := True;
  256. CheckListBox2.MinItemHeight := WizardForm.TasksList.MinItemHeight;
  257. CheckListBox2.ShowLines := False;
  258. CheckListBox2.WantTabs := True;
  259. CheckListBox2.Parent := Page.Surface;
  260. CheckListBox2.AddGroup('TNewCheckListBox', '', 0, nil);
  261. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, True, True, nil);
  262. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, False, True, nil);
  263. { TFolderTreeView }
  264. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TFolderTreeView');
  265. FolderTreeView := TFolderTreeView.Create(Page);
  266. FolderTreeView.Width := Page.SurfaceWidth;
  267. FolderTreeView.Height := Page.SurfaceHeight;
  268. FolderTreeView.Anchors := [akLeft, akTop, akRight, akBottom];
  269. FolderTreeView.Parent := Page.Surface;
  270. FolderTreeView.Directory := ExpandConstant('{src}');
  271. { TBitmapImage }
  272. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TBitmapImage');
  273. BitmapFileName := ExpandConstant('{tmp}\WizClassicSmallImage.bmp');
  274. ExtractTemporaryFile(ExtractFileName(BitmapFileName));
  275. BitmapImage := TBitmapImage.Create(Page);
  276. BitmapImage.AutoSize := True;
  277. BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
  278. BitmapImage.Cursor := crHand;
  279. BitmapImage.OnClick := @BitmapImageOnClick;
  280. BitmapImage.Parent := Page.Surface;
  281. BitmapImage2 := TBitmapImage.Create(Page);
  282. BitmapImage2.BackColor := $400000;
  283. BitmapImage2.Bitmap := BitmapImage.Bitmap;
  284. BitmapImage2.Center := True;
  285. BitmapImage2.Left := BitmapImage.Width + 10;
  286. BitmapImage2.Height := 2*BitmapImage.Height;
  287. BitmapImage2.Width := 2*BitmapImage.Width;
  288. BitmapImage2.Cursor := crHand;
  289. BitmapImage2.OnClick := @BitmapImageOnClick;
  290. BitmapImage2.Parent := Page.Surface;
  291. BitmapImage3 := TBitmapImage.Create(Page);
  292. BitmapImage3.Bitmap := BitmapImage.Bitmap;
  293. BitmapImage3.Stretch := True;
  294. BitmapImage3.Left := 3*BitmapImage.Width + 20;
  295. BitmapImage3.Height := 4*BitmapImage.Height;
  296. BitmapImage3.Width := 4*BitmapImage.Width;
  297. BitmapImage3.Anchors := [akLeft, akTop, akRight, akBottom];
  298. BitmapImage3.Cursor := crHand;
  299. BitmapImage3.OnClick := @BitmapImageOnClick;
  300. BitmapImage3.Parent := Page.Surface;
  301. { TRichViewer }
  302. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TRichViewer');
  303. RichEditViewer := TRichEditViewer.Create(Page);
  304. RichEditViewer.Width := Page.SurfaceWidth;
  305. RichEditViewer.Height := Page.SurfaceHeight;
  306. RichEditViewer.Anchors := [akLeft, akTop, akRight, akBottom];
  307. RichEditViewer.BevelKind := bkFlat;
  308. RichEditViewer.BorderStyle := bsNone;
  309. RichEditViewer.Parent := Page.Surface;
  310. RichEditViewer.ScrollBars := ssVertical;
  311. RichEditViewer.UseRichEdit := True;
  312. RichEditViewer.RTFText := '{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue128;}\viewkind4\uc1\pard\f0\fs20 T\cf1 Rich\cf2 Edit\cf3 Viewer\cf0\par}';
  313. RichEditViewer.ReadOnly := True;
  314. end;
  315. procedure AboutButtonOnClick(Sender: TObject);
  316. begin
  317. MsgBox('This demo shows some features of the various form objects and control classes.', mbInformation, mb_Ok);
  318. end;
  319. procedure URLLabelOnClick(Sender: TObject);
  320. var
  321. ErrorCode: Integer;
  322. begin
  323. ShellExecAsOriginalUser('open', 'http://www.innosetup.com/', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  324. end;
  325. procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
  326. var
  327. AboutButton: TNewButton;
  328. URLLabel: TNewStaticText;
  329. begin
  330. AboutButton := TNewButton.Create(ParentForm);
  331. AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  332. AboutButton.Top := CancelButton.Top;
  333. AboutButton.Width := CancelButton.Width;
  334. AboutButton.Height := CancelButton.Height;
  335. AboutButton.Anchors := [akLeft, akBottom];
  336. AboutButton.Caption := '&About...';
  337. AboutButton.OnClick := @AboutButtonOnClick;
  338. AboutButton.Parent := ParentForm;
  339. URLLabel := TNewStaticText.Create(ParentForm);
  340. URLLabel.Caption := 'www.innosetup.com';
  341. URLLabel.Cursor := crHand;
  342. URLLabel.OnClick := @URLLabelOnClick;
  343. URLLabel.Parent := ParentForm;
  344. { Alter Font *after* setting Parent so the correct defaults are inherited first }
  345. URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
  346. URLLabel.Font.Color := clHotLight
  347. URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
  348. URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
  349. URLLabel.Anchors := [akLeft, akBottom];
  350. end;
  351. procedure InitializeWizard();
  352. begin
  353. { Custom wizard pages }
  354. CreateTheWizardPages;
  355. { Custom controls }
  356. CreateAboutButtonAndURLLabel(WizardForm, WizardForm.CancelButton);
  357. { Custom beveled label }
  358. WizardForm.BeveledLabel.Caption := ' Bevel ';
  359. end;
  360. procedure InitializeUninstallProgressForm();
  361. begin
  362. { Custom controls }
  363. CreateAboutButtonAndURLLabel(UninstallProgressForm, UninstallProgressForm.CancelButton);
  364. end;