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.

131 lines
2.5 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. int
  4. MessageBoxFromMessageV(
  5. IN HWND Window,
  6. IN DWORD MessageId,
  7. IN BOOL SystemMessage,
  8. IN LPCTSTR CaptionString,
  9. IN UINT Style,
  10. IN va_list *Args
  11. )
  12. {
  13. TCHAR Caption[512];
  14. TCHAR Buffer[5000];
  15. if((DWORD_PTR)CaptionString > 0xffff) {
  16. //
  17. // It's a string already.
  18. //
  19. lstrcpyn(Caption,CaptionString,sizeof(Caption)/sizeof(TCHAR));
  20. } else {
  21. //
  22. // It's a string id
  23. //
  24. if(!LoadString(hInst,PtrToUlong(CaptionString),Caption,sizeof(Caption)/sizeof(TCHAR))) {
  25. Caption[0] = 0;
  26. }
  27. }
  28. FormatMessage(
  29. SystemMessage ? FORMAT_MESSAGE_FROM_SYSTEM : FORMAT_MESSAGE_FROM_HMODULE,
  30. NULL,
  31. MessageId,
  32. 0,
  33. Buffer,
  34. sizeof(Buffer) / sizeof(TCHAR),
  35. Args
  36. );
  37. return(MessageBox(Window,Buffer,Caption,Style|MB_SETFOREGROUND));
  38. }
  39. int
  40. MessageBoxFromMessage(
  41. IN HWND Window,
  42. IN DWORD MessageId,
  43. IN BOOL SystemMessage,
  44. IN LPCTSTR CaptionString,
  45. IN UINT Style,
  46. ...
  47. )
  48. {
  49. va_list arglist;
  50. int i;
  51. va_start(arglist,Style);
  52. i = MessageBoxFromMessageV(Window,MessageId,SystemMessage,CaptionString,Style,&arglist);
  53. va_end(arglist);
  54. return(i);
  55. }
  56. int
  57. MessageBoxFromMessageAndSystemError(
  58. IN HWND Window,
  59. IN DWORD MessageId,
  60. IN DWORD SystemMessageId,
  61. IN LPCTSTR CaptionString,
  62. IN UINT Style,
  63. ...
  64. )
  65. {
  66. va_list arglist;
  67. TCHAR Caption[512];
  68. TCHAR Buffer1[1024];
  69. TCHAR Buffer2[1024];
  70. int i;
  71. //
  72. // Fetch the non-system part. The arguments are for that part of the
  73. // message -- the system part has no inserts.
  74. //
  75. va_start(arglist,Style);
  76. FormatMessage(
  77. FORMAT_MESSAGE_FROM_HMODULE,
  78. NULL,
  79. MessageId,
  80. 0,
  81. Buffer1,
  82. sizeof(Buffer1) / sizeof(TCHAR),
  83. &arglist
  84. );
  85. va_end(arglist);
  86. //
  87. // Now fetch the system part.
  88. //
  89. FormatMessage(
  90. FORMAT_MESSAGE_FROM_SYSTEM,
  91. NULL,
  92. MessageId,
  93. 0,
  94. Buffer2,
  95. sizeof(Buffer2) / sizeof(TCHAR),
  96. &arglist
  97. );
  98. //
  99. // Now display the message, which is made up of two parts that get
  100. // inserted into MSG_ERROR_WITH_SYSTEM_ERROR.
  101. //
  102. i = MessageBoxFromMessage(
  103. Window,
  104. MSG_ERROR_WITH_SYSTEM_ERROR,
  105. FALSE,
  106. CaptionString,
  107. Style,
  108. Buffer1,
  109. Buffer2
  110. );
  111. return(i);
  112. }