Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: message.cxx
  7. //
  8. // Contents: Helper functions for popup message boxes.
  9. //
  10. // Classes:
  11. //
  12. // Functions: MessageBoxFromSringIds
  13. //
  14. // History: 6-24-94 stevebl Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include "message.h"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: MessageBoxFromStringIds
  22. //
  23. // Synopsis: Displays a simple message box taking its text from a string
  24. // table instead of from user allocated strings.
  25. //
  26. // Arguments: [hwndOwner] - window handle for the message box's owner
  27. // [hinst] - instance associated with the string table
  28. // [idText] - string id for the box's text string
  29. // [idTitle] - string id for the box's title string
  30. // [fuStyle] - style of message box
  31. // (see Windows function MessageBox for styles)
  32. //
  33. // Returns: result from MessageBox
  34. //
  35. // History: 6-24-94 stevebl Created
  36. //
  37. // Notes: Each string is limited to MAX_STRING_LENGTH characters.
  38. //
  39. //----------------------------------------------------------------------------
  40. int MessageBoxFromStringIds(
  41. const HWND hwndOwner,
  42. const HINSTANCE hinst,
  43. const UINT idText,
  44. const UINT idTitle,
  45. const UINT fuStyle)
  46. {
  47. int iReturn = 0;
  48. TCHAR szTitle[MAX_STRING_LENGTH];
  49. TCHAR szText[MAX_STRING_LENGTH];
  50. if (LoadString(hinst, idTitle, szTitle, MAX_STRING_LENGTH))
  51. {
  52. if (LoadString(hinst, idText, szText, MAX_STRING_LENGTH))
  53. {
  54. iReturn = MessageBox(
  55. hwndOwner,
  56. szText,
  57. szTitle,
  58. fuStyle);
  59. }
  60. }
  61. return(iReturn);
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Function: MessageBoxFromStringIdsAndArgs
  66. //
  67. // Synopsis: Creates a message box from a pair of string IDs similar
  68. // to MessageBoxFromStringIds. The principle difference
  69. // is that idFormat is an ID for a string which is a printf
  70. // format string suitable for passing to wsprintf.
  71. // The variable argument list is combined with the format
  72. // string to create the text of the message box.
  73. //
  74. // Arguments: [hwndOwner] - window handle for the message box's owner
  75. // [hinst] - instance associated with the string table
  76. // [idFormat] - string id for the format of the box's text
  77. // [idTitle] - string id for the box's title string
  78. // [fuStyle] - style of the dialog box
  79. // [...] - argument list for text format string
  80. //
  81. // Returns: result from MessageBox
  82. //
  83. // History: 6-24-94 stevebl Created
  84. //
  85. // Notes: Neither the composed text string nor the title must be
  86. // longer than MAX_STRING_LENGTH characters.
  87. //
  88. //----------------------------------------------------------------------------
  89. int MessageBoxFromStringIdsAndArgs(
  90. const HWND hwndOwner,
  91. const HINSTANCE hinst,
  92. const UINT idFormat,
  93. const UINT idTitle,
  94. const UINT fuStyle, ...)
  95. {
  96. int iReturn = 0;
  97. va_list arglist;
  98. va_start(arglist, fuStyle);
  99. TCHAR szTitle[MAX_STRING_LENGTH];
  100. TCHAR szText[MAX_STRING_LENGTH];
  101. TCHAR szFormat[MAX_STRING_LENGTH];
  102. if (LoadString(hinst, idTitle, szTitle, MAX_STRING_LENGTH))
  103. {
  104. if (LoadString(hinst, idFormat, szFormat, MAX_STRING_LENGTH))
  105. {
  106. wvsprintf(szText, szFormat, arglist);
  107. iReturn = MessageBox(
  108. hwndOwner,
  109. szText,
  110. szTitle,
  111. fuStyle);
  112. }
  113. }
  114. return(iReturn);
  115. }