CodeClasses.iss 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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 LinkLabelOnLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType);
  94. var
  95. ErrorCode: Integer;
  96. begin
  97. if (LinkType = sltID) and (Link = 'jrsoftware') then
  98. ShellExecAsOriginalUser('open', 'https://jrsoftware.org', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode)
  99. else if LinkType = sltURL then
  100. ShellExecAsOriginalUser('open', Link, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  101. end;
  102. procedure CreateTheWizardPages;
  103. var
  104. Page: TWizardPage;
  105. Button, FormButton, TaskDialogButton: TNewButton;
  106. Panel: TPanel;
  107. CheckBox: TNewCheckBox;
  108. Edit: TNewEdit;
  109. PasswordEdit: TPasswordEdit;
  110. Memo: TNewMemo;
  111. ComboBox: TNewComboBox;
  112. ListBox: TNewListBox;
  113. StaticText, StaticText2, ProgressBarLabel: TNewStaticText;
  114. LinkLabel: TNewLinkLabel;
  115. ProgressBar, ProgressBar2, ProgressBar3: TNewProgressBar;
  116. CheckListBox, CheckListBox2: TNewCheckListBox;
  117. FolderTreeView: TFolderTreeView;
  118. BitmapImage, BitmapImage2, BitmapImage3: TBitmapImage;
  119. BitmapFileName: String;
  120. RichEditViewer: TRichEditViewer;
  121. begin
  122. { TButton and others }
  123. Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'TButton and others');
  124. Button := TNewButton.Create(Page);
  125. Button.Caption := 'TNewButton';
  126. Button.Width := WizardForm.CalculateButtonWidth([Button.Caption]);
  127. Button.Height := ScaleY(23);
  128. Button.OnClick := @ButtonOnClick;
  129. Button.Parent := Page.Surface;
  130. Panel := TPanel.Create(Page);
  131. Panel.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  132. Panel.Left := Page.SurfaceWidth - Panel.Width;
  133. Panel.Height := Button.Height * 2;
  134. Panel.Anchors := [akLeft, akTop, akRight];
  135. Panel.Caption := 'TPanel';
  136. Panel.Color := clWindow;
  137. Panel.BevelKind := bkFlat;
  138. Panel.BevelOuter := bvNone;
  139. Panel.ParentBackground := False;
  140. Panel.Parent := Page.Surface;
  141. CheckBox := TNewCheckBox.Create(Page);
  142. CheckBox.Top := Button.Top + Button.Height + ScaleY(8);
  143. CheckBox.Width := Page.SurfaceWidth div 2;
  144. CheckBox.Height := ScaleY(17);
  145. CheckBox.Caption := 'TNewCheckBox';
  146. CheckBox.Checked := True;
  147. CheckBox.Parent := Page.Surface;
  148. Edit := TNewEdit.Create(Page);
  149. Edit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  150. Edit.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  151. Edit.Text := 'TNewEdit';
  152. Edit.Parent := Page.Surface;
  153. PasswordEdit := TPasswordEdit.Create(Page);
  154. PasswordEdit.Left := Page.SurfaceWidth - Edit.Width;
  155. PasswordEdit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  156. PasswordEdit.Width := Edit.Width;
  157. PasswordEdit.Anchors := [akLeft, akTop, akRight];
  158. PasswordEdit.Text := 'TPasswordEdit';
  159. PasswordEdit.Parent := Page.Surface;
  160. Memo := TNewMemo.Create(Page);
  161. Memo.Top := Edit.Top + Edit.Height + ScaleY(8);
  162. Memo.Width := Page.SurfaceWidth;
  163. Memo.Height := ScaleY(89);
  164. Memo.Anchors := [akLeft, akTop, akRight, akBottom];
  165. Memo.ScrollBars := ssVertical;
  166. Memo.Text := 'TNewMemo';
  167. Memo.Parent := Page.Surface;
  168. FormButton := TNewButton.Create(Page);
  169. FormButton.Caption := 'TSetupForm';
  170. FormButton.Top := Memo.Top + Memo.Height + ScaleY(8);
  171. FormButton.Width := WizardForm.CalculateButtonWidth([FormButton.Caption]);
  172. FormButton.Height := ScaleY(23);
  173. FormButton.Anchors := [akLeft, akBottom];
  174. FormButton.OnClick := @FormButtonOnClick;
  175. FormButton.Parent := Page.Surface;
  176. TaskDialogButton := TNewButton.Create(Page);
  177. TaskDialogButton.Caption := 'TaskDialogMsgBox';
  178. TaskDialogButton.Top := FormButton.Top;
  179. TaskDialogButton.Left := FormButton.Left + FormButton.Width + ScaleX(8);
  180. TaskDialogButton.Width := WizardForm.CalculateButtonWidth([TaskDialogButton.Caption]);
  181. TaskDialogButton.Height := ScaleY(23);
  182. TaskDialogButton.Anchors := [akLeft, akBottom];
  183. TaskDialogButton.OnClick := @TaskDialogButtonOnClick;
  184. TaskDialogButton.Parent := Page.Surface;
  185. { TComboBox and others }
  186. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TComboBox and others');
  187. ComboBox := TNewComboBox.Create(Page);
  188. ComboBox.Width := Page.SurfaceWidth;
  189. ComboBox.Anchors := [akLeft, akTop, akRight];
  190. ComboBox.Parent := Page.Surface;
  191. ComboBox.Style := csDropDownList;
  192. ComboBox.Items.Add('TComboBox');
  193. ComboBox.ItemIndex := 0;
  194. ListBox := TNewListBox.Create(Page);
  195. ListBox.Top := ComboBox.Top + ComboBox.Height + ScaleY(8);
  196. ListBox.Width := Page.SurfaceWidth;
  197. ListBox.Height := ScaleY(97);
  198. ListBox.Anchors := [akLeft, akTop, akRight, akBottom];
  199. ListBox.Parent := Page.Surface;
  200. ListBox.Items.Add('TListBox');
  201. ListBox.ItemIndex := 0;
  202. StaticText := TNewStaticText.Create(Page);
  203. StaticText.Top := ListBox.Top + ListBox.Height + ScaleY(8);
  204. StaticText.Anchors := [akLeft, akRight, akBottom];
  205. StaticText.Caption := 'TNewStaticText';
  206. StaticText.Parent := Page.Surface;
  207. StaticText2 := TNewStaticText.Create(Page);
  208. StaticText2.AutoSize := False;
  209. StaticText2.Left := StaticText.Width + ScaleX(32);
  210. StaticText2.Top := StaticText.Top;
  211. StaticText2.Anchors := [akLeft, akRight, akBottom];
  212. StaticText2.WordWrap := True;
  213. StaticText2.Caption := 'TNewStaticText with more text and an adjusted label height so it''s multi-line.';
  214. StaticText2.Width := 2 * StaticText.Width;
  215. StaticText2.Parent := Page.Surface;
  216. StaticText2.AdjustHeight;
  217. LinkLabel := TNewLinkLabel.Create(Page);
  218. LinkLabel.AutoSize := False;
  219. LinkLabel.Left := StaticText2.Left;
  220. LinkLabel.Top := StaticText2.Top + StaticText2.Height + ScaleY(8);
  221. LinkLabel.Anchors := [akLeft, akRight, akBottom];
  222. LinkLabel.Caption := 'TNew<a id="jrsoftware">Link</a>Label with more text and an adjusted label height so it''s multi-line with a second <a id="jrsoftware">link</a> on the second line.';
  223. LinkLabel.Width := StaticText2.Width;
  224. LinkLabel.OnLinkClick := @LinkLabelOnLinkClick;
  225. LinkLabel.Parent := Page.Surface;
  226. LinkLabel.AdjustHeight;
  227. { TNewProgressBar }
  228. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TNewProgressBar');
  229. ProgressBarLabel := TNewStaticText.Create(Page);
  230. ProgressBarLabel.Anchors := [akLeft, akTop];
  231. ProgressBarLabel.Caption := 'TNewProgressBar';
  232. ProgressBarLabel.Parent := Page.Surface;
  233. ProgressBar := TNewProgressBar.Create(Page);
  234. ProgressBar.Left := ProgressBarLabel.Width + ScaleX(8);
  235. ProgressBar.Top := ProgressBarLabel.Top;
  236. ProgressBar.Width := Page.SurfaceWidth - ProgressBar.Left;
  237. ProgressBar.Height := ProgressBarLabel.Height + ScaleY(8);
  238. ProgressBar.Anchors := [akLeft, akRight, akTop];
  239. ProgressBar.Parent := Page.Surface;
  240. ProgressBar.Position := 25;
  241. ProgressBar2 := TNewProgressBar.Create(Page);
  242. ProgressBar2.Left := ProgressBarLabel.Width + ScaleX(8);
  243. ProgressBar2.Top := ProgressBar.Top + ProgressBar.Height + ScaleY(4);
  244. ProgressBar2.Width := Page.SurfaceWidth - ProgressBar.Left;
  245. ProgressBar2.Height := ProgressBarLabel.Height + ScaleY(8);
  246. ProgressBar2.Anchors := [akLeft, akRight, akTop];
  247. ProgressBar2.Parent := Page.Surface;
  248. ProgressBar2.Position := 50;
  249. ProgressBar2.State := npbsError;
  250. ProgressBar3 := TNewProgressBar.Create(Page);
  251. ProgressBar3.Left := ProgressBarLabel.Width + ScaleX(8);
  252. ProgressBar3.Top := ProgressBar2.Top + ProgressBar2.Height + ScaleY(4);
  253. ProgressBar3.Width := Page.SurfaceWidth - ProgressBar.Left;
  254. ProgressBar3.Height := ProgressBarLabel.Height + ScaleY(8);
  255. ProgressBar3.Anchors := [akLeft, akRight, akTop];
  256. ProgressBar3.Parent := Page.Surface;
  257. ProgressBar3.Style := npbstMarquee;
  258. { TNewCheckListBox }
  259. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TNewCheckListBox');
  260. CheckListBox := TNewCheckListBox.Create(Page);
  261. CheckListBox.Width := Page.SurfaceWidth;
  262. CheckListBox.Height := ScaleY(97);
  263. CheckListBox.Anchors := [akLeft, akTop, akRight, akBottom];
  264. CheckListBox.Flat := True;
  265. CheckListBox.Parent := Page.Surface;
  266. CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  267. CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, True, True, nil);
  268. CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, False, True, nil);
  269. CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  270. CheckListBox.AddCheckBox('TNewCheckListBox', '', 1, True, True, False, True, nil);
  271. CheckListBox.AddCheckBox('TNewCheckListBox', '123', 2, True, True, False, True, nil);
  272. CheckListBox.AddCheckBox('TNewCheckListBox', '456', 2, False, True, False, True, nil);
  273. CheckListBox.AddCheckBox('TNewCheckListBox', '', 1, False, True, False, True, nil);
  274. CheckListBox.ItemFontStyle[5] := [fsBold];
  275. CheckListBox.SubItemFontStyle[5] := [fsBold];
  276. CheckListBox.ItemFontStyle[6] := [fsBold, fsItalic];
  277. CheckListBox.SubItemFontStyle[6] := [fsBold, fsUnderline];
  278. CheckListBox2 := TNewCheckListBox.Create(Page);
  279. CheckListBox2.Top := CheckListBox.Top + CheckListBox.Height + ScaleY(8);
  280. CheckListBox2.Width := Page.SurfaceWidth;
  281. CheckListBox2.Height := ScaleY(97);
  282. CheckListBox2.Anchors := [akLeft, akRight, akBottom];
  283. CheckListBox2.BorderStyle := bsNone;
  284. CheckListBox2.ParentColor := True;
  285. CheckListBox2.MinItemHeight := WizardForm.TasksList.MinItemHeight;
  286. CheckListBox2.ShowLines := False;
  287. CheckListBox2.WantTabs := True;
  288. CheckListBox2.Parent := Page.Surface;
  289. CheckListBox2.AddGroup('TNewCheckListBox', '', 0, nil);
  290. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, True, True, nil);
  291. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, False, True, nil);
  292. { TFolderTreeView }
  293. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TFolderTreeView');
  294. FolderTreeView := TFolderTreeView.Create(Page);
  295. FolderTreeView.Width := Page.SurfaceWidth;
  296. FolderTreeView.Height := Page.SurfaceHeight;
  297. FolderTreeView.Anchors := [akLeft, akTop, akRight, akBottom];
  298. FolderTreeView.Parent := Page.Surface;
  299. FolderTreeView.Directory := ExpandConstant('{src}');
  300. { TBitmapImage }
  301. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TBitmapImage');
  302. BitmapFileName := ExpandConstant('{tmp}\WizClassicSmallImage.bmp');
  303. ExtractTemporaryFile(ExtractFileName(BitmapFileName));
  304. BitmapImage := TBitmapImage.Create(Page);
  305. BitmapImage.AutoSize := True;
  306. BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
  307. BitmapImage.Cursor := crHand;
  308. BitmapImage.OnClick := @BitmapImageOnClick;
  309. BitmapImage.Parent := Page.Surface;
  310. BitmapImage2 := TBitmapImage.Create(Page);
  311. BitmapImage2.BackColor := $400000;
  312. BitmapImage2.Bitmap := BitmapImage.Bitmap;
  313. BitmapImage2.Center := True;
  314. BitmapImage2.Left := BitmapImage.Width + 10;
  315. BitmapImage2.Height := 2*BitmapImage.Height;
  316. BitmapImage2.Width := 2*BitmapImage.Width;
  317. BitmapImage2.Cursor := crHand;
  318. BitmapImage2.OnClick := @BitmapImageOnClick;
  319. BitmapImage2.Parent := Page.Surface;
  320. BitmapImage3 := TBitmapImage.Create(Page);
  321. BitmapImage3.Bitmap := BitmapImage.Bitmap;
  322. BitmapImage3.Stretch := True;
  323. BitmapImage3.Left := 3*BitmapImage.Width + 20;
  324. BitmapImage3.Height := 4*BitmapImage.Height;
  325. BitmapImage3.Width := 4*BitmapImage.Width;
  326. BitmapImage3.Anchors := [akLeft, akTop, akRight, akBottom];
  327. BitmapImage3.Cursor := crHand;
  328. BitmapImage3.OnClick := @BitmapImageOnClick;
  329. BitmapImage3.Parent := Page.Surface;
  330. { TRichViewer }
  331. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TRichViewer');
  332. RichEditViewer := TRichEditViewer.Create(Page);
  333. RichEditViewer.Width := Page.SurfaceWidth;
  334. RichEditViewer.Height := Page.SurfaceHeight;
  335. RichEditViewer.Anchors := [akLeft, akTop, akRight, akBottom];
  336. RichEditViewer.BevelKind := bkFlat;
  337. RichEditViewer.BorderStyle := bsNone;
  338. RichEditViewer.Parent := Page.Surface;
  339. RichEditViewer.ScrollBars := ssVertical;
  340. RichEditViewer.UseRichEdit := True;
  341. 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}';
  342. RichEditViewer.ReadOnly := True;
  343. end;
  344. procedure AboutButtonOnClick(Sender: TObject);
  345. begin
  346. MsgBox('This demo shows some features of the various form objects and control classes.', mbInformation, mb_Ok);
  347. end;
  348. procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
  349. var
  350. AboutButton: TNewButton;
  351. URLLabel: TNewLinkLabel;
  352. begin
  353. AboutButton := TNewButton.Create(ParentForm);
  354. AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  355. AboutButton.Top := CancelButton.Top;
  356. AboutButton.Width := CancelButton.Width;
  357. AboutButton.Height := CancelButton.Height;
  358. AboutButton.Anchors := [akLeft, akBottom];
  359. AboutButton.Caption := '&About...';
  360. AboutButton.OnClick := @AboutButtonOnClick;
  361. AboutButton.Parent := ParentForm;
  362. URLLabel := TNewLinkLabel.Create(ParentForm);
  363. URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
  364. URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
  365. URLLabel.Anchors := [akLeft, akBottom];
  366. URLLabel.Caption := '<a href="https://jrsoftware.org">jrsoftware.org</a>';
  367. URLLabel.OnLinkClick := @LinkLabelOnLinkClick;
  368. URLLabel.UseVisualStyle := True;
  369. URLLabel.Parent := ParentForm;
  370. end;
  371. procedure InitializeWizard();
  372. begin
  373. { Custom wizard pages }
  374. CreateTheWizardPages;
  375. { Custom controls }
  376. CreateAboutButtonAndURLLabel(WizardForm, WizardForm.CancelButton);
  377. { Custom beveled label }
  378. WizardForm.BeveledLabel.Caption := ' Bevel ';
  379. end;
  380. procedure InitializeUninstallProgressForm();
  381. begin
  382. { Custom controls }
  383. CreateAboutButtonAndURLLabel(UninstallProgressForm, UninstallProgressForm.CancelButton);
  384. end;