CodeClasses.iss 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. CreateAppDir=no
  8. DisableProgramGroupPage=yes
  9. DefaultGroupName=My Program
  10. UninstallDisplayIcon={app}\MyProg.exe
  11. WindowVisible=yes
  12. OutputDir=userdocs:Inno Setup Examples Output
  13. [Files]
  14. Source: compiler:WizModernSmallImage.bmp; Flags: dontcopy
  15. [Code]
  16. procedure ButtonOnClick(Sender: TObject);
  17. begin
  18. MsgBox('You clicked the button!', mbInformation, mb_Ok);
  19. end;
  20. procedure BitmapImageOnClick(Sender: TObject);
  21. begin
  22. MsgBox('You clicked the image!', mbInformation, mb_Ok);
  23. end;
  24. procedure FormButtonOnClick(Sender: TObject);
  25. var
  26. Form: TSetupForm;
  27. Edit: TNewEdit;
  28. OKButton, CancelButton: TNewButton;
  29. begin
  30. Form := CreateCustomForm();
  31. try
  32. Form.ClientWidth := ScaleX(256);
  33. Form.ClientHeight := ScaleY(128);
  34. Form.Caption := 'TSetupForm';
  35. Form.CenterInsideControl(WizardForm, False);
  36. Edit := TNewEdit.Create(Form);
  37. Edit.Top := ScaleY(10);
  38. Edit.Left := ScaleX(10);
  39. Edit.Width := Form.ClientWidth - ScaleX(2 * 10);
  40. Edit.Height := ScaleY(23);
  41. Edit.Text := 'TNewEdit';
  42. Edit.Parent := Form;
  43. OKButton := TNewButton.Create(Form);
  44. OKButton.Parent := Form;
  45. OKButton.Width := ScaleX(75);
  46. OKButton.Height := ScaleY(23);
  47. OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
  48. OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  49. OKButton.Caption := 'OK';
  50. OKButton.ModalResult := mrOk;
  51. OKButton.Default := True;
  52. CancelButton := TNewButton.Create(Form);
  53. CancelButton.Parent := Form;
  54. CancelButton.Width := ScaleX(75);
  55. CancelButton.Height := ScaleY(23);
  56. CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
  57. CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  58. CancelButton.Caption := 'Cancel';
  59. CancelButton.ModalResult := mrCancel;
  60. CancelButton.Cancel := True;
  61. Form.ActiveControl := Edit;
  62. if Form.ShowModal() = mrOk then
  63. MsgBox('You clicked OK.', mbInformation, MB_OK);
  64. finally
  65. Form.Free();
  66. end;
  67. end;
  68. procedure CreateTheWizardPages;
  69. var
  70. Page: TWizardPage;
  71. Button, FormButton: TNewButton;
  72. Panel: TPanel;
  73. CheckBox: TNewCheckBox;
  74. Edit: TNewEdit;
  75. PasswordEdit: TPasswordEdit;
  76. Memo: TNewMemo;
  77. ComboBox: TNewComboBox;
  78. ListBox: TNewListBox;
  79. StaticText, ProgressBarLabel: TNewStaticText;
  80. ProgressBar, ProgressBar2, ProgressBar3: TNewProgressBar;
  81. CheckListBox, CheckListBox2: TNewCheckListBox;
  82. FolderTreeView: TFolderTreeView;
  83. BitmapImage, BitmapImage2, BitmapImage3: TBitmapImage;
  84. BitmapFileName: String;
  85. RichEditViewer: TRichEditViewer;
  86. begin
  87. { TButton and others }
  88. Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'TButton and others');
  89. Button := TNewButton.Create(Page);
  90. Button.Width := ScaleX(75);
  91. Button.Height := ScaleY(23);
  92. Button.Caption := 'TNewButton';
  93. Button.OnClick := @ButtonOnClick;
  94. Button.Parent := Page.Surface;
  95. Panel := TPanel.Create(Page);
  96. Panel.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  97. Panel.Left := Page.SurfaceWidth - Panel.Width;
  98. Panel.Height := Button.Height * 2;
  99. Panel.Caption := 'TPanel';
  100. Panel.Color := clWindow;
  101. Panel.ParentBackground := False;
  102. Panel.Parent := Page.Surface;
  103. CheckBox := TNewCheckBox.Create(Page);
  104. CheckBox.Top := Button.Top + Button.Height + ScaleY(8);
  105. CheckBox.Width := Page.SurfaceWidth div 2;
  106. CheckBox.Height := ScaleY(17);
  107. CheckBox.Caption := 'TNewCheckBox';
  108. CheckBox.Checked := True;
  109. CheckBox.Parent := Page.Surface;
  110. Edit := TNewEdit.Create(Page);
  111. Edit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  112. Edit.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  113. Edit.Text := 'TNewEdit';
  114. Edit.Parent := Page.Surface;
  115. PasswordEdit := TPasswordEdit.Create(Page);
  116. PasswordEdit.Left := Page.SurfaceWidth - Edit.Width;
  117. PasswordEdit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  118. PasswordEdit.Width := Edit.Width;
  119. PasswordEdit.Text := 'TPasswordEdit';
  120. PasswordEdit.Parent := Page.Surface;
  121. Memo := TNewMemo.Create(Page);
  122. Memo.Top := Edit.Top + Edit.Height + ScaleY(8);
  123. Memo.Width := Page.SurfaceWidth;
  124. Memo.Height := ScaleY(89);
  125. Memo.ScrollBars := ssVertical;
  126. Memo.Text := 'TNewMemo';
  127. Memo.Parent := Page.Surface;
  128. FormButton := TNewButton.Create(Page);
  129. FormButton.Top := Memo.Top + Memo.Height + ScaleY(8);
  130. FormButton.Width := ScaleX(75);
  131. FormButton.Height := ScaleY(23);
  132. FormButton.Caption := 'TSetupForm';
  133. FormButton.OnClick := @FormButtonOnClick;
  134. FormButton.Parent := Page.Surface;
  135. { TComboBox and others }
  136. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TComboBox and others');
  137. ComboBox := TNewComboBox.Create(Page);
  138. ComboBox.Width := Page.SurfaceWidth;
  139. ComboBox.Parent := Page.Surface;
  140. ComboBox.Style := csDropDownList;
  141. ComboBox.Items.Add('TComboBox');
  142. ComboBox.ItemIndex := 0;
  143. ListBox := TNewListBox.Create(Page);
  144. ListBox.Top := ComboBox.Top + ComboBox.Height + ScaleY(8);
  145. ListBox.Width := Page.SurfaceWidth;
  146. ListBox.Height := ScaleY(97);
  147. ListBox.Parent := Page.Surface;
  148. ListBox.Items.Add('TListBox');
  149. ListBox.ItemIndex := 0;
  150. StaticText := TNewStaticText.Create(Page);
  151. StaticText.Top := ListBox.Top + ListBox.Height + ScaleY(8);
  152. StaticText.Caption := 'TNewStaticText';
  153. StaticText.AutoSize := True;
  154. StaticText.Parent := Page.Surface;
  155. ProgressBarLabel := TNewStaticText.Create(Page);
  156. ProgressBarLabel.Top := StaticText.Top + StaticText.Height + ScaleY(8);
  157. ProgressBarLabel.Caption := 'TNewProgressBar';
  158. ProgressBarLabel.AutoSize := True;
  159. ProgressBarLabel.Parent := Page.Surface;
  160. ProgressBar := TNewProgressBar.Create(Page);
  161. ProgressBar.Left := ProgressBarLabel.Width + ScaleX(8);
  162. ProgressBar.Top := ProgressBarLabel.Top;
  163. ProgressBar.Width := Page.SurfaceWidth - ProgressBar.Left;
  164. ProgressBar.Height := ProgressBarLabel.Height + ScaleY(8);
  165. ProgressBar.Parent := Page.Surface;
  166. ProgressBar.Position := 25;
  167. ProgressBar2 := TNewProgressBar.Create(Page);
  168. ProgressBar2.Left := ProgressBarLabel.Width + ScaleX(8);
  169. ProgressBar2.Top := ProgressBar.Top + ProgressBar.Height + ScaleY(4);
  170. ProgressBar2.Width := Page.SurfaceWidth - ProgressBar.Left;
  171. ProgressBar2.Height := ProgressBarLabel.Height + ScaleY(8);
  172. ProgressBar2.Parent := Page.Surface;
  173. ProgressBar2.Position := 50;
  174. { Note: TNewProgressBar.State property only has an effect on Windows Vista and newer }
  175. ProgressBar2.State := npbsError;
  176. ProgressBar3 := TNewProgressBar.Create(Page);
  177. ProgressBar3.Left := ProgressBarLabel.Width + ScaleX(8);
  178. ProgressBar3.Top := ProgressBar2.Top + ProgressBar2.Height + ScaleY(4);
  179. ProgressBar3.Width := Page.SurfaceWidth - ProgressBar.Left;
  180. ProgressBar3.Height := ProgressBarLabel.Height + ScaleY(8);
  181. ProgressBar3.Parent := Page.Surface;
  182. { Note: TNewProgressBar.Style property only has an effect on Windows XP and newer }
  183. ProgressBar3.Style := npbstMarquee;
  184. { TNewCheckListBox }
  185. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TNewCheckListBox');
  186. CheckListBox := TNewCheckListBox.Create(Page);
  187. CheckListBox.Width := Page.SurfaceWidth;
  188. CheckListBox.Height := ScaleY(97);
  189. CheckListBox.Flat := True;
  190. CheckListBox.Parent := Page.Surface;
  191. CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  192. CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, True, True, nil);
  193. CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, False, True, nil);
  194. CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  195. CheckListBox2 := TNewCheckListBox.Create(Page);
  196. CheckListBox2.Top := CheckListBox.Top + CheckListBox.Height + ScaleY(8);
  197. CheckListBox2.Width := Page.SurfaceWidth;
  198. CheckListBox2.Height := ScaleY(97);
  199. CheckListBox2.BorderStyle := bsNone;
  200. CheckListBox2.ParentColor := True;
  201. CheckListBox2.MinItemHeight := WizardForm.TasksList.MinItemHeight;
  202. CheckListBox2.ShowLines := False;
  203. CheckListBox2.WantTabs := True;
  204. CheckListBox2.Parent := Page.Surface;
  205. CheckListBox2.AddGroup('TNewCheckListBox', '', 0, nil);
  206. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, True, True, nil);
  207. CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, False, True, nil);
  208. { TFolderTreeView }
  209. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TFolderTreeView');
  210. FolderTreeView := TFolderTreeView.Create(Page);
  211. FolderTreeView.Width := Page.SurfaceWidth;
  212. FolderTreeView.Height := Page.SurfaceHeight;
  213. FolderTreeView.Parent := Page.Surface;
  214. FolderTreeView.Directory := ExpandConstant('{src}');
  215. { TBitmapImage }
  216. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TBitmapImage');
  217. BitmapFileName := ExpandConstant('{tmp}\WizModernSmallImage.bmp');
  218. ExtractTemporaryFile(ExtractFileName(BitmapFileName));
  219. BitmapImage := TBitmapImage.Create(Page);
  220. BitmapImage.AutoSize := True;
  221. BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
  222. BitmapImage.Cursor := crHand;
  223. BitmapImage.OnClick := @BitmapImageOnClick;
  224. BitmapImage.Parent := Page.Surface;
  225. BitmapImage2 := TBitmapImage.Create(Page);
  226. BitmapImage2.BackColor := $400000;
  227. BitmapImage2.Bitmap := BitmapImage.Bitmap;
  228. BitmapImage2.Center := True;
  229. BitmapImage2.Left := BitmapImage.Width + 10;
  230. BitmapImage2.Height := 2*BitmapImage.Height;
  231. BitmapImage2.Width := 2*BitmapImage.Width;
  232. BitmapImage2.Cursor := crHand;
  233. BitmapImage2.OnClick := @BitmapImageOnClick;
  234. BitmapImage2.Parent := Page.Surface;
  235. BitmapImage3 := TBitmapImage.Create(Page);
  236. BitmapImage3.Bitmap := BitmapImage.Bitmap;
  237. BitmapImage3.Stretch := True;
  238. BitmapImage3.Left := 3*BitmapImage.Width + 20;
  239. BitmapImage3.Height := 4*BitmapImage.Height;
  240. BitmapImage3.Width := 4*BitmapImage.Width;
  241. BitmapImage3.Cursor := crHand;
  242. BitmapImage3.OnClick := @BitmapImageOnClick;
  243. BitmapImage3.Parent := Page.Surface;
  244. { TRichViewer }
  245. Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TRichViewer');
  246. RichEditViewer := TRichEditViewer.Create(Page);
  247. RichEditViewer.Width := Page.SurfaceWidth;
  248. RichEditViewer.Height := Page.SurfaceHeight;
  249. RichEditViewer.Parent := Page.Surface;
  250. RichEditViewer.ScrollBars := ssVertical;
  251. RichEditViewer.UseRichEdit := True;
  252. 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}';
  253. RichEditViewer.ReadOnly := True;
  254. end;
  255. procedure AboutButtonOnClick(Sender: TObject);
  256. begin
  257. MsgBox('This demo shows some features of the various form objects and control classes.', mbInformation, mb_Ok);
  258. end;
  259. procedure URLLabelOnClick(Sender: TObject);
  260. var
  261. ErrorCode: Integer;
  262. begin
  263. ShellExecAsOriginalUser('open', 'http://www.innosetup.com/', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  264. end;
  265. procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
  266. var
  267. AboutButton: TNewButton;
  268. URLLabel: TNewStaticText;
  269. begin
  270. AboutButton := TNewButton.Create(ParentForm);
  271. AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  272. AboutButton.Top := CancelButton.Top;
  273. AboutButton.Width := CancelButton.Width;
  274. AboutButton.Height := CancelButton.Height;
  275. AboutButton.Caption := '&About...';
  276. AboutButton.OnClick := @AboutButtonOnClick;
  277. AboutButton.Parent := ParentForm;
  278. URLLabel := TNewStaticText.Create(ParentForm);
  279. URLLabel.Caption := 'www.innosetup.com';
  280. URLLabel.Cursor := crHand;
  281. URLLabel.OnClick := @URLLabelOnClick;
  282. URLLabel.Parent := ParentForm;
  283. { Alter Font *after* setting Parent so the correct defaults are inherited first }
  284. URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
  285. if GetWindowsVersion >= $040A0000 then { Windows 98 or later? }
  286. URLLabel.Font.Color := clHotLight
  287. else
  288. URLLabel.Font.Color := clBlue;
  289. URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
  290. URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
  291. end;
  292. procedure InitializeWizard();
  293. var
  294. BackgroundBitmapImage: TBitmapImage;
  295. BackgroundBitmapText: TNewStaticText;
  296. begin
  297. { Custom wizard pages }
  298. CreateTheWizardPages;
  299. { Custom controls }
  300. CreateAboutButtonAndURLLabel(WizardForm, WizardForm.CancelButton);
  301. BackgroundBitmapImage := TBitmapImage.Create(MainForm);
  302. BackgroundBitmapImage.Left := 50;
  303. BackgroundBitmapImage.Top := 90;
  304. BackgroundBitmapImage.AutoSize := True;
  305. BackgroundBitmapImage.Bitmap := WizardForm.WizardBitmapImage.Bitmap;
  306. BackgroundBitmapImage.Parent := MainForm;
  307. BackgroundBitmapText := TNewStaticText.Create(MainForm);
  308. BackgroundBitmapText.Left := BackgroundBitmapImage.Left;
  309. BackgroundBitmapText.Top := BackgroundBitmapImage.Top + BackgroundBitmapImage.Height + ScaleY(8);
  310. BackgroundBitmapText.Caption := 'TBitmapImage';
  311. BackgroundBitmapText.Parent := MainForm;
  312. { Custom beveled label }
  313. WizardForm.BeveledLabel.Caption := ' BeveledLabel ';
  314. end;
  315. procedure InitializeUninstallProgressForm();
  316. begin
  317. { Custom controls }
  318. CreateAboutButtonAndURLLabel(UninstallProgressForm, UninstallProgressForm.CancelButton);
  319. end;