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.

142 lines
3.9 KiB

  1. #include <windows.h>
  2. #include <fontdefs.h>
  3. #include <fvmsg.h>
  4. TCHAR gpszUnknownError[MAX_PATH] = TEXT("Error");
  5. TCHAR gszDots[] = TEXT("...");
  6. /***************************************************************************\
  7. *
  8. * FUNCTION: FmtMessageBox( HWND hwnd, DWORD dwTitleID, UINT fuStyle,
  9. * BOOL fSound, DWORD dwTextID, ... );
  10. *
  11. * PURPOSE: Formats messages with FormatMessage and then displays them
  12. * in a message box
  13. *
  14. *
  15. *
  16. *
  17. * History:
  18. * 22-Apr-1993 JonPa Created it.
  19. \***************************************************************************/
  20. int FmtMessageBox( HWND hwnd, DWORD dwTitleID, LPTSTR pszTitleStr,
  21. UINT fuStyle, BOOL fSound, DWORD dwTextID, ... ) {
  22. LPTSTR pszMsg;
  23. LPTSTR pszTitle;
  24. int idRet;
  25. va_list marker;
  26. va_start( marker, dwTextID );
  27. if(!FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  28. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_MAX_WIDTH_MASK, hInst,
  29. dwTextID, 0, (LPTSTR)&pszMsg, 1, &marker))
  30. pszMsg = gpszUnknownError;
  31. va_end( marker );
  32. GetLastError();
  33. if (dwTitleID != FMB_TTL_ERROR ||
  34. !FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  35. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_MAX_WIDTH_MASK |
  36. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  37. hInst, dwTitleID, 0, (LPTSTR)&pszTitle, 1, (va_list *)&pszTitleStr)) {
  38. pszTitle = NULL;
  39. }
  40. GetLastError();
  41. if (fSound) {
  42. MessageBeep( fuStyle & (MB_ICONASTERISK | MB_ICONEXCLAMATION |
  43. MB_ICONHAND | MB_ICONQUESTION | MB_OK) );
  44. }
  45. if (hwnd == NULL)
  46. hwnd = GetDesktopWindow();
  47. idRet = MessageBox(hwnd, pszMsg, pszTitle, fuStyle);
  48. if (pszTitle != NULL)
  49. FmtFree( pszTitle );
  50. if (pszMsg != gpszUnknownError)
  51. FmtFree( pszMsg );
  52. return idRet;
  53. }
  54. /***************************************************************************\
  55. *
  56. * FUNCTION: FmtSprintf( DWORD id, ... );
  57. *
  58. * PURPOSE: sprintf but it gets the pattern string from the message rc.
  59. *
  60. * History:
  61. * 03-May-1993 JonPa Created it.
  62. \***************************************************************************/
  63. LPTSTR FmtSprintf( DWORD id, ... ) {
  64. LPTSTR pszMsg;
  65. va_list marker;
  66. va_start( marker, id );
  67. if(!FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  68. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_MAX_WIDTH_MASK, hInst,
  69. id, 0, (LPTSTR)&pszMsg, 1, &marker)) {
  70. GetLastError();
  71. pszMsg = gszDots;
  72. }
  73. va_end( marker );
  74. return pszMsg;
  75. }
  76. /***************************************************************************\
  77. *
  78. * FUNCTION: PVOID AllocMem( DWORD cb );
  79. *
  80. * PURPOSE: allocates memory, checking for errors
  81. *
  82. * Do not call this function until after LoadFontFile() has been called
  83. * since this function will try and remove the font.
  84. *
  85. * History:
  86. * 22-Apr-1993 JonPa Wrote it.
  87. \***************************************************************************/
  88. PVOID AllocMem( DWORD cb ) {
  89. PVOID pv = (PVOID)LocalAlloc(LPTR, cb);
  90. if (pv == NULL) {
  91. FmtMessageBox( ghwndFrame, FMB_TTL_ERROR, NULL, MB_OK | MB_ICONSTOP,
  92. TRUE, MSG_OUTOFMEM );
  93. RemoveFontResource( gszFontPath );
  94. ExitProcess(2);
  95. }
  96. return pv;
  97. }
  98. #ifdef FV_DEBUG
  99. /***************************************************************************\
  100. *
  101. * FUNCTION: FmtSprintf( DWORD id, ... );
  102. *
  103. * PURPOSE: sprintf but it gets the pattern string from the message rc.
  104. *
  105. * History:
  106. * 03-May-1993 JonPa Created it.
  107. \***************************************************************************/
  108. void Dprintf( LPTSTR pszFmt, ... ) {
  109. TCHAR szBuffer[256];
  110. va_list marker;
  111. va_start( marker, pszFmt );
  112. StringCchVPrintf( szBuffer, ARRAYSIZE(szBuffer), pszFmt, marker );
  113. OutputDebugString(szBuffer);
  114. va_end( marker );
  115. }
  116. #endif