Win32OSDisplay.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // Win32OSDisplay.cpp //////////////////////////////////////
  24. // John McDonald, December 2002
  25. ////////////////////////////////////////////////////////////
  26. #define WIN32_LEAN_AND_MEAN
  27. #include <windows.h>
  28. #include "Common/OSDisplay.h"
  29. #include "Common/SubsystemInterface.h"
  30. #include "Common/STLTypeDefs.h"
  31. #include "Common/AsciiString.h"
  32. #include "Common/SystemInfo.h"
  33. #include "Common/UnicodeString.h"
  34. #include "GameClient/GameText.h"
  35. #ifdef _INTERNAL
  36. //#pragma optimize("", off)
  37. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  38. #endif
  39. extern HWND ApplicationHWnd;
  40. //-------------------------------------------------------------------------------------------------
  41. static void RTSFlagsToOSFlags(UnsignedInt buttonFlags, UnsignedInt otherFlags, UnsignedInt& outWindowsFlags)
  42. {
  43. outWindowsFlags = 0;
  44. if (BitTest(buttonFlags, OSDBT_OK)) {
  45. outWindowsFlags |= MB_OK;
  46. }
  47. if (BitTest(buttonFlags, OSDBT_CANCEL)) {
  48. outWindowsFlags |= MB_OKCANCEL;
  49. }
  50. //-----------------------------------------------------------------------------------------------
  51. if (BitTest(otherFlags, OSDOF_SYSTEMMODAL)) {
  52. outWindowsFlags |= MB_SYSTEMMODAL;
  53. }
  54. if (BitTest(otherFlags, OSDOF_APPLICATIONMODAL)) {
  55. outWindowsFlags |= MB_APPLMODAL;
  56. }
  57. if (BitTest(otherFlags, OSDOF_TASKMODAL)) {
  58. outWindowsFlags |= MB_TASKMODAL;
  59. }
  60. if (BitTest(otherFlags, OSDOF_EXCLAMATIONICON)) {
  61. outWindowsFlags |= MB_ICONEXCLAMATION;
  62. }
  63. if (BitTest(otherFlags, OSDOF_INFORMATIONICON)) {
  64. outWindowsFlags |= MB_ICONINFORMATION;
  65. }
  66. if (BitTest(otherFlags, OSDOF_ERRORICON)) {
  67. outWindowsFlags |= MB_ICONERROR;
  68. }
  69. if (BitTest(otherFlags, OSDOF_STOPICON)) {
  70. outWindowsFlags |= MB_ICONSTOP;
  71. }
  72. }
  73. //-------------------------------------------------------------------------------------------------
  74. OSDisplayButtonType OSDisplayWarningBox(AsciiString p, AsciiString m, UnsignedInt buttonFlags, UnsignedInt otherFlags)
  75. {
  76. if (!TheGameText) {
  77. return OSDBT_ERROR;
  78. }
  79. UnicodeString promptStr = TheGameText->fetch(p);
  80. UnicodeString mesgStr = TheGameText->fetch(m);
  81. UnsignedInt windowsOptionsFlags = 0;
  82. RTSFlagsToOSFlags(buttonFlags, otherFlags, windowsOptionsFlags);
  83. // @todo Make this return more than just ok/cancel - jkmcd
  84. // (we need a function to translate back the other way.)
  85. Int returnResult = 0;
  86. if (TheSystemIsUnicode)
  87. {
  88. returnResult = ::MessageBoxW(NULL, mesgStr.str(), promptStr.str(), windowsOptionsFlags);
  89. }
  90. else
  91. {
  92. // However, if we're using the default version of the message box, we need to
  93. // translate the string into an AsciiString
  94. AsciiString promptA, mesgA;
  95. promptA.translate(promptStr);
  96. mesgA.translate(mesgStr);
  97. //Make sure main window is not TOP_MOST
  98. ::SetWindowPos(ApplicationHWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  99. returnResult = ::MessageBoxA(NULL, mesgA.str(), promptA.str(), windowsOptionsFlags);
  100. }
  101. if (returnResult == IDOK) {
  102. return OSDBT_OK;
  103. }
  104. return OSDBT_CANCEL;
  105. }