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.

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