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.

126 lines
3.7 KiB

  1. /* (C) Copyright Microsoft Corporation 1991-1994. All Rights Reserved */
  2. /*******************************************************************
  3. *
  4. * ERRORBOX.C
  5. *
  6. * Routines for dealing with Resource-string based message
  7. * boxes.
  8. *
  9. *******************************************************************/
  10. /* Revision History.
  11. * 4/2/91 LaurieGr (AKA LKG) Ported to WIN32 / WIN16 common code
  12. * 22/Feb/94 LaurieGr Merged Motown and Daytona versions
  13. */
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <mmsystem.h>
  17. #include <mmreg.h>
  18. #include "soundrec.h"
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21. /*
  22. * @doc INTERNAL
  23. *
  24. * @func short | ErrorResBox | This function displays a message box using
  25. * program resource error strings.
  26. *
  27. * @parm HWND | hwnd | Specifies the message box parent window.
  28. *
  29. * @parm HANDLE | hInst | Specifies the instance handle of the module
  30. * that contains the resource strings specified by <p idAppName> and
  31. * <p idErrorStr>. If this value is NULL, the instance handle is
  32. * obtained from <p hwnd> (in which case <p hwnd> may not be NULL).
  33. *
  34. * @parm UINT | flags | Specifies message box types controlling the
  35. * message box appearance. All message box types valid for <f MessageBox> are
  36. * valid.
  37. *
  38. * @parm UINT | idAppName | Specifies the resource ID of a string that
  39. * is to be used as the message box caption.
  40. *
  41. * @parm UINT | idErrorStr | Specifies the resource ID of a error
  42. * message format string. This string is of the style passed to
  43. * <f wsprintf>, containing the standard C argument formatting
  44. * characters. Any procedure parameters following <p idErrorStr> will
  45. * be taken as arguments for this format string.
  46. *
  47. * @parm arguments | [ arguments, ... ] | Specifies additional
  48. * arguments corresponding to the format specification given by
  49. * <p idErrorStr>. All string arguments must be FAR pointers.
  50. *
  51. * @rdesc Returns the result of the call to <f MessageBox>. If an
  52. * error occurs, returns zero.
  53. *
  54. * @comm This is a variable arguments function, the parameters after
  55. * <p idErrorStr> being taken for arguments to the <f printf> format
  56. * string specified by <p idErrorStr>. The string resources specified
  57. * by <p idAppName> and <p idErrorStr> must be loadable using the
  58. * instance handle <p hInst>. If the strings cannot be
  59. * loaded, or <p hwnd> is not valid, the function will fail and return
  60. * zero.
  61. *
  62. */
  63. #define STRING_SIZE 1024
  64. short FAR _cdecl
  65. ErrorResBox (
  66. HWND hwnd,
  67. HANDLE hInst,
  68. UINT flags,
  69. UINT idAppName,
  70. UINT idErrorStr,
  71. ... )
  72. {
  73. PTSTR sz = NULL;
  74. PTSTR szFmt = NULL;
  75. UINT w;
  76. va_list va; // got to do this for DEC Alpha platform
  77. // where parameter lists are different.
  78. if (hInst == NULL) {
  79. if (hwnd == NULL) {
  80. MessageBeep(0);
  81. return FALSE;
  82. }
  83. hInst = (HANDLE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
  84. }
  85. w = 0;
  86. sz = (PTSTR) GlobalAllocPtr(GHND, STRING_SIZE*sizeof(TCHAR));
  87. szFmt = (PTSTR) GlobalAllocPtr(GHND, STRING_SIZE*sizeof(TCHAR));
  88. if (!sz || !szFmt)
  89. goto ExitError; // no mem, get out
  90. if (!LoadString(hInst, idErrorStr, szFmt, STRING_SIZE))
  91. goto ExitError;
  92. va_start(va, idErrorStr);
  93. wvsprintf(sz, szFmt, va);
  94. va_end(va);
  95. if (!LoadString(hInst, idAppName, szFmt, STRING_SIZE))
  96. goto ExitError;
  97. if (gfErrorBox) {
  98. #if DBG
  99. TCHAR szTxt[256];
  100. wsprintf(szTxt, TEXT("!ERROR '%s'\r\n"), sz);
  101. OutputDebugString(szTxt);
  102. #endif
  103. return 0;
  104. }
  105. else {
  106. gfErrorBox++;
  107. w = MessageBox(hwnd, sz, szFmt, flags);
  108. gfErrorBox--;
  109. }
  110. ExitError:
  111. if (sz) GlobalFreePtr(sz);
  112. if (szFmt) GlobalFreePtr(szFmt);
  113. return (short)w;
  114. }