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.

167 lines
5.5 KiB

  1. /*-----------------------------------------------------------------------------+
  2. | ERRORBOX.C |
  3. | |
  4. | Routines for dealing with Resource-string based messages |
  5. | |
  6. | (C) Copyright Microsoft Corporation 1991. All rights reserved. |
  7. | |
  8. | Revision History |
  9. | 15-Oct-1992 LaurieGr (AKA LKG) Ported to WIN32 / WIN16 common code |
  10. | |
  11. +-----------------------------------------------------------------------------*/
  12. #include <windows.h>
  13. #include <mmsystem.h>
  14. #include <stdio.h> // needed for va_list stuff
  15. #include <stdarg.h> // needed for va_list stuff
  16. #define STRSAFE_NO_DEPRECATE
  17. #include <strsafe.h>
  18. #include "mplayer.h"
  19. /*
  20. * @doc INTERNAL
  21. *
  22. * @func short | ErrorResBox | This function displays a message box using
  23. * program resource error strings.
  24. *
  25. * @parm HWND | hwnd | Specifies the message box parent window.
  26. *
  27. * @parm HANDLE | hInst | Specifies the instance handle of the module
  28. * that contains the resource strings specified by <p idAppName> and
  29. * <p idErrorStr>. If this value is NULL, the instance handle is
  30. * obtained from <p hwnd> (in which case <p hwnd> may not be NULL).
  31. *
  32. * @parm WORD | flags | Specifies message box types controlling the
  33. * message box appearance. All message box types valid for <f MessageBox> are
  34. * valid.
  35. *
  36. * @parm WORD | idAppName | Specifies the resource ID of a string that
  37. * is to be used as the message box caption.
  38. *
  39. * @parm WORD | idErrorStr | Specifies the resource ID of a error
  40. * message format string. This string is of the style passed to
  41. * <f wsprintf>, containing the standard C argument formatting
  42. * characters. Any procedure parameters following <p idErrorStr> will
  43. * be taken as arguments for this format string.
  44. *
  45. * @parm arguments | [ arguments, ... ] | Specifies additional
  46. * arguments corresponding to the format specification given by
  47. * <p idErrorStr>. All string arguments must be FAR pointers.
  48. *
  49. * @rdesc Returns the result of the call to <f MessageBox>. If an
  50. * error occurs, returns zero.
  51. *
  52. * @comm This is a variable arguments function, the parameters after
  53. * <p idErrorStr> being taken for arguments to the <f printf> format
  54. * string specified by <p idErrorStr>. The string resources specified
  55. * by <p idAppName> and <p idErrorStr> must be loadable using the
  56. * instance handle <p hInst>. If the strings cannot be
  57. * loaded, or <p hwnd> is not valid, the function will fail and return
  58. * zero.
  59. *
  60. */
  61. #define STRING_SIZE 256
  62. void PositionMsgID(PTSTR szMsg, HANDLE hInst, UINT iErr)
  63. {
  64. PTSTR psz;
  65. TCHAR szMplayerMsgID[16];
  66. TCHAR szTmp[STRING_SIZE];
  67. TCHAR szFmt[STRING_SIZE];
  68. if (!LoadString(hInst, IDS_MSGFORMAT, szFmt, STRING_SIZE))
  69. return;
  70. if (!iErr)
  71. {
  72. for (psz = szMsg; psz && *psz && *psz != TEXT(' '); psz++)
  73. ;
  74. if (*psz == TEXT(' '))
  75. {
  76. *psz++ = TEXT('\0');
  77. wsprintf((LPTSTR)szTmp, (LPTSTR)szFmt, (LPTSTR)psz, (LPTSTR)szMsg);
  78. }
  79. else
  80. return;
  81. }
  82. else
  83. {
  84. wsprintf((LPTSTR)szMplayerMsgID, TEXT("MPLAYER%3.3u"), iErr);
  85. wsprintf((LPTSTR)szTmp, (LPTSTR)szFmt, (LPTSTR)szMsg, (LPTSTR)szMplayerMsgID);
  86. }
  87. lstrcpy((LPTSTR)szMsg, (LPTSTR)szTmp);
  88. }
  89. short FAR cdecl ErrorResBox(HWND hwnd, HANDLE hInst, UINT flags,
  90. UINT idAppName, UINT idErrorStr, ...)
  91. {
  92. TCHAR sz[STRING_SIZE];
  93. TCHAR szFmt[STRING_SIZE];
  94. UINT w;
  95. va_list va;
  96. /* We're going away... bringing a box up will crash */
  97. if (gfInClose)
  98. return 0;
  99. if (hInst == NULL) {
  100. if (hwnd == NULL)
  101. hInst = ghInst;
  102. else
  103. hInst = GETHWNDINSTANCE(hwnd);
  104. }
  105. w = 0;
  106. if (!sz || !szFmt)
  107. goto ExitError; // no mem, get out
  108. if (!LOADSTRINGFROM(hInst, idErrorStr, szFmt))
  109. goto ExitError;
  110. va_start(va, idErrorStr);
  111. StringCchVPrintf(sz, STRING_SIZE, szFmt, va);
  112. va_end(va);
  113. if (flags == MB_ERROR)
  114. if (idErrorStr == IDS_DEVICEERROR)
  115. PositionMsgID(sz, hInst, 0);
  116. else
  117. PositionMsgID(sz, hInst, idErrorStr);
  118. if (!LOADSTRINGFROM(hInst, idAppName, szFmt))
  119. goto ExitError;
  120. if (gfErrorBox) {
  121. DPF("*** \n");
  122. DPF("*** NESTED ERROR: '%"DTS"'\n", (LPTSTR)sz);
  123. DPF("*** \n");
  124. return 0;
  125. }
  126. // BlockServer();
  127. gfErrorBox++;
  128. /* Don't own this error box if we are not visible... eg. PowerPoint will
  129. hard crash. */
  130. if (!IsWindowVisible(ghwndApp) || gfPlayingInPlace) {
  131. DPF("Bring error up as SYSTEMMODAL because PowerPig crashes in slide show\n");
  132. hwnd = NULL;
  133. flags |= MB_SYSTEMMODAL;
  134. }
  135. w = MessageBox(hwnd, sz, szFmt,
  136. flags);
  137. gfErrorBox--;
  138. // UnblockServer();
  139. if (gfErrorDeath) {
  140. DPF("*** Error box is gone ok to destroy window\n");
  141. PostMessage(ghwndApp, gfErrorDeath, 0, 0);
  142. }
  143. ExitError:
  144. return (short)w;
  145. }
  146.