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.

151 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. macros.c
  5. Abstract:
  6. This module contains the global macros
  7. Author:
  8. Steven Kehrli (steveke) 11/15/1997
  9. --*/
  10. #ifndef _MACROS_C
  11. #define _MACROS_C
  12. #include <stdio.h>
  13. // szDefaultCaption is the default caption
  14. LPWSTR szDefaultCaption = NULL;
  15. VOID
  16. SetDefaultCaptionMacro(
  17. LPWSTR szCaption
  18. )
  19. /*++
  20. Routine Description:
  21. Sets the default caption
  22. Arguments:
  23. szCaption - default caption
  24. Return Value:
  25. None
  26. --*/
  27. {
  28. DWORD cb;
  29. if (szCaption) {
  30. // Determine the memory required by szDefaultCaption
  31. cb = (lstrlen(szCaption) + 1) * sizeof(WCHAR);
  32. // Allocate the memory for szDefaultCaption
  33. szDefaultCaption = MemAllocMacro(cb);
  34. // Set szDefaultCaption
  35. lstrcpy(szDefaultCaption, szCaption);
  36. }
  37. }
  38. VOID
  39. DebugMacro(
  40. LPWSTR szFormatString,
  41. ...
  42. )
  43. /*++
  44. Routine Description:
  45. Displays a string in the debugger
  46. Arguments:
  47. szFormatString - pointer to the string
  48. Return Value:
  49. None
  50. --*/
  51. {
  52. va_list varg_ptr;
  53. SYSTEMTIME SystemTime;
  54. // szDebugBuffer is the debug string
  55. WCHAR szDebugBuffer[1024];
  56. DWORD cb;
  57. // Initialize the buffer
  58. ZeroMemory(szDebugBuffer, sizeof(szDebugBuffer));
  59. // Get the current time
  60. GetLocalTime(&SystemTime);
  61. if (szDefaultCaption) {
  62. wsprintf(szDebugBuffer, L"%s - %02d.%02d.%04d@%02d:%02d:%02d.%03d:\n", szDefaultCaption, SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds);
  63. }
  64. else {
  65. wsprintf(szDebugBuffer, L"%02d.%02d.%04d@%02d:%02d:%02d.%03d:\n", SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds);
  66. }
  67. cb = lstrlen(szDebugBuffer);
  68. va_start(varg_ptr, szFormatString);
  69. _vsnwprintf(&szDebugBuffer[cb], sizeof(szDebugBuffer) - cb, szFormatString, varg_ptr);
  70. OutputDebugString(szDebugBuffer);
  71. }
  72. VOID
  73. MessageBoxMacro(
  74. HWND hWndParent,
  75. UINT uID,
  76. UINT uType,
  77. ...
  78. )
  79. /*++
  80. Routine Description:
  81. Displays a pop-up
  82. Arguments:
  83. hWndParent - handle of parent window
  84. uID - id of resource string
  85. uType - type of message box
  86. Return Value:
  87. None
  88. --*/
  89. {
  90. va_list varg_ptr;
  91. // szFormatString is the string determined from the id of the resource string, used as format control
  92. WCHAR szFormatString[MAX_STRINGLEN];
  93. // szTest is the string displayed in the pop-up
  94. WCHAR szText[MAX_STRINGLEN * 2];
  95. // Initialize the buffers
  96. ZeroMemory(szFormatString, sizeof(szFormatString));
  97. ZeroMemory(szText, sizeof(szText));
  98. // Load the resource string
  99. LoadString(g_hInstance, uID, szFormatString, MAX_STRINGLEN);
  100. va_start(varg_ptr, uType);
  101. _vsnwprintf(szText, MAX_STRINGLEN * 2, szFormatString, varg_ptr);
  102. DebugMacro(L"%s\n", szText);
  103. // Display the pop-up
  104. MessageBox(hWndParent, szText, szDefaultCaption, MB_OK | uType);
  105. }
  106. #endif