CodeClasses.iss 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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:WizModernSmallImage.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. begin
  35. Form := CreateCustomForm();
  36. try
  37. Form.ClientWidth := ScaleX(256);
  38. Form.ClientHeight := ScaleY(128);
  39. Form.Caption := 'TSetupForm';
  40. Edit := TNewEdit.Create(Form);
  41. Edit.Top := ScaleY(10);
  42. Edit.Left := ScaleX(10);
  43. Edit.Width := Form.ClientWidth - ScaleX(2 * 10);
  44. Edit.Height := ScaleY(23);
  45. Edit.Anchors := [akLeft, akTop, akRight];
  46. Edit.Text := 'TNewEdit';
  47. Edit.Parent := Form;
  48. OKButton := TNewButton.Create(Form);
  49. OKButton.Parent := Form;
  50. OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
  51. OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  52. OKButton.Width := ScaleX(75);
  53. OKButton.Height := ScaleY(23);
  54. OKButton.Anchors := [akRight, akBottom]
  55. OKButton.Caption := 'OK';
  56. OKButton.ModalResult := mrOk;
  57. OKButton.Default := True;
  58. CancelButton := TNewButton.Create(Form);
  59. CancelButton.Parent := Form;
  60. CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
  61. CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  62. CancelButton.Width := ScaleX(75);
  63. CancelButton.Height := ScaleY(23);
  64. CancelButton.Anchors := [akRight, akBottom]
  65. CancelButton.Caption := 'Cancel';
  66. CancelButton.ModalResult := mrCancel;
  67. CancelButton.Cancel := True;
  68. Form.ActiveControl := Edit;
  69. { Keep the form from sizing vertically since we don't have any controls which can size vertically }
  70. Form.KeepSizeY := True;
  71. { Center on WizardForm. Without this call it will still automatically center, but on the screen }
  72. Form.FlipSizeAndCenterIfNeeded(True, WizardForm, False);
  73. if Form.ShowModal() = mrOk then
  74. MsgBox('You clicked OK.', mbInformation, MB_OK);
  75. finally
  76. Form.Free();
  77. end;
  78. end;
  79. procedure TaskDialogButtonOnClick(Sender: TObject);
  80. begin
  81. { TaskDialogMsgBox isn't a class but showing it anyway since it fits with the theme }
  82. case TaskDialogMsgBox('Choose A or B',
  83. 'You can choose A or B.',
  84. mbInformation,
  85. MB_YESNOCANCEL, ['I choose &A'#13#10'A will be chosen.', 'I choose &B'#13#10'B will be chosen.'],
  86. IDYES) of
  87. IDYES: MsgBox('You chose A.', mbInformation, MB_OK);
  88. IDNO: MsgBox('You chose B.', mbInformation, MB_OK);
  89. end;
  90. end;
  91. procedure CreateTheWizardPages;
  92. var
  93. Page: TWizardPage;
  94. Button, FormButton, TaskDialogButton: TNewButton;
  95. Panel: TPanel;
  96. CheckBox: TNewCheckBox;
  97. Edit: TNewEdit;
  98. PasswordEdit: TPasswordEdit;
  99. Memo: TNewMemo;
  100. ComboBox: TNewComboBox;
  101. ListBox: TNewListBox;
  102. StaticText, ProgressBarLabel: TNewStaticText;
  103. ProgressBar, ProgressBar2, ProgressBar3: TNewProgressBar;
  104. CheckListBox, CheckListBox2: TNewCheckListBox;
  105. FolderTreeView: TFolderTreeView;
  106. BitmapImage, BitmapImage2, BitmapImage3: TBitmapImage;
  107. BitmapFileName: String;
  108. RichEditViewer: TRichEditViewer;
  109. begin
  110. { TButton and others }
  111. Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'TButton and others');
  112. Button := TNewButton.Create(Page);
  113. Button.Width := ScaleX(75);
  114. Button.Height := ScaleY(23);
  115. Button.Caption := 'TNewButton';
  116. Button.OnClick := @ButtonOnClick;
  117. Button.Parent := Page.Surface;
  118. Panel := TPanel.Create(Page);
  119. Panel.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  120. Panel.Left := Page.SurfaceWidth - Panel.Width;
  121. Panel.Height := Button.Height * 2;
  122. Panel.Anchors := [akLeft, akTop, akRight];
  123. Panel.Caption := 'TPanel';
  124. Panel.Color := clWindow;
  125. Panel.BevelKind := bkFlat;
  126. Panel.BevelOuter := bvNone;
  127. Panel.ParentBackground := False;
  128. Panel.Parent := Page.Surface;
  129. CheckBox := TNewCheckBox.Create(Page);
  130. CheckBox.Top := Button.Top + Button.Height + ScaleY(8);
  131. CheckBox.Width := Page.SurfaceWidth div 2;
  132. CheckBox.Height := ScaleY(17);
  133. CheckBox.Caption := 'TNewCheckBox';
  134. CheckBox.Checked := True;
  135. CheckBox.Parent := Page.Surface;
  136. Edit := TNewEdit.Create(Page);
  137. Edit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  138. Edit.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  139. Edit.Text := 'TNewEdit';
  140. Edit.Parent := Page.Surface;
  141. PasswordEdit := TPasswordEdit.Create(Page);
  142. PasswordEdit.Left := Page.SurfaceWidth - Edit.Width;
  143. PasswordEdit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  144. PasswordEdit.Width := Edit.Width;
  145. PasswordEdit.Anchors := [akLeft, akTop, akRight];
  146. PasswordEdit.Text := 'TPasswordEdit';
  147. PasswordEdit.Parent := Page.Surface;
  148. Memo := TNewMemo.Create(Page);
  149. Memo.Top := Edit.Top + Edit.Height + ScaleY(8);
  150. Memo.Width := Page.SurfaceWidth;
  151. Memo.Height := ScaleY(89);
  152. Memo.Anchors := [akLeft, akTop, akRight, akBottom];
  153. Memo.ScrollBars := ssVertical;
  154. Memo.Text := 'TNewMemo';
  155. Memo.Parent := Page.Surface;
  156. FormButton := TNewButton.Create(Page);
  157. FormButton.Top := Memo.Top + Memo.Height + ScaleY(8);
  158. FormButton.Width := ScaleX(75);
  159. FormButton.Height := ScaleY(23);
  160. FormButton.Anchors := [akLeft, akBottom];
  161. FormButton.Caption := 'TSetupForm';
  162. FormButton.OnClick := @FormButtonOnClick;
  163. FormButton.Parent := Page.Surface;
  164. TaskDialogButton := TNewButton.Create(Page);
  165. TaskDialogButton.Top := FormButton.Top;
  166. TaskDialogButton.Left := FormButton.Left + FormButton.Width + ScaleX(8);
  167. TaskDialogButton.Width := ScaleX(110);
  168. TaskDialogButton.Height := ScaleY(23);
  169. TaskDialogButton.Anchors := [akLeft, akBottom];
  170. TaskDialogButton.Caption := 'TaskDialogMsgBox';
  171. TaskDialogButton.OnClick := @TaskDialogButtonOnClick;
  172. TaskDialogButton.Parent := Page.Surface;
  173. { TComboBox and others }
  174. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TComboBox and others');
  175. ComboBox := TNewComboBox.Create(Page);
  176. ComboBox.Width := Page.SurfaceWidth;
  177. ComboBox.Anchors := [akLeft, akTop, akRight];
  178. ComboBox.Parent := Page.Surface;
  179. ComboBox.Style := csDropDownList;
  180. ComboBox.Items.Add('TComboBox');
  181. ComboBox.ItemIndex := 0;
  182. ListBox := TNewListBox.Create(Page);
  183. ListBox.Top := ComboBox.Top + ComboBox.Height + ScaleY(8);
  184. ListBox.Width := Page.SurfaceWidth;
  185. ListBox.Height := ScaleY(97);
  186. ListBox.Anchors := [akLeft, akTop, akRight, akBottom];
  187. ListBox.Parent := Page.Surface;
  188. ListBox.Items.Add('TListBox');
  189. ListBox.ItemIndex := 0;
  190. StaticText := TNewStaticText.Create(Page);
  191. StaticText.Top := ListBox.Top + ListBox.Height + ScaleY(8);
  192. StaticText.Anchors := [akLeft, akRight, akBottom];
  193. StaticText.Caption := 'TNewStaticText';
  194. StaticText.AutoSize := True;
  195. StaticText.Parent := Page.Surface;
  196. ProgressBarLabel := TNewStaticText.Create(Page);
  197. ProgressBarLabel.Top := StaticText.Top + StaticText.Height + ScaleY(8);
  198. ProgressBarLabel.Anchors := [akLeft, akBottom];
  199. ProgressBarLabel.Caption := 'TNewProgressBar';
  200. ProgressBarLabel.AutoSize := True;
  201. ProgressBarLabel.Parent := Page.Surface;
  202. ProgressBar := TNewProgressBar.Create(Page);
  203. ProgressBar.Left := ProgressBarLabel.Width + ScaleX(8);
  204. ProgressBar.Top := ProgressBarLabel.Top;
  205. ProgressBar.Width := Page.SurfaceWidth - ProgressBar.Left;
  206. ProgressBar.Height := ProgressBarLabel.Height + ScaleY(8);
  207. ProgressBar.Anchors := [akLeft, akRight, akBottom];
  208. ProgressBar.Parent := Page.Surface;
  209. ProgressBar.Position := 25;
  210. ProgressBar2 := TNewProgressBar.Create(Page);
  211. ProgressBar2.Left := ProgressBarLabel.Width + ScaleX(8);
  212. ProgressBar2.Top := ProgressBar.Top + ProgressBar.Height + ScaleY(4);
  213. ProgressBar2.Width := Page.SurfaceWidth - ProgressBar.Left;
  214. ProgressBar2.Height := ProgressBarLabel.Height + ScaleY(8);
  215. ProgressBar2.Anchors := [akLeft, akRight, akBottom];
  216. ProgressBar2.Parent := Page.Surface;
  217. ProgressBar2.Position := 50;
  218. { Note: TNewProgressBar.State property only has an effect on Windows Vista and newer }
  219. ProgressBar2.State := npbsError;
  220. ProgressBar3 := TNewProgressBar.Create(Page);
  221. ProgressBar3.Left := ProgressBarLabel.Width + ScaleX(8);
  222. ProgressBar3.Top := ProgressBar2.Top + ProgressBar2.Height + ScaleY(4);
  223. ProgressBar3.Width := Page.SurfaceWidth - ProgressBar.Left;
  224. ProgressBar3.Height := ProgressBarLabel.Height + ScaleY(8);
  225. ProgressBar3.Anchors := [akLeft, akRight, akBottom];
  226. ProgressBar3.Parent := Page.Surface;
  227. { Note: TNewProgressBar.Style property only has an effect on Windows XP and newer }
  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', '', 2, True, True, False, True, nil);
  243. CheckListBox.AddCheckBox('TNewCheckListBox', '', 2, False, True, False, True, nil);
  244. CheckListBox.AddCheckBox('TNewCheckListBox', '', 1, False, True, False, True, nil);
  245. CheckListBox2 := TNewCheckListBox.Create(Page);
  246. CheckListBox2.Top := CheckListBox.Top + CheckListBox.Height + ScaleY(8);
  247. CheckListBox2.Width := Page.SurfaceWidth;
  248. CheckListBox2.Height := ScaleY(97);
  249. CheckListBox2.Anchors := [akLeft, akRight, akBottom];
  250. CheckListBox2.BorderStyle := bsNone;
  251. CheckListBox2.ParentColor := True;
  252. CheckListBox2.MinItemHeight := WizardForm.TasksList.MinItemHeight;
  253. CheckListBox2.ShowLines := False;
  254. CheckListBox2.WantTabs := True;
  255. CheckListBox2.Parent := Page.Surface;
  256. CheckListBox2.AddGroup('TNewCheckListBox', '', 0, nil);
  257. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, True, True, nil);
  258. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, False, True, nil);
  259. { TFolderTreeView }
  260. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TFolderTreeView');
  261. FolderTreeView := TFolderTreeView.Create(Page);
  262. FolderTreeView.Width := Page.SurfaceWidth;
  263. FolderTreeView.Height := Page.SurfaceHeight;
  264. FolderTreeView.Anchors := [akLeft, akTop, akRight, akBottom];
  265. FolderTreeView.Parent := Page.Surface;
  266. FolderTreeView.Directory := ExpandConstant('{src}');
  267. { TBitmapImage }
  268. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TBitmapImage');
  269. BitmapFileName := ExpandConstant('{tmp}\WizModernSmallImage.bmp');
  270. ExtractTemporaryFile(ExtractFileName(BitmapFileName));
  271. BitmapImage := TBitmapImage.Create(Page);
  272. BitmapImage.AutoSize := True;
  273. BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
  274. BitmapImage.Cursor := crHand;
  275. BitmapImage.OnClick := @BitmapImageOnClick;
  276. BitmapImage.Parent := Page.Surface;
  277. BitmapImage2 := TBitmapImage.Create(Page);
  278. BitmapImage2.BackColor := $400000;
  279. BitmapImage2.Bitmap := BitmapImage.Bitmap;
  280. BitmapImage2.Center := True;
  281. BitmapImage2.Left := BitmapImage.Width + 10;
  282. BitmapImage2.Height := 2*BitmapImage.Height;
  283. BitmapImage2.Width := 2*BitmapImage.Width;
  284. BitmapImage2.Cursor := crHand;
  285. BitmapImage2.OnClick := @BitmapImageOnClick;
  286. BitmapImage2.Parent := Page.Surface;
  287. BitmapImage3 := TBitmapImage.Create(Page);
  288. BitmapImage3.Bitmap := BitmapImage.Bitmap;
  289. BitmapImage3.Stretch := True;
  290. BitmapImage3.Left := 3*BitmapImage.Width + 20;
  291. BitmapImage3.Height := 4*BitmapImage.Height;
  292. BitmapImage3.Width := 4*BitmapImage.Width;
  293. BitmapImage3.Anchors := [akLeft, akTop, akRight, akBottom];
  294. BitmapImage3.Cursor := crHand;
  295. BitmapImage3.OnClick := @BitmapImageOnClick;
  296. BitmapImage3.Parent := Page.Surface;
  297. { TRichViewer }
  298. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TRichViewer');
  299. RichEditViewer := TRichEditViewer.Create(Page);
  300. RichEditViewer.Width := Page.SurfaceWidth;
  301. RichEditViewer.Height := Page.SurfaceHeight;
  302. RichEditViewer.Anchors := [akLeft, akTop, akRight, akBottom];
  303. RichEditViewer.BevelKind := bkFlat;
  304. RichEditViewer.BorderStyle := bsNone;
  305. RichEditViewer.Parent := Page.Surface;
  306. RichEditViewer.ScrollBars := ssVertical;
  307. RichEditViewer.UseRichEdit := True;
  308. 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}';
  309. RichEditViewer.ReadOnly := True;
  310. end;
  311. procedure AboutButtonOnClick(Sender: TObject);
  312. begin
  313. MsgBox('This demo shows some features of the various form objects and control classes.', mbInformation, mb_Ok);
  314. end;
  315. procedure URLLabelOnClick(Sender: TObject);
  316. var
  317. ErrorCode: Integer;
  318. begin
  319. ShellExecAsOriginalUser('open', 'http://www.innosetup.com/', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  320. end;
  321. procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
  322. var
  323. AboutButton: TNewButton;
  324. URLLabel: TNewStaticText;
  325. begin
  326. AboutButton := TNewButton.Create(ParentForm);
  327. AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  328. AboutButton.Top := CancelButton.Top;
  329. AboutButton.Width := CancelButton.Width;
  330. AboutButton.Height := CancelButton.Height;
  331. AboutButton.Anchors := [akLeft, akBottom];
  332. AboutButton.Caption := '&About...';
  333. AboutButton.OnClick := @AboutButtonOnClick;
  334. AboutButton.Parent := ParentForm;
  335. URLLabel := TNewStaticText.Create(ParentForm);
  336. URLLabel.Caption := 'www.innosetup.com';
  337. URLLabel.Cursor := crHand;
  338. URLLabel.OnClick := @URLLabelOnClick;
  339. URLLabel.Parent := ParentForm;
  340. { Alter Font *after* setting Parent so the correct defaults are inherited first }
  341. URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
  342. URLLabel.Font.Color := clHotLight
  343. URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
  344. URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
  345. URLLabel.Anchors := [akLeft, akBottom];
  346. end;
  347. procedure InitializeWizard();
  348. begin
  349. { Custom wizard pages }
  350. CreateTheWizardPages;
  351. { Custom controls }
  352. CreateAboutButtonAndURLLabel(WizardForm, WizardForm.CancelButton);
  353. { Custom beveled label }
  354. WizardForm.BeveledLabel.Caption := ' Bevel ';
  355. end;
  356. procedure InitializeUninstallProgressForm();
  357. begin
  358. { Custom controls }
  359. CreateAboutButtonAndURLLabel(UninstallProgressForm, UninstallProgressForm.CancelButton);
  360. end;