UtilsWin.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. {
  2. This Delphi unit is part of TIGCC.
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. }
  16. unit UtilsWin;
  17. interface
  18. uses
  19. Windows;
  20. type
  21. TMessageButtons = (mbOK, mbOKCancel, mbYesNo, mbYesNoCancel, mbRetryCancel, mbAbortRetryIgnore);
  22. TMessageIcon = (miNone, miAsterisk, miInformation, miQuestion, miExclamation, miWarning, miHand, miStop, miError);
  23. TMessageModalState = (msDefault, msApplModal, msSystemModal, msTaskModal);
  24. TDefaultMessageType = (mtDefault, mtInformation, mtQuestion, mtWarning, mtProgramError, mtDeviceError);
  25. function ShowMessageBox(const Content, Title: string; Buttons: TMessageButtons = mbOK; Icon: TMessageIcon = miNone; ModalState: TMessageModalState = msDefault; DisplayHelp: Boolean = False; DefaultButton: Integer = 0; Flags: Integer = 0): Integer;
  26. function ShowDefaultMessageBox(const Content, Title: string; MessageType: TDefaultMessageType = mtDefault; Critical: Boolean = False; DisplayHelp: Boolean = False; DefaultButton: Integer = 0): Integer;
  27. function CompressMessageFlags(Buttons: TMessageButtons; Icon: TMessageIcon; ModalState: TMessageModalState; DisplayHelp: Boolean; DefaultButton: Integer): Integer;
  28. implementation
  29. function ShowMessageBox;
  30. begin
  31. Result := MessageBox (GetActiveWindow, PChar (Content), PChar (Title), Flags or CompressMessageFlags (Buttons, Icon, ModalState, DisplayHelp, DefaultButton));
  32. end;
  33. function ShowDefaultMessageBox;
  34. var
  35. Buttons: TMessageButtons;
  36. Icon: TMessageIcon;
  37. begin
  38. case MessageType of
  39. mtInformation: begin
  40. if Critical then
  41. Buttons := mbOKCancel
  42. else
  43. Buttons := mbOK;
  44. Icon := miInformation;
  45. end;
  46. mtQuestion: begin
  47. if Critical then
  48. Buttons := mbYesNoCancel
  49. else
  50. Buttons := mbYesNo;
  51. Icon := miQuestion;
  52. end;
  53. mtWarning: begin
  54. if Critical then
  55. Buttons := mbOKCancel
  56. else
  57. Buttons := mbOK;
  58. Icon := miWarning;
  59. end;
  60. mtProgramError: begin
  61. if Critical then
  62. Buttons := mbOKCancel
  63. else
  64. Buttons := mbOK;
  65. Icon := miError;
  66. end;
  67. mtDeviceError: begin
  68. if Critical then
  69. Buttons := mbRetryCancel
  70. else
  71. Buttons := mbAbortRetryIgnore;
  72. Icon := miError;
  73. end;
  74. else begin
  75. if Critical then
  76. Buttons := mbOKCancel
  77. else
  78. Buttons := mbOK;
  79. Icon := miNone;
  80. end;
  81. end;
  82. Result := ShowMessageBox (Content, Title, Buttons, Icon, msDefault, DisplayHelp, DefaultButton, 0);
  83. end;
  84. function CompressMessageFlags;
  85. begin
  86. case Buttons of
  87. mbOK: Result := mb_OK;
  88. mbOKCancel: Result := mb_OKCancel;
  89. mbYesNo: Result := mb_YesNo;
  90. mbYesNoCancel: Result := mb_YesNoCancel;
  91. mbRetryCancel: Result := mb_RetryCancel;
  92. mbAbortRetryIgnore: Result := mb_AbortRetryIgnore;
  93. else Result := 0;
  94. end;
  95. case Icon of
  96. miAsterisk: Result := Result or mb_IconAsterisk;
  97. miInformation: Result := Result or mb_IconInformation;
  98. miQuestion: Result := Result or mb_IconQuestion;
  99. miExclamation: Result := Result or mb_IconExclamation;
  100. miWarning: Result := Result or mb_IconWarning;
  101. miHand: Result := Result or mb_IconHand;
  102. miStop: Result := Result or mb_IconStop;
  103. miError: Result := Result or mb_IconError;
  104. end;
  105. case ModalState of
  106. msApplModal: Result := Result or mb_ApplModal;
  107. msSystemModal: Result := Result or mb_SystemModal;
  108. msTaskModal: Result := Result or mb_TaskModal;
  109. end;
  110. if DisplayHelp then
  111. Result := Result or mb_Help;
  112. case DefaultButton of
  113. 1: Result := Result or mb_DefButton1;
  114. 2: Result := Result or mb_DefButton2;
  115. 3: Result := Result or mb_DefButton3;
  116. 4: Result := Result or mb_DefButton4;
  117. end;
  118. end;
  119. end.