IDE.MsgBoxDesignerForm.pas 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. unit IDE.MsgBoxDesignerForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. MessageBox Designer form
  8. Originally contributed by leserg73
  9. }
  10. interface
  11. uses
  12. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13. UIStateForm, StdCtrls, ExtCtrls, NewStaticText, ComCtrls, pngimage, BitmapImage;
  14. type
  15. TMsgBoxDesignerForm = class(TUIStateForm)
  16. IMGmbInformation: TBitmapImage;
  17. IMGmbConfirmation: TBitmapImage;
  18. IMGmbError: TBitmapImage;
  19. IMGmbCriticalError: TBitmapImage;
  20. Panel1: TPanel;
  21. GroupBox1: TGroupBox;
  22. GroupBox2: TGroupBox;
  23. MSGText: TMemo;
  24. rb_mbInformation: TRadioButton;
  25. rb_mbConfirmation: TRadioButton;
  26. rb_mbError: TRadioButton;
  27. rb_mbCriticalError: TRadioButton;
  28. GroupBox3: TGroupBox;
  29. MBDButtonOK: TButton;
  30. MBDButtonCancel: TButton;
  31. MBDButtonPreview: TButton;
  32. Bevel1: TBevel;
  33. rbMB_OK: TRadioButton;
  34. rbMB_OKCANCEL: TRadioButton;
  35. rbMB_YESNO: TRadioButton;
  36. rbMB_YESNOCANCEL: TRadioButton;
  37. rbMB_RETRYCANCEL: TRadioButton;
  38. rbMB_ABORTRETRYIGNORE: TRadioButton;
  39. GroupBox4: TGroupBox;
  40. cb_IDOK: TCheckBox;
  41. cb_IDCANCEL: TCheckBox;
  42. cb_IDYES: TCheckBox;
  43. cb_IDNO: TCheckBox;
  44. cb_IDABORT: TCheckBox;
  45. cb_IDRETRY: TCheckBox;
  46. cb_IDIGNORE: TCheckBox;
  47. GroupBox5: TGroupBox;
  48. cb_MB_SETFOREGROUND: TCheckBox;
  49. NewStaticText1: TNewStaticText;
  50. NewEdit1: TEdit;
  51. UpDown1: TUpDown;
  52. GroupBox6: TGroupBox;
  53. cb_MsgBox: TRadioButton;
  54. cb_TaskDialogMsgBox: TRadioButton;
  55. rb_IDOK: TCheckBox;
  56. rb_IDCANCEL: TCheckBox;
  57. rb_IDYES: TCheckBox;
  58. rb_IDNO: TCheckBox;
  59. rb_IDABORT: TCheckBox;
  60. rb_IDRETRY: TCheckBox;
  61. rb_IDIGNORE: TCheckBox;
  62. TaskInstructionLabel: TNewStaticText;
  63. TaskMessageLabel: TNewStaticText;
  64. TaskInstructionText: TEdit;
  65. TaskMessageText: TEdit;
  66. Button1Text: TEdit;
  67. Button2Text: TEdit;
  68. Button3Text: TEdit;
  69. Button1Label: TNewStaticText;
  70. Button2Label: TNewStaticText;
  71. Button3Label: TNewStaticText;
  72. cb_Suppressible: TCheckBox;
  73. cb_DefIDOK: TRadioButton;
  74. cb_DefIDCANCEL: TRadioButton;
  75. cb_DefIDYES: TRadioButton;
  76. cb_DefIDNO: TRadioButton;
  77. cb_DefIDABORT: TRadioButton;
  78. cb_DefIDRETRY: TRadioButton;
  79. cb_DefIDIGNORE: TRadioButton;
  80. procedure FormCreate(Sender: TObject);
  81. procedure UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
  82. procedure rbMB_OKClick(Sender: TObject);
  83. procedure rbMB_OKCANCELClick(Sender: TObject);
  84. procedure rbMB_YESNOClick(Sender: TObject);
  85. procedure rbMB_RETRYCANCELClick(Sender: TObject);
  86. procedure rbMB_YESNOCANCELClick(Sender: TObject);
  87. procedure rbMB_ABORTRETRYIGNOREClick(Sender: TObject);
  88. procedure MBDButtonPreviewClick(Sender: TObject);
  89. procedure cb_TaskDialogMsgBoxClick(Sender: TObject);
  90. procedure cb_MsgBoxClick(Sender: TObject);
  91. procedure rb_IDOKClick(Sender: TObject);
  92. procedure rb_IDCANCELClick(Sender: TObject);
  93. procedure rb_IDNOClick(Sender: TObject);
  94. procedure rb_IDYESClick(Sender: TObject);
  95. procedure rb_IDRETRYClick(Sender: TObject);
  96. procedure rb_IDIGNOREClick(Sender: TObject);
  97. procedure rb_IDABORTClick(Sender: TObject);
  98. procedure cb_SuppressibleClick(Sender: TObject);
  99. procedure MSGTextKeyPress(Sender: TObject; var Key: Char);
  100. public
  101. function GetText(TabWidth: Integer; UseTabCharacter: Boolean): String;
  102. end;
  103. implementation
  104. uses
  105. ShellAPI,
  106. Shared.CommonFunc.Vcl, Shared.CommonFunc, IDE.HelperFunc, Shared.TaskDialogFunc, IDE.Messages;
  107. {$R *.DFM}
  108. procedure TMsgBoxDesignerForm.FormCreate(Sender: TObject);
  109. begin
  110. InitFormFont(Self);
  111. InitFormTheme(Self);
  112. IMGmbInformation.InitializeFromStockIcon(SIID_INFO, clNone, [32, 48, 64]);
  113. IMGmbConfirmation.InitializeFromStockIcon(SIID_HELP, clNone, [32, 48, 64]);
  114. IMGmbError.InitializeFromStockIcon(SIID_WARNING, clNone, [32, 48, 64]);
  115. IMGmbCriticalError.InitializeFromStockIcon(SIID_ERROR, clNone, [32, 48, 64]);
  116. cb_Suppressible.Checked := True;
  117. MSGText.Text := '<Enter your text here...>';
  118. MSGText.SelectAll;
  119. cb_IDCANCEL.Enabled := False;
  120. cb_IDABORT.Enabled := False;
  121. cb_IDRETRY.Enabled := False;
  122. cb_IDIGNORE.Enabled := False;
  123. cb_IDYES.Enabled := False;
  124. cb_IDNO.Enabled := False;
  125. NewStaticText1.Enabled := False;
  126. NewEdit1.Enabled := False;
  127. UpDown1.Enabled := False;
  128. TaskInstructionLabel.Visible := False;
  129. TaskMessageLabel.Visible := False;
  130. TaskInstructionText.Visible := False;
  131. TaskMessageText.Visible := False;
  132. Button1Text.Visible := False;
  133. Button2Text.Visible := False;
  134. Button3Text.Visible := False;
  135. Button1Label.Visible := False;
  136. Button2Label.Visible := False;
  137. Button3Label.Visible := False;
  138. end;
  139. procedure TMsgBoxDesignerForm.rbMB_OKClick(Sender: TObject);
  140. begin
  141. cb_IDOK.Checked := False;
  142. cb_IDCANCEL.Checked := False;
  143. cb_IDABORT.Checked := False;
  144. cb_IDRETRY.Checked := False;
  145. cb_IDIGNORE.Checked := False;
  146. cb_IDYES.Checked := False;
  147. cb_IDNO.Checked := False;
  148. cb_IDOK.Enabled := False;
  149. cb_IDCANCEL.Enabled := False;
  150. cb_IDABORT.Enabled := False;
  151. cb_IDRETRY.Enabled := False;
  152. cb_IDIGNORE.Enabled := False;
  153. cb_IDYES.Enabled := False;
  154. cb_IDNO.Enabled := False;
  155. NewStaticText1.Enabled := False;
  156. NewEdit1.Enabled := False;
  157. NewEdit1.Text := '1';
  158. UpDown1.Enabled := False;
  159. if cb_TaskDialogMsgBox.Checked then begin
  160. rb_IDOK.Enabled := True;
  161. rb_IDCANCEL.Enabled := False;
  162. rb_IDABORT.Enabled := False;
  163. rb_IDRETRY.Enabled := False;
  164. rb_IDIGNORE.Enabled := False;
  165. rb_IDYES.Enabled := False;
  166. rb_IDNO.Enabled := False;
  167. rb_IDOK.Checked := False;
  168. rb_IDCANCEL.Checked := False;
  169. rb_IDABORT.Checked := False;
  170. rb_IDRETRY.Checked := False;
  171. rb_IDIGNORE.Checked := False;
  172. rb_IDYES.Checked := False;
  173. rb_IDNO.Checked := False;
  174. Button3Text.Enabled := False;
  175. Button3Label.Enabled := False;
  176. Button2Text.Enabled := False;
  177. Button2Label.Enabled := False;
  178. Button1Text.Enabled := True;
  179. Button1Label.Enabled := True;
  180. Button1Text.Text := 'OK';
  181. Button2Text.Text := '';
  182. Button3Text.Text := '';
  183. end;
  184. if cb_Suppressible.Checked then begin
  185. cb_DefIDOK.Checked := True;
  186. cb_DefIDCANCEL.Checked := False;
  187. cb_DefIDYES.Checked := False;
  188. cb_DefIDNO.Checked := False;
  189. cb_DefIDABORT.Checked := False;
  190. cb_DefIDRETRY.Checked := False;
  191. cb_DefIDIGNORE.Checked := False;
  192. cb_DefIDOK.Enabled := True;
  193. cb_DefIDCANCEL.Enabled := False;
  194. cb_DefIDYES.Enabled := False;
  195. cb_DefIDNO.Enabled := False;
  196. cb_DefIDABORT.Enabled := False;
  197. cb_DefIDRETRY.Enabled := False;
  198. cb_DefIDIGNORE.Enabled := False;
  199. end;
  200. end;
  201. procedure TMsgBoxDesignerForm.rbMB_YESNOClick(Sender: TObject);
  202. begin
  203. cb_IDOK.Checked := False;
  204. cb_IDCANCEL.Checked := False;
  205. cb_IDABORT.Checked := False;
  206. cb_IDRETRY.Checked := False;
  207. cb_IDIGNORE.Checked := False;
  208. cb_IDYES.Checked := False;
  209. cb_IDNO.Checked := False;
  210. cb_IDOK.Enabled := False;
  211. cb_IDCANCEL.Enabled := False;
  212. cb_IDABORT.Enabled := False;
  213. cb_IDRETRY.Enabled := False;
  214. cb_IDIGNORE.Enabled := False;
  215. cb_IDYES.Enabled := True;
  216. cb_IDNO.Enabled := True;
  217. if not cb_TaskDialogMsgBox.Checked then begin
  218. NewStaticText1.Enabled := True;
  219. NewEdit1.Enabled := True;
  220. NewEdit1.Text := '1';
  221. UpDown1.Max := 2;
  222. UpDown1.Enabled := True;
  223. end;
  224. if cb_TaskDialogMsgBox.Checked then begin
  225. rb_IDOK.Enabled := False;
  226. rb_IDCANCEL.Enabled := False;
  227. rb_IDABORT.Enabled := False;
  228. rb_IDRETRY.Enabled := False;
  229. rb_IDIGNORE.Enabled := False;
  230. rb_IDYES.Enabled := True;
  231. rb_IDNO.Enabled := True;
  232. rb_IDOK.Checked := False;
  233. rb_IDCANCEL.Checked := False;
  234. rb_IDABORT.Checked := False;
  235. rb_IDRETRY.Checked := False;
  236. rb_IDIGNORE.Checked := False;
  237. rb_IDYES.Checked := False;
  238. rb_IDNO.Checked := False;
  239. Button3Text.Enabled := False;
  240. Button3Label.Enabled := False;
  241. Button2Text.Enabled := True;
  242. Button2Label.Enabled := True;
  243. Button1Text.Enabled := True;
  244. Button1Label.Enabled := True;
  245. Button1Text.Text := 'Yes';
  246. Button2Text.Text := 'No';
  247. Button3Text.Text := '';
  248. end;
  249. if cb_Suppressible.Checked then begin
  250. cb_DefIDOK.Checked := False;
  251. cb_DefIDCANCEL.Checked := False;
  252. cb_DefIDYES.Checked := True;
  253. cb_DefIDNO.Checked := False;
  254. cb_DefIDABORT.Checked := False;
  255. cb_DefIDRETRY.Checked := False;
  256. cb_DefIDIGNORE.Checked := False;
  257. cb_DefIDOK.Enabled := False;
  258. cb_DefIDCANCEL.Enabled := False;
  259. cb_DefIDYES.Enabled := True;
  260. cb_DefIDNO.Enabled := True;
  261. cb_DefIDABORT.Enabled := False;
  262. cb_DefIDRETRY.Enabled := False;
  263. cb_DefIDIGNORE.Enabled := False;
  264. end;
  265. end;
  266. procedure TMsgBoxDesignerForm.rbMB_OKCANCELClick(Sender: TObject);
  267. begin
  268. cb_IDOK.Checked := False;
  269. cb_IDCANCEL.Checked := False;
  270. cb_IDABORT.Checked := False;
  271. cb_IDRETRY.Checked := False;
  272. cb_IDIGNORE.Checked := False;
  273. cb_IDYES.Checked := False;
  274. cb_IDNO.Checked := False;
  275. cb_IDOK.Enabled := True;
  276. cb_IDCANCEL.Enabled := True;
  277. cb_IDABORT.Enabled := False;
  278. cb_IDRETRY.Enabled := False;
  279. cb_IDIGNORE.Enabled := False;
  280. cb_IDYES.Enabled := False;
  281. cb_IDNO.Enabled := False;
  282. if not cb_TaskDialogMsgBox.Checked then begin
  283. NewStaticText1.Enabled := True;
  284. NewEdit1.Enabled := True;
  285. NewEdit1.Text := '1';
  286. UpDown1.Max := 2;
  287. UpDown1.Enabled := True;
  288. end;
  289. if cb_TaskDialogMsgBox.Checked then begin
  290. rb_IDOK.Enabled := True;
  291. rb_IDCANCEL.Enabled := True;
  292. rb_IDABORT.Enabled := False;
  293. rb_IDRETRY.Enabled := False;
  294. rb_IDIGNORE.Enabled := False;
  295. rb_IDYES.Enabled := False;
  296. rb_IDNO.Enabled := False;
  297. rb_IDOK.Checked := False;
  298. rb_IDCANCEL.Checked := False;
  299. rb_IDABORT.Checked := False;
  300. rb_IDRETRY.Checked := False;
  301. rb_IDIGNORE.Checked := False;
  302. rb_IDYES.Checked := False;
  303. rb_IDNO.Checked := False;
  304. Button3Text.Enabled := False;
  305. Button3Label.Enabled := False;
  306. Button2Text.Enabled := True;
  307. Button2Label.Enabled := True;
  308. Button1Text.Enabled := True;
  309. Button1Label.Enabled := True;
  310. Button1Text.Text := 'OK';
  311. Button2Text.Text := 'Cancel';
  312. Button3Text.Text := '';
  313. end;
  314. if cb_Suppressible.Checked then begin
  315. cb_DefIDOK.Checked := True;
  316. cb_DefIDCANCEL.Checked := False;
  317. cb_DefIDYES.Checked := False;
  318. cb_DefIDNO.Checked := False;
  319. cb_DefIDABORT.Checked := False;
  320. cb_DefIDRETRY.Checked := False;
  321. cb_DefIDIGNORE.Checked := False;
  322. cb_DefIDOK.Enabled := True;
  323. cb_DefIDCANCEL.Enabled := True;
  324. cb_DefIDYES.Enabled := False;
  325. cb_DefIDNO.Enabled := False;
  326. cb_DefIDABORT.Enabled := False;
  327. cb_DefIDRETRY.Enabled := False;
  328. cb_DefIDIGNORE.Enabled := False;
  329. end;
  330. end;
  331. procedure TMsgBoxDesignerForm.rbMB_RETRYCANCELClick(Sender: TObject);
  332. begin
  333. cb_IDOK.Checked := False;
  334. cb_IDCANCEL.Checked := False;
  335. cb_IDABORT.Checked := False;
  336. cb_IDRETRY.Checked := False;
  337. cb_IDIGNORE.Checked := False;
  338. cb_IDYES.Checked := False;
  339. cb_IDNO.Checked := False;
  340. cb_IDOK.Enabled := False;
  341. cb_IDCANCEL.Enabled := True;
  342. cb_IDABORT.Enabled := False;
  343. cb_IDRETRY.Enabled := True;
  344. cb_IDIGNORE.Enabled := False;
  345. cb_IDYES.Enabled := False;
  346. cb_IDNO.Enabled := False;
  347. if not cb_TaskDialogMsgBox.Checked then begin
  348. NewStaticText1.Enabled := True;
  349. NewEdit1.Enabled := True;
  350. NewEdit1.Text := '1';
  351. UpDown1.Max := 2;
  352. UpDown1.Enabled := True;
  353. end;
  354. if cb_TaskDialogMsgBox.Checked then begin
  355. rb_IDOK.Enabled := False;
  356. rb_IDCANCEL.Enabled := True;
  357. rb_IDABORT.Enabled := False;
  358. rb_IDRETRY.Enabled := True;
  359. rb_IDIGNORE.Enabled := False;
  360. rb_IDYES.Enabled := False;
  361. rb_IDNO.Enabled := False;
  362. rb_IDOK.Checked := False;
  363. rb_IDCANCEL.Checked := False;
  364. rb_IDABORT.Checked := False;
  365. rb_IDRETRY.Checked := False;
  366. rb_IDIGNORE.Checked := False;
  367. rb_IDYES.Checked := False;
  368. rb_IDNO.Checked := False;
  369. Button3Text.Enabled := False;
  370. Button3Label.Enabled := False;
  371. Button2Text.Enabled := True;
  372. Button2Label.Enabled := True;
  373. Button1Text.Enabled := True;
  374. Button1Label.Enabled := True;
  375. Button1Text.Text := 'Retry';
  376. Button2Text.Text := 'Cancel';
  377. Button3Text.Text := '';
  378. end;
  379. if cb_Suppressible.Checked then begin
  380. cb_DefIDOK.Checked := False;
  381. cb_DefIDCANCEL.Checked := True;
  382. cb_DefIDYES.Checked := False;
  383. cb_DefIDNO.Checked := False;
  384. cb_DefIDABORT.Checked := False;
  385. cb_DefIDRETRY.Checked := False;
  386. cb_DefIDIGNORE.Checked := False;
  387. cb_DefIDOK.Enabled := False;
  388. cb_DefIDCANCEL.Enabled := True;
  389. cb_DefIDYES.Enabled := False;
  390. cb_DefIDNO.Enabled := False;
  391. cb_DefIDABORT.Enabled := False;
  392. cb_DefIDRETRY.Enabled := True;
  393. cb_DefIDIGNORE.Enabled := False;
  394. end;
  395. end;
  396. procedure TMsgBoxDesignerForm.rbMB_YESNOCANCELClick(Sender: TObject);
  397. begin
  398. cb_IDOK.Checked := False;
  399. cb_IDCANCEL.Checked := False;
  400. cb_IDABORT.Checked := False;
  401. cb_IDRETRY.Checked := False;
  402. cb_IDIGNORE.Checked := False;
  403. cb_IDYES.Checked := False;
  404. cb_IDNO.Checked := False;
  405. cb_IDOK.Enabled := False;
  406. cb_IDCANCEL.Enabled := True;
  407. cb_IDABORT.Enabled := False;
  408. cb_IDRETRY.Enabled := False;
  409. cb_IDIGNORE.Enabled := False;
  410. cb_IDYES.Enabled := True;
  411. cb_IDNO.Enabled := True;
  412. if not cb_TaskDialogMsgBox.Checked then begin
  413. NewStaticText1.Enabled := True;
  414. NewEdit1.Enabled := True;
  415. NewEdit1.Text := '1';
  416. UpDown1.Max := 3;
  417. UpDown1.Enabled := True;
  418. end;
  419. if cb_TaskDialogMsgBox.Checked then begin
  420. rb_IDOK.Enabled := False;
  421. rb_IDCANCEL.Enabled := True;
  422. rb_IDABORT.Enabled := False;
  423. rb_IDRETRY.Enabled := False;
  424. rb_IDIGNORE.Enabled := False;
  425. rb_IDYES.Enabled := True;
  426. rb_IDNO.Enabled := True;
  427. rb_IDOK.Checked := False;
  428. rb_IDCANCEL.Checked := False;
  429. rb_IDABORT.Checked := False;
  430. rb_IDRETRY.Checked := False;
  431. rb_IDIGNORE.Checked := False;
  432. rb_IDYES.Checked := False;
  433. rb_IDNO.Checked := False;
  434. Button3Text.Enabled := True;
  435. Button3Label.Enabled := True;
  436. Button2Text.Enabled := True;
  437. Button2Label.Enabled := True;
  438. Button1Text.Enabled := True;
  439. Button1Label.Enabled := True;
  440. Button1Text.Text := 'Yes';
  441. Button2Text.Text := 'No';
  442. Button3Text.Text := 'Cancel';
  443. end;
  444. if cb_Suppressible.Checked then begin
  445. cb_DefIDOK.Checked := False;
  446. cb_DefIDCANCEL.Checked := False;
  447. cb_DefIDYES.Checked := True;
  448. cb_DefIDNO.Checked := False;
  449. cb_DefIDABORT.Checked := False;
  450. cb_DefIDRETRY.Checked := False;
  451. cb_DefIDIGNORE.Checked := False;
  452. cb_DefIDOK.Enabled := False;
  453. cb_DefIDCANCEL.Enabled := True;
  454. cb_DefIDYES.Enabled := True;
  455. cb_DefIDNO.Enabled := True;
  456. cb_DefIDABORT.Enabled := False;
  457. cb_DefIDRETRY.Enabled := False;
  458. cb_DefIDIGNORE.Enabled := False;
  459. end;
  460. end;
  461. procedure TMsgBoxDesignerForm.rbMB_ABORTRETRYIGNOREClick(Sender: TObject);
  462. begin
  463. cb_IDOK.Checked := False;
  464. cb_IDCANCEL.Checked := False;
  465. cb_IDABORT.Checked := False;
  466. cb_IDRETRY.Checked := False;
  467. cb_IDIGNORE.Checked := False;
  468. cb_IDYES.Checked := False;
  469. cb_IDNO.Checked := False;
  470. cb_IDOK.Enabled := False;
  471. cb_IDCANCEL.Enabled := False;
  472. cb_IDABORT.Enabled := True;
  473. cb_IDRETRY.Enabled := True;
  474. cb_IDIGNORE.Enabled := True;
  475. cb_IDYES.Enabled := False;
  476. cb_IDNO.Enabled := False;
  477. if not cb_TaskDialogMsgBox.Checked then begin
  478. NewStaticText1.Enabled := True;
  479. NewEdit1.Enabled := True;
  480. NewEdit1.Text := '1';
  481. UpDown1.Max := 3;
  482. UpDown1.Enabled := True;
  483. end;
  484. if cb_TaskDialogMsgBox.Checked then begin
  485. rb_IDOK.Enabled := False;
  486. rb_IDCANCEL.Enabled := False;
  487. rb_IDABORT.Enabled := True;
  488. rb_IDRETRY.Enabled := True;
  489. rb_IDIGNORE.Enabled := True;
  490. rb_IDYES.Enabled := False;
  491. rb_IDNO.Enabled := False;
  492. rb_IDOK.Checked := False;
  493. rb_IDCANCEL.Checked := False;
  494. rb_IDABORT.Checked := False;
  495. rb_IDRETRY.Checked := False;
  496. rb_IDIGNORE.Checked := False;
  497. rb_IDYES.Checked := False;
  498. rb_IDNO.Checked := False;
  499. Button3Text.Enabled := True;
  500. Button3Label.Enabled := True;
  501. Button2Text.Enabled := True;
  502. Button2Label.Enabled := True;
  503. Button1Text.Enabled := True;
  504. Button1Label.Enabled := True;
  505. Button1Text.Text := 'Retry'; //this order is not a mistake
  506. Button2Text.Text := 'Ignore'; //
  507. Button3Text.Text := 'Abort'; //
  508. end;
  509. if cb_Suppressible.Checked then begin
  510. cb_DefIDOK.Checked := False;
  511. cb_DefIDCANCEL.Checked := False;
  512. cb_DefIDYES.Checked := False;
  513. cb_DefIDNO.Checked := False;
  514. cb_DefIDABORT.Checked := False;
  515. cb_DefIDRETRY.Checked := False;
  516. cb_DefIDIGNORE.Checked := True;
  517. cb_DefIDOK.Enabled := False;
  518. cb_DefIDCANCEL.Enabled := False;
  519. cb_DefIDYES.Enabled := False;
  520. cb_DefIDNO.Enabled := False;
  521. cb_DefIDABORT.Enabled := True;
  522. cb_DefIDRETRY.Enabled := True;
  523. cb_DefIDIGNORE.Enabled := True;
  524. end;
  525. end;
  526. procedure TMsgBoxDesignerForm.UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
  527. begin
  528. AllowChange := True;
  529. end;
  530. procedure TMsgBoxDesignerForm.cb_MsgBoxClick(Sender: TObject);
  531. begin
  532. IMGmbConfirmation.Visible := True;
  533. cb_MB_SETFOREGROUND.Enabled := True;
  534. cb_MB_SETFOREGROUND.Checked := False;
  535. GroupBox1.Visible := True;
  536. if not cb_Suppressible.Checked then begin
  537. GroupBox4.Caption := ' Return values ';
  538. cb_DefIDOK.Visible := False;
  539. cb_DefIDCANCEL.Visible := False;
  540. cb_DefIDYES.Visible := False;
  541. cb_DefIDNO.Visible := False;
  542. cb_DefIDABORT.Visible := False;
  543. cb_DefIDRETRY.Visible := False;
  544. cb_DefIDIGNORE.Visible := False;
  545. end
  546. else begin
  547. GroupBox4.Caption := ' Return values / ------- / Default ';
  548. cb_DefIDOK.Visible := True;
  549. cb_DefIDCANCEL.Visible := True;
  550. cb_DefIDYES.Visible := True;
  551. cb_DefIDNO.Visible := True;
  552. cb_DefIDABORT.Visible := True;
  553. cb_DefIDRETRY.Visible := True;
  554. cb_DefIDIGNORE.Visible := True;
  555. end;
  556. cb_IDOK.Checked := False;
  557. cb_IDCANCEL.Checked := False;
  558. cb_IDABORT.Checked := False;
  559. cb_IDRETRY.Checked := False;
  560. cb_IDIGNORE.Checked := False;
  561. cb_IDYES.Checked := False;
  562. cb_IDNO.Checked := False;
  563. rb_IDOK.Visible := False;
  564. rb_IDCANCEL.Visible := False;
  565. rb_IDABORT.Visible := False;
  566. rb_IDRETRY.Visible := False;
  567. rb_IDIGNORE.Visible := False;
  568. rb_IDYES.Visible := False;
  569. rb_IDNO.Visible := False;
  570. rb_mbInformation.Checked := True;
  571. TaskInstructionLabel.Visible := False;
  572. TaskMessageLabel.Visible := False;
  573. TaskInstructionText.Visible := False;
  574. TaskMessageText.Visible := False;
  575. Button1Text.Visible := False;
  576. Button2Text.Visible := False;
  577. Button3Text.Visible := False;
  578. Button1Label.Visible := False;
  579. Button2Label.Visible := False;
  580. Button3Label.Visible := False;
  581. rbMB_OK.Checked := True;
  582. rbMB_OKClick(Self);
  583. end;
  584. procedure TMsgBoxDesignerForm.cb_SuppressibleClick(Sender: TObject);
  585. begin
  586. if cb_Suppressible.Checked then begin
  587. cb_DefIDOK.Visible := True;
  588. cb_DefIDCANCEL.Visible := True;
  589. cb_DefIDYES.Visible := True;
  590. cb_DefIDNO.Visible := True;
  591. cb_DefIDABORT.Visible := True;
  592. cb_DefIDRETRY.Visible := True;
  593. cb_DefIDIGNORE.Visible := True;
  594. if cb_MsgBox.Checked then
  595. GroupBox4.Caption := ' Return values / -------- / Default ';
  596. if cb_TaskDialogMsgBox.Checked then
  597. GroupBox4.Caption := ' Return values / Shield / Default ';
  598. end
  599. else begin
  600. cb_DefIDOK.Checked := False;
  601. cb_DefIDCANCEL.Checked := False;
  602. cb_DefIDYES.Checked := False;
  603. cb_DefIDNO.Checked := False;
  604. cb_DefIDABORT.Checked := False;
  605. cb_DefIDRETRY.Checked := False;
  606. cb_DefIDIGNORE.Checked := False;
  607. cb_DefIDOK.Visible := False;
  608. cb_DefIDCANCEL.Visible := False;
  609. cb_DefIDYES.Visible := False;
  610. cb_DefIDNO.Visible := False;
  611. cb_DefIDABORT.Visible := False;
  612. cb_DefIDRETRY.Visible := False;
  613. cb_DefIDIGNORE.Visible := False;
  614. if cb_MsgBox.Checked then
  615. GroupBox4.Caption := ' Return values ';
  616. if cb_TaskDialogMsgBox.Checked then
  617. GroupBox4.Caption := ' Return values / Shield ';
  618. end;
  619. if rbMB_OK.Checked then rbMB_OKClick(Self);
  620. if rbMB_OKCANCEL.Checked then rbMB_OKCANCELClick(Self);
  621. if rbMB_YESNO.Checked then rbMB_YESNOClick(Self);
  622. if rbMB_YESNOCANCEL.Checked then rbMB_YESNOCANCELClick(Self);
  623. if rbMB_RETRYCANCEL.Checked then rbMB_RETRYCANCELClick(Self);
  624. if rbMB_ABORTRETRYIGNORE.Checked then rbMB_ABORTRETRYIGNOREClick(Self);
  625. end;
  626. procedure TMsgBoxDesignerForm.cb_TaskDialogMsgBoxClick(Sender: TObject);
  627. begin
  628. IMGmbConfirmation.Visible := False;
  629. cb_MB_SETFOREGROUND.Enabled := False;
  630. cb_MB_SETFOREGROUND.Checked := False;
  631. GroupBox1.Visible := False;
  632. if not cb_Suppressible.Checked then begin
  633. GroupBox4.Caption := ' Return values / Shield ';
  634. cb_DefIDOK.Visible := False;
  635. cb_DefIDCANCEL.Visible := False;
  636. cb_DefIDYES.Visible := False;
  637. cb_DefIDNO.Visible := False;
  638. cb_DefIDABORT.Visible := False;
  639. cb_DefIDRETRY.Visible := False;
  640. cb_DefIDIGNORE.Visible := False;
  641. end
  642. else begin
  643. GroupBox4.Caption := ' Return values / Shield / Default ';
  644. cb_DefIDOK.Visible := True;
  645. cb_DefIDCANCEL.Visible := True;
  646. cb_DefIDYES.Visible := True;
  647. cb_DefIDNO.Visible := True;
  648. cb_DefIDABORT.Visible := True;
  649. cb_DefIDRETRY.Visible := True;
  650. cb_DefIDIGNORE.Visible := True;
  651. end;
  652. cb_IDOK.Checked := False;
  653. cb_IDCANCEL.Checked := False;
  654. cb_IDABORT.Checked := False;
  655. cb_IDRETRY.Checked := False;
  656. cb_IDIGNORE.Checked := False;
  657. cb_IDYES.Checked := False;
  658. cb_IDNO.Checked := False;
  659. rb_IDOK.Checked := False;
  660. rb_IDCANCEL.Checked := False;
  661. rb_IDABORT.Checked := False;
  662. rb_IDRETRY.Checked := False;
  663. rb_IDIGNORE.Checked := False;
  664. rb_IDYES.Checked := False;
  665. rb_IDNO.Checked := False;
  666. rb_IDOK.Visible := True;
  667. rb_IDCANCEL.Visible := True;
  668. rb_IDABORT.Visible := True;
  669. rb_IDRETRY.Visible := True;
  670. rb_IDIGNORE.Visible := True;
  671. rb_IDYES.Visible := True;
  672. rb_IDNO.Visible := True;
  673. rb_mbInformation.Checked := True;
  674. TaskInstructionLabel.Visible := True;
  675. TaskMessageLabel.Visible := True;
  676. TaskInstructionText.Visible := True;
  677. TaskMessageText.Visible := True;
  678. Button1Text.Visible := True;
  679. Button2Text.Visible := True;
  680. Button3Text.Visible := True;
  681. Button1Label.Visible := True;
  682. Button2Label.Visible := True;
  683. Button3Label.Visible := True;
  684. TaskInstructionText.Text := 'Instruction Text';
  685. TaskMessageText.Text := 'Message Text';
  686. rbMB_OK.Checked := True;
  687. rbMB_OKClick(Self);
  688. end;
  689. procedure TMsgBoxDesignerForm.rb_IDOKClick(Sender: TObject);
  690. begin
  691. if rb_IDOK.Checked then
  692. rb_IDCANCEL.Checked := False;
  693. end;
  694. procedure TMsgBoxDesignerForm.rb_IDCANCELClick(Sender: TObject);
  695. begin
  696. if rb_IDCANCEL.Checked then begin
  697. rb_IDOK.Checked := False;
  698. rb_IDNO.Checked := False;
  699. rb_IDYES.Checked := False;
  700. rb_IDRETRY.Checked := False;
  701. end;
  702. end;
  703. procedure TMsgBoxDesignerForm.rb_IDYESClick(Sender: TObject);
  704. begin
  705. if rb_IDYES.Checked then begin
  706. rb_IDNO.Checked := False;
  707. rb_IDCANCEL.Checked := False;
  708. end;
  709. end;
  710. procedure TMsgBoxDesignerForm.rb_IDNOClick(Sender: TObject);
  711. begin
  712. if rb_IDNO.Checked then begin
  713. rb_IDYES.Checked := False;
  714. rb_IDCANCEL.Checked := False;
  715. end;
  716. end;
  717. procedure TMsgBoxDesignerForm.rb_IDRETRYClick(Sender: TObject);
  718. begin
  719. if rb_IDRETRY.Checked then begin
  720. rb_IDCANCEL.Checked := False;
  721. rb_IDABORT.Checked := False;
  722. rb_IDIGNORE.Checked := False;
  723. end;
  724. end;
  725. procedure TMsgBoxDesignerForm.rb_IDIGNOREClick(Sender: TObject);
  726. begin
  727. if rb_IDIGNORE.Checked then begin
  728. rb_IDABORT.Checked := False;
  729. rb_IDRETRY.Checked := False;
  730. end;
  731. end;
  732. procedure TMsgBoxDesignerForm.rb_IDABORTClick(Sender: TObject);
  733. begin
  734. if rb_IDABORT.Checked then begin
  735. rb_IDIGNORE.Checked := False;
  736. rb_IDRETRY.Checked := False;
  737. end;
  738. end;
  739. procedure TMsgBoxDesignerForm.MBDButtonPreviewClick(Sender: TObject);
  740. begin
  741. { default value }
  742. var Buttons: Cardinal := MB_OK;
  743. var Typ := mbInformation;
  744. { icon and caption set }
  745. var Caption: String;
  746. if rb_mbInformation.Checked then begin
  747. Caption := 'Info';
  748. Typ := mbInformation;
  749. end;
  750. if rb_mbConfirmation.Checked then begin
  751. Caption := 'Confirm';
  752. Typ := mbConfirmation;
  753. end;
  754. if rb_mbError.Checked then begin
  755. Caption := 'Error';
  756. Typ := mbError;
  757. end;
  758. if rb_mbCriticalError.Checked then begin
  759. Caption := 'Fatal Error';
  760. Typ := mbCriticalError;
  761. end;
  762. { button type set }
  763. if rbMB_OK.Checked then Buttons := MB_OK;
  764. if rbMB_OKCANCEL.Checked then Buttons := MB_OKCANCEL;
  765. if rbMB_YESNO.Checked then Buttons := MB_YESNO;
  766. if rbMB_YESNOCANCEL.Checked then Buttons := MB_YESNOCANCEL;
  767. if rbMB_RETRYCANCEL.Checked then Buttons := MB_RETRYCANCEL;
  768. if rbMB_ABORTRETRYIGNORE.Checked then Buttons := MB_ABORTRETRYIGNORE;
  769. if cb_MsgBox.Checked then begin
  770. if MSGText.GetTextLen = 0 then
  771. MSGText.Lines.Add('Your message text.');
  772. { MessageBox with DefButton }
  773. if NewEdit1.Text = '1' then
  774. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons);
  775. if NewEdit1.Text = '2' then
  776. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON2);
  777. if NewEdit1.Text = '3' then
  778. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON3);
  779. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  780. if (NewEdit1.Text = '1') and (cb_MB_SETFOREGROUND.Checked) then
  781. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_SETFOREGROUND);
  782. if (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  783. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON2 or MB_SETFOREGROUND);
  784. if (NewEdit1.Text = '3') and (cb_MB_SETFOREGROUND.Checked) then
  785. MsgBox(MSGText.Lines.GetText, Caption, Typ, Buttons or MB_DEFBUTTON3 or MB_SETFOREGROUND);
  786. end else if cb_TaskDialogMsgBox.Checked then begin
  787. { create ButtonLabels array - also see GetText}
  788. var ButtonLabels: TArray<string>;
  789. if Button3Text.Enabled then
  790. ButtonLabels := TArray<string>.Create(Button1Text.Text, Button2Text.Text, Button3Text.Text)
  791. else if Button2Text.Enabled then
  792. ButtonLabels := TArray<string>.Create(Button1Text.Text, Button2Text.Text)
  793. else
  794. ButtonLabels := TArray<string>.Create(Button1Text.Text);
  795. if rbMB_OKCANCEL.Checked or rbMB_YESNOCANCEL.Checked or rbMB_RETRYCANCEL.Checked then begin
  796. { Specifying a cancel label is optional: if it's missing TaskDialogMsgBox will use a button
  797. at the bottom instead }
  798. const NLabels = Length(ButtonLabels);
  799. if ButtonLabels[NLabels-1] = '' then
  800. SetLength(ButtonLabels, NLabels-1);
  801. end;
  802. { get Shield Flag value }
  803. var ShieldButton := 0;
  804. if rbMB_OK.Checked and rb_IDOK.Checked then ShieldButton := IDOK;
  805. if rbMB_OKCANCEL.Checked and rb_IDOK.Checked then ShieldButton := IDOK;
  806. if rbMB_OKCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := IDCANCEL;
  807. if rbMB_YESNO.Checked and rb_IDYES.Checked then ShieldButton := IDYES;
  808. if rbMB_YESNO.Checked and rb_IDNO.Checked then ShieldButton := IDNO;
  809. if rbMB_YESNOCANCEL.Checked and rb_IDYES.Checked then ShieldButton := IDYES;
  810. if rbMB_YESNOCANCEL.Checked and rb_IDNO.Checked then ShieldButton := IDNO;
  811. if rbMB_YESNOCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := IDCANCEL;
  812. if rbMB_RETRYCANCEL.Checked and rb_IDRETRY.Checked then ShieldButton := IDRETRY;
  813. if rbMB_RETRYCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := IDCANCEL;
  814. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDRETRY.Checked then ShieldButton := IDRETRY;
  815. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDABORT.Checked then ShieldButton := IDABORT;
  816. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDIGNORE.Checked then ShieldButton := IDIGNORE;
  817. { TaskDialogMsgBox(Icon, Instruction, Text, Caption, Typ, Buttons, ButtonLabels, ShieldButton) }
  818. TaskDialogMsgBox('', TaskInstructionText.Text, TaskMessageText.Text, Caption,
  819. Typ, Buttons, ButtonLabels, ShieldButton);
  820. end;
  821. end;
  822. procedure TMsgBoxDesignerForm.MSGTextKeyPress(Sender: TObject; var Key: Char);
  823. begin
  824. if Key = #27 then begin
  825. MBDButtonCancel.Click;
  826. Key := #0;
  827. end;
  828. end;
  829. function TMsgBoxDesignerForm.GetText(TabWidth: Integer; UseTabCharacter: Boolean): String;
  830. function TextTab: String;
  831. begin
  832. if UseTabCharacter then
  833. Result := #9
  834. else
  835. Result := Format('%*s', [TabWidth, '']);
  836. end;
  837. function TextUserClicked(IDButton: String): String;
  838. begin
  839. Result := 'user clicked ' + StringReplace(IDButton, 'ID', '', [])
  840. end;
  841. function TextCase(IDButton: String): String;
  842. begin
  843. Result := TextTab + IDButton +': { ' + TextUserClicked(IDButton) + ' };';
  844. end;
  845. function TextCall(ButtonCount: Integer; SCall, IDButton, IDButton2, IDButton3: String): String;
  846. begin
  847. case ButtonCount of
  848. 0: Result := SCall + ';';
  849. 1: Result := 'if ' + SCall + ' = ' + IDButton + ' then' + SNewLine +
  850. 'begin' + SNewLine +
  851. TextTab + '// ' + TextUserClicked(IDButton) + SNewLine +
  852. 'end;';
  853. 2, 3:
  854. begin
  855. Result := 'case ' + SCall + ' of ' + SNewLine +
  856. TextCase(IDButton) + SNewLine +
  857. TextCase(IDButton2) + SNewLine;
  858. if ButtonCount = 3 then
  859. Result := Result + TextCase(IDButton3) + SNewLine;
  860. Result := Result + 'end;';
  861. end;
  862. end;
  863. end;
  864. { MsgBox / SuppressibleMsgBox }
  865. function TextMsgBox(ButtonCount: Integer; Caption, Typ, Buttons,
  866. IDButton, IDButton2, IDButton3: String): String;
  867. begin
  868. var SMsgBox: String;
  869. if not cb_Suppressible.Checked then
  870. SMsgBox := 'MsgBox'
  871. else
  872. SMsgBox := 'SuppressibleMsgBox';
  873. //Buttons also contains Default if suppressible, pre-separated by a comma (but ButtonCount does *not* include this)
  874. SMsgBox := SMsgBox + '(''' + Caption + ''', ' + Typ + ', ' + Buttons + ')';
  875. Result := TextCall(ButtonCount, SMsgBox, IDButton, IDButton2, IDButton3);
  876. end;
  877. { TaskDialogMsgBox / SuppressibleTaskDialogMsgBox }
  878. function TextTaskDialog(ButtonCount: Integer; InstructionAndText, Typ, Buttons,
  879. ButtonLabels, ShieldButton, IDButton, IDButton2, IDButton3: String): String;
  880. begin
  881. var STaskDialog: String;
  882. if not cb_Suppressible.Checked then
  883. STaskDialog := 'TaskDialogMsgBox'
  884. else
  885. STaskDialog := 'SuppressibleTaskDialogMsgBox';
  886. //InstructionAndText contains both Instruction and Text, pre-separated by a quote, a comma and another quote
  887. //ButtonLabels contains all labels, also pre-separated by the above
  888. //ShieldButton also contains Default if suppressible, pre-separated by a comma (but ButtonCount does *not* include this)
  889. STaskDialog := STaskDialog+ '(''' + InstructionAndText + ''', ' + Typ + ', ' + Buttons + ', [''' + ButtonLabels + '''], ' + ShieldButton + ')';
  890. Result := TextCall(ButtonCount, STaskDialog, IDButton, IDButton2, IDButton3);
  891. end;
  892. begin
  893. { default value }
  894. var ButtonCount := 0;
  895. var Buttons := 'MB_OK';
  896. var Typ := 'mbInformation';
  897. var ShieldButton: String := '0';
  898. var SuppressibleDefault := '';
  899. { make a string with Default parameter for Suppressible* calls }
  900. if cb_Suppressible.Checked then begin
  901. if cb_DefIDOK.Checked then SuppressibleDefault := ', IDOK';
  902. if cb_DefIDCANCEL.Checked then SuppressibleDefault := ', IDCANCEL';
  903. if cb_DefIDYES.Checked then SuppressibleDefault := ', IDYES';
  904. if cb_DefIDNO.Checked then SuppressibleDefault := ', IDNO';
  905. if cb_DefIDABORT.Checked then SuppressibleDefault := ', IDABORT';
  906. if cb_DefIDRETRY.Checked then SuppressibleDefault := ', IDRETRY';
  907. if cb_DefIDIGNORE.Checked then SuppressibleDefault := ', IDIGNORE';
  908. end;
  909. { icon and caption set }
  910. if rb_mbInformation.Checked then begin
  911. Typ := 'mbInformation';
  912. end;
  913. if rb_mbConfirmation.Checked then begin
  914. Typ := 'mbConfirmation';
  915. end;
  916. if rb_mbError.Checked then begin
  917. Typ := 'mbError';
  918. end;
  919. if rb_mbCriticalError.Checked then begin
  920. Typ := 'mbCriticalError';
  921. end;
  922. { button type set }
  923. if rbMB_OK.Checked then Buttons := 'MB_OK';
  924. if rbMB_OKCANCEL.Checked then Buttons := 'MB_OKCANCEL';
  925. if rbMB_YESNO.Checked then Buttons := 'MB_YESNO';
  926. if rbMB_YESNOCANCEL.Checked then Buttons := 'MB_YESNOCANCEL';
  927. if rbMB_RETRYCANCEL.Checked then Buttons := 'MB_RETRYCANCEL';
  928. if rbMB_ABORTRETRYIGNORE.Checked then Buttons := 'MB_ABORTRETRYIGNORE';
  929. var ModeMsg: Integer;
  930. var CaptionOrInstructionAndText: String;
  931. var ButtonLabels: String;
  932. if cb_MsgBox.Checked then begin
  933. { MsgBox(Text, Typ, Buttons); }
  934. ModeMsg := 0;
  935. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  936. if (rbMB_OK.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  937. Buttons := 'MB_OK or MB_SETFOREGROUND';
  938. if (rbMB_OKCANCEL.Checked) and (NewEdit1.Text = '2') then
  939. Buttons := 'MB_OKCANCEL or MB_DEFBUTTON2';
  940. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  941. if (rbMB_OKCANCEL.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  942. Buttons := 'MB_OKCANCEL or MB_SETFOREGROUND';
  943. if (rbMB_OKCANCEL.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  944. Buttons := 'MB_OKCANCEL or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  945. if (rbMB_YESNO.Checked) and (NewEdit1.Text = '2') then
  946. Buttons := 'MB_YESNO or MB_DEFBUTTON2';
  947. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  948. if (rbMB_YESNO.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  949. Buttons := 'MB_YESNO or MB_SETFOREGROUND';
  950. if (rbMB_YESNO.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  951. Buttons := 'MB_YESNO or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  952. if (rbMB_RETRYCANCEL.Checked) and (NewEdit1.Text = '2') then
  953. Buttons := 'MB_RETRYCANCEL or MB_DEFBUTTON2';
  954. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  955. if (rbMB_RETRYCANCEL.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  956. Buttons := 'MB_RETRYCANCEL or MB_SETFOREGROUND';
  957. if (rbMB_RETRYCANCEL.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  958. Buttons := 'MB_RETRYCANCEL or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  959. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '2') then
  960. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON2';
  961. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '3') then
  962. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON3';
  963. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  964. if (rbMB_YESNOCANCEL.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  965. Buttons := 'MB_YESNOCANCEL or MB_SETFOREGROUND';
  966. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  967. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  968. if (rbMB_YESNOCANCEL.Checked) and (NewEdit1.Text = '3') and (cb_MB_SETFOREGROUND.Checked) then
  969. Buttons := 'MB_YESNOCANCEL or MB_DEFBUTTON3 or MB_SETFOREGROUND';
  970. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '2') then
  971. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON2';
  972. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '3') then
  973. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON3';
  974. { MessageBox with DefButton and Flag MB_SETFOREGROUND }
  975. if (rbMB_ABORTRETRYIGNORE.Checked) and (cb_MB_SETFOREGROUND.Checked) then
  976. Buttons := 'MB_ABORTRETRYIGNORE or MB_SETFOREGROUND';
  977. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '2') and (cb_MB_SETFOREGROUND.Checked) then
  978. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON2 or MB_SETFOREGROUND';
  979. if (rbMB_ABORTRETRYIGNORE.Checked) and (NewEdit1.Text = '3') and (cb_MB_SETFOREGROUND.Checked) then
  980. Buttons := 'MB_ABORTRETRYIGNORE or MB_DEFBUTTON3 or MB_SETFOREGROUND';
  981. { Suppressible msg }
  982. if cb_Suppressible.Checked then Buttons := Buttons + SuppressibleDefault;
  983. { replace in a message string escape /r/n }
  984. CaptionOrInstructionAndText := StringReplace(MSGText.Lines.GetText, SNewLine, '''#13#10''', [rfReplaceAll]);
  985. end else begin
  986. { TaskDialogMsgBox(TaskInstructionText.Text, TaskMessageText.Text, Typ, Buttons, ButtonLabels, ShieldButton) }
  987. ModeMsg := 1;
  988. { create ButtonLabels array - also see MBDButtonPreviewClick }
  989. var ButtonLabelsArray: TArray<string>;
  990. if Button3Text.Enabled then
  991. ButtonLabelsArray := TArray<string>.Create(Button1Text.Text, Button2Text.Text, Button3Text.Text)
  992. else if Button2Text.Enabled then
  993. ButtonLabelsArray := TArray<string>.Create(Button1Text.Text, Button2Text.Text)
  994. else
  995. ButtonLabelsArray := TArray<string>.Create(Button1Text.Text);
  996. var NLabels := Length(ButtonLabelsArray);
  997. if rbMB_OKCANCEL.Checked or rbMB_YESNOCANCEL.Checked or rbMB_RETRYCANCEL.Checked then begin
  998. { Specifying a cancel label is optional: if it's missing TaskDialogMsgBox will use a button
  999. at the bottom instead }
  1000. if ButtonLabelsArray[NLabels-1] = '' then begin
  1001. Dec(NLabels);
  1002. SetLength(ButtonLabelsArray, NLabels);
  1003. end;
  1004. end;
  1005. for var I := 0 to NLabels-1 do begin { NLabels is always > 0 }
  1006. if I = 0 then
  1007. ButtonLabels := ButtonLabelsArray[I]
  1008. else
  1009. ButtonLabels := ButtonLabels + ''', ''' + ButtonLabelsArray[I];
  1010. end;
  1011. { get Shield Flag value }
  1012. if rbMB_OK.Checked and rb_IDOK.Checked then ShieldButton := 'IDOK';
  1013. if rbMB_OKCANCEL.Checked and rb_IDOK.Checked then ShieldButton := 'IDOK';
  1014. if rbMB_OKCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := 'IDCANCEL';
  1015. if rbMB_YESNO.Checked and rb_IDYES.Checked then ShieldButton := 'IDYES';
  1016. if rbMB_YESNO.Checked and rb_IDNO.Checked then ShieldButton := 'IDNO';
  1017. if rbMB_YESNOCANCEL.Checked and rb_IDYES.Checked then ShieldButton := 'IDYES';
  1018. if rbMB_YESNOCANCEL.Checked and rb_IDNO.Checked then ShieldButton := 'IDNO';
  1019. if rbMB_YESNOCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := 'IDCANCEL';
  1020. if rbMB_RETRYCANCEL.Checked and rb_IDRETRY.Checked then ShieldButton := 'IDRETRY';
  1021. if rbMB_RETRYCANCEL.Checked and rb_IDCANCEL.Checked then ShieldButton := 'IDCANCEL';
  1022. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDRETRY.Checked then ShieldButton := 'IDRETRY';
  1023. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDABORT.Checked then ShieldButton := 'IDABORT';
  1024. if rbMB_ABORTRETRYIGNORE.Checked and rb_IDIGNORE.Checked then ShieldButton := 'IDIGNORE';
  1025. { Suppressible msg }
  1026. if cb_Suppressible.Checked then ShieldButton := ShieldButton + SuppressibleDefault;
  1027. CaptionOrInstructionAndText := TaskInstructionText.Text + ''', ''' + TaskMessageText.Text;
  1028. end;
  1029. var IDButton, IDButton2, IDButton3: String;
  1030. var Text: String;
  1031. { selected button OK }
  1032. if (cb_IDOK.Checked and not cb_IDCANCEL.Checked) then begin
  1033. IDButton := 'IDOK';
  1034. ButtonCount := 1;
  1035. case ModeMsg of
  1036. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1037. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1038. end;
  1039. end
  1040. { selected button CANCEL }
  1041. else if (cb_IDCANCEL.Checked and not cb_IDOK.Checked and not cb_IDRETRY.Checked and not cb_IDYES.Checked and not cb_IDNO.Checked and not cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1042. IDButton := 'IDCANCEL';
  1043. ButtonCount := 1;
  1044. case ModeMsg of
  1045. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1046. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1047. end;
  1048. end
  1049. { selected button OK and CANCEL }
  1050. else if (cb_IDCANCEL.Checked and cb_IDOK.Checked and not cb_IDRETRY.Checked and not cb_IDYES.Checked and not cb_IDNO.Checked) then begin
  1051. IDButton := 'IDOK';
  1052. IDButton2 := 'IDCANCEL';
  1053. ButtonCount := 2;
  1054. case ModeMsg of
  1055. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1056. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1057. end;
  1058. end
  1059. { selected button YES }
  1060. else if (cb_IDYES.Checked and not cb_IDNO.Checked and not cb_IDCANCEL.Checked) then begin
  1061. IDButton := 'IDYES';
  1062. ButtonCount := 1;
  1063. case ModeMsg of
  1064. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1065. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1066. end;
  1067. end
  1068. { selected button NO }
  1069. else if (cb_IDNO.Checked and not cb_IDYES.Checked and not cb_IDCANCEL.Checked) then begin
  1070. IDButton := 'IDNO';
  1071. ButtonCount := 1;
  1072. case ModeMsg of
  1073. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1074. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1075. end;
  1076. end
  1077. { selected button YES and NO }
  1078. else if (cb_IDYES.Checked and cb_IDNO.Checked and not cb_IDCANCEL.Checked) then begin
  1079. IDButton := 'IDYES';
  1080. IDButton2 := 'IDNO';
  1081. ButtonCount := 2;
  1082. case ModeMsg of
  1083. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1084. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1085. end;
  1086. end
  1087. { selected button YES and CANCEL }
  1088. else if (cb_IDYES.Checked and not cb_IDNO.Checked and cb_IDCANCEL.Checked) then begin
  1089. IDButton := 'IDYES';
  1090. IDButton2 := 'IDCANCEL';
  1091. ButtonCount := 2;
  1092. case ModeMsg of
  1093. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1094. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1095. end;
  1096. end
  1097. { selected button NO and CANCEL }
  1098. else if (cb_IDNO.Checked and not cb_IDYES.Checked and cb_IDCANCEL.Checked) then begin
  1099. IDButton := 'IDNO';
  1100. IDButton2 := 'IDCANCEL';
  1101. ButtonCount := 2;
  1102. case ModeMsg of
  1103. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1104. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1105. end;
  1106. end
  1107. { selected button YES, NO and CANCEL }
  1108. else if (cb_IDYES.Checked and cb_IDNO.Checked and cb_IDCANCEL.Checked) then begin
  1109. IDButton := 'IDYES';
  1110. IDButton2 := 'IDNO';
  1111. IDButton3 := 'IDCANCEL';
  1112. ButtonCount := 3;
  1113. case ModeMsg of
  1114. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, IDButton3);
  1115. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, IDButton3);
  1116. end;
  1117. end
  1118. { selected button RETRY }
  1119. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and not cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1120. IDButton := 'IDRETRY';
  1121. ButtonCount := 1;
  1122. case ModeMsg of
  1123. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1124. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1125. end;
  1126. end
  1127. { selected button RETRY and CANCEL }
  1128. else if (cb_IDRETRY.Checked and cb_IDCANCEL.Checked and not cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1129. IDButton := 'IDRETRY';
  1130. IDButton2 := 'IDCANCEL';
  1131. ButtonCount := 2;
  1132. case ModeMsg of
  1133. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1134. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1135. end;
  1136. end
  1137. { selected button IGNORE }
  1138. else if (cb_IDIGNORE.Checked and not cb_IDCANCEL.Checked and not cb_IDABORT.Checked and not cb_IDRETRY.Checked) then begin
  1139. IDButton := 'IDIGNORE';
  1140. ButtonCount := 1;
  1141. case ModeMsg of
  1142. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1143. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1144. end;
  1145. end
  1146. { selected button ABORT }
  1147. else if (cb_IDABORT.Checked and not cb_IDCANCEL.Checked and not cb_IDRETRY.Checked and not cb_IDIGNORE.Checked) then begin
  1148. IDButton := 'IDABORT';
  1149. ButtonCount := 1;
  1150. case ModeMsg of
  1151. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, '', '');
  1152. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, '', '');
  1153. end;
  1154. end
  1155. { selected button RETRY and IGNORE }
  1156. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and not cb_IDABORT.Checked and cb_IDIGNORE.Checked) then begin
  1157. IDButton := 'IDRETRY';
  1158. IDButton2 := 'IDIGNORE';
  1159. ButtonCount := 2;
  1160. case ModeMsg of
  1161. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1162. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1163. end;
  1164. end
  1165. { selected button RETRY and ABORT }
  1166. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and cb_IDABORT.Checked and not cb_IDIGNORE.Checked) then begin
  1167. IDButton := 'IDRETRY';
  1168. IDButton2 := 'IDABORT';
  1169. ButtonCount := 2;
  1170. case ModeMsg of
  1171. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1172. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1173. end;
  1174. end
  1175. { selected button IGNORE and ABORT }
  1176. else if (not cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and cb_IDABORT.Checked and cb_IDIGNORE.Checked) then begin
  1177. IDButton := 'IDIGNORE';
  1178. IDButton2 := 'IDABORT';
  1179. ButtonCount := 2;
  1180. case ModeMsg of
  1181. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, '');
  1182. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, '');
  1183. end;
  1184. end
  1185. { selected button RETRY, IGNORE and ABORT }
  1186. else if (cb_IDRETRY.Checked and not cb_IDCANCEL.Checked and cb_IDABORT.Checked and cb_IDIGNORE.Checked) then begin
  1187. IDButton := 'IDRETRY';
  1188. IDButton2 := 'IDIGNORE';
  1189. IDButton3 := 'IDABORT';
  1190. ButtonCount := 3;
  1191. case ModeMsg of
  1192. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, IDButton, IDButton2, IDButton3);
  1193. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, IDButton, IDButton2, IDButton3);
  1194. end;
  1195. end
  1196. { no selected buttons }
  1197. else begin
  1198. case ModeMsg of
  1199. 0: Text := TextMsgBox(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, '', '', '');
  1200. 1: Text := TextTaskDialog(ButtonCount, CaptionOrInstructionAndText, Typ, Buttons, ButtonLabels, ShieldButton, '', '', '');
  1201. end;
  1202. end;
  1203. var SL := TStringList.Create;
  1204. try
  1205. SL.Text := Text;
  1206. SL.Insert(0, '// Display a message box');
  1207. for var I := 0 to SL.Count-1 do
  1208. SL[I] := TextTab + SL[I];
  1209. Result := SL.Text;
  1210. finally
  1211. SL.Free;
  1212. end;
  1213. end;
  1214. end.