IDE.MsgBoxDesignerForm.pas 49 KB

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