Leaked source code of windows server 2003
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.

162 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: msgpopup.cpp
  8. //
  9. // This file contains MessageBox helper functions.
  10. //
  11. //--------------------------------------------------------------------------
  12. #include "pch.h"
  13. #pragma hdrstop
  14. /*******************************************************************
  15. NAME: MsgPopup
  16. SYNOPSIS: Displays a message to the user
  17. ENTRY: hwnd - Owner window handle
  18. pszMsgFmt - Main message text
  19. pszTitle - MessageBox title
  20. uType - MessageBox flags
  21. hInstance - Module to load strings from. Only required if
  22. pszMsgFmt or pszTitle is a string resource ID.
  23. Optional format insert parameters.
  24. EXIT:
  25. RETURNS: MessageBox result
  26. NOTES: Either of the string parameters may be string resource ID's.
  27. HISTORY:
  28. JeffreyS 11-Jun-1997 Created
  29. ********************************************************************/
  30. int
  31. WINAPIV
  32. MsgPopup(HWND hwnd,
  33. LPCTSTR pszMsgFmt,
  34. LPCTSTR pszTitle,
  35. UINT uType,
  36. HINSTANCE hInstance,
  37. ...)
  38. {
  39. int nResult;
  40. LPTSTR szMsg = NULL;
  41. LPTSTR szTitle = NULL;
  42. DWORD dwFormatResult;
  43. va_list args;
  44. if (pszMsgFmt == NULL)
  45. return -1;
  46. //
  47. // Insert arguments into the format string
  48. //
  49. va_start(args, hInstance);
  50. if (IS_INTRESOURCE(pszMsgFmt))
  51. dwFormatResult = vFormatStringID(&szMsg, hInstance, (UINT)((ULONG_PTR)pszMsgFmt), &args);
  52. else
  53. dwFormatResult = vFormatString(&szMsg, pszMsgFmt, &args);
  54. va_end(args);
  55. if (!dwFormatResult)
  56. return -1;
  57. //
  58. // Load the caption if necessary
  59. //
  60. if (pszTitle && IS_INTRESOURCE(pszTitle))
  61. {
  62. if (LoadStringAlloc(&szTitle, hInstance, (UINT)((ULONG_PTR)pszTitle)))
  63. pszTitle = szTitle;
  64. else
  65. pszTitle = NULL;
  66. }
  67. //
  68. // Display message box
  69. //
  70. nResult = MessageBox(hwnd, szMsg, pszTitle, uType);
  71. LocalFreeString(&szMsg);
  72. LocalFreeString(&szTitle);
  73. return nResult;
  74. }
  75. /*******************************************************************
  76. NAME: SysMsgPopup
  77. SYNOPSIS: Displays a message to the user using a system error
  78. message as an insert.
  79. ENTRY: hwnd - Owner window handle
  80. pszMsg - Main message text
  81. pszTitle - MessageBox title
  82. uType - MessageBox flags
  83. hInstance - Module to load strings from. Only required if
  84. pszMsg or pszTitle is a string resource ID.
  85. dwErrorID - System defined error code (Insert 1)
  86. pszInsert2 - Optional string to be inserted into pszMsg
  87. EXIT:
  88. RETURNS: MessageBox result
  89. NOTES: Any of the string parameters may be string resource ID's.
  90. HISTORY:
  91. JeffreyS 11-Jun-1997 Created
  92. ********************************************************************/
  93. int
  94. WINAPI
  95. SysMsgPopup(HWND hwnd,
  96. LPCTSTR pszMsg,
  97. LPCTSTR pszTitle,
  98. UINT uType,
  99. HINSTANCE hInstance,
  100. DWORD dwErrorID,
  101. LPCTSTR pszInsert2)
  102. {
  103. int nResult;
  104. LPTSTR szInsert2 = NULL;
  105. LPTSTR szErrorText = NULL;
  106. //
  107. // Load the 2nd insert string if necessary
  108. //
  109. if (pszInsert2 && IS_INTRESOURCE(pszInsert2))
  110. {
  111. if (LoadStringAlloc(&szInsert2, hInstance, (UINT)((ULONG_PTR)pszInsert2)))
  112. pszInsert2 = szInsert2;
  113. else
  114. pszInsert2 = NULL;
  115. }
  116. //
  117. // Get the error message string
  118. //
  119. if (dwErrorID)
  120. {
  121. GetSystemErrorText(&szErrorText, dwErrorID);
  122. }
  123. nResult = MsgPopup(hwnd, pszMsg, pszTitle, uType, hInstance, szErrorText, pszInsert2);
  124. LocalFreeString(&szInsert2);
  125. LocalFreeString(&szErrorText);
  126. return nResult;
  127. }