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.

236 lines
4.0 KiB

  1. #include "faxrtp.h"
  2. #pragma hdrstop
  3. typedef struct _STRING_TABLE {
  4. DWORD ResourceId;
  5. DWORD InternalId;
  6. LPCTSTR String;
  7. } STRING_TABLE, *PSTRING_TABLE;
  8. static STRING_TABLE StringTable[] =
  9. {
  10. { IDS_NO_MAPI_LOGON, IDS_NO_MAPI_LOGON, NULL },
  11. { IDS_SERVICE_NAME, IDS_SERVICE_NAME, NULL },
  12. { IDS_DEFAULT, IDS_DEFAULT, NULL }
  13. };
  14. #define CountStringTable (sizeof(StringTable)/sizeof(STRING_TABLE))
  15. LPTSTR
  16. GetLastErrorText(
  17. DWORD ErrorCode
  18. )
  19. /*++
  20. Routine Description:
  21. Gets a string for a given WIN32 error code.
  22. Arguments:
  23. ErrorCode - WIN32 error code.
  24. Return Value:
  25. Pointer to a string representing the ErrorCode.
  26. --*/
  27. {
  28. static TCHAR ErrorBuf[256];
  29. DWORD Count;
  30. Count = FormatMessage(
  31. FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
  32. NULL,
  33. ErrorCode,
  34. LANG_NEUTRAL,
  35. ErrorBuf,
  36. sizeof(ErrorBuf),
  37. NULL
  38. );
  39. if (Count) {
  40. if (ErrorBuf[Count-1] == TEXT('\n')) {
  41. ErrorBuf[Count-1] = 0;
  42. }
  43. if ((Count>1) && (ErrorBuf[Count-2] == TEXT('\r'))) {
  44. ErrorBuf[Count-2] = 0;
  45. }
  46. }
  47. return ErrorBuf;
  48. }
  49. VOID
  50. InitializeStringTable(
  51. VOID
  52. )
  53. {
  54. DWORD i;
  55. HINSTANCE hInstance;
  56. TCHAR Buffer[256];
  57. hInstance = GetModuleHandle(NULL);
  58. for (i=0; i<CountStringTable; i++) {
  59. if (LoadString(
  60. hInstance,
  61. StringTable[i].ResourceId,
  62. Buffer,
  63. sizeof(Buffer)/sizeof(TCHAR)
  64. )) {
  65. StringTable[i].String = (LPCTSTR) MemAlloc( StringSize( Buffer ) );
  66. if (!StringTable[i].String) {
  67. StringTable[i].String = TEXT("");
  68. } else {
  69. _tcscpy( (LPTSTR)StringTable[i].String, Buffer );
  70. }
  71. } else {
  72. StringTable[i].String = TEXT("");
  73. }
  74. }
  75. }
  76. LPCTSTR
  77. GetString(
  78. DWORD InternalId
  79. )
  80. /*++
  81. Routine Description:
  82. Loads a resource string and returns a pointer to the string.
  83. The caller must free the memory.
  84. Arguments:
  85. ResourceId - resource string id
  86. Return Value:
  87. pointer to the string
  88. --*/
  89. {
  90. DWORD i;
  91. for (i=0; i<CountStringTable; i++) {
  92. if (StringTable[i].InternalId == InternalId) {
  93. return StringTable[i].String;
  94. }
  95. }
  96. return NULL;
  97. }
  98. DWORD
  99. MessageBoxThread(
  100. IN PMESSAGEBOX_DATA MsgBox
  101. )
  102. {
  103. DWORD Answer = (DWORD) MessageBox(
  104. NULL,
  105. MsgBox->Text,
  106. GetString( IDS_SERVICE_NAME ),
  107. MsgBox->Type | MB_SERVICE_NOTIFICATION
  108. );
  109. if (MsgBox->Response) {
  110. *MsgBox->Response = Answer;
  111. }
  112. MemFree( (LPBYTE) MsgBox->Text );
  113. MemFree( MsgBox );
  114. return 0;
  115. }
  116. BOOL
  117. ServiceMessageBox(
  118. IN LPCTSTR MsgString,
  119. IN DWORD Type,
  120. IN BOOL UseThread,
  121. IN LPDWORD Response,
  122. IN ...
  123. )
  124. {
  125. #define BUFSIZE 1024
  126. PMESSAGEBOX_DATA MsgBox;
  127. DWORD ThreadId;
  128. HANDLE hThread;
  129. DWORD Answer;
  130. LPTSTR buf;
  131. va_list arg_ptr;
  132. buf = (LPTSTR) MemAlloc( BUFSIZE );
  133. if (!buf) {
  134. return FALSE;
  135. }
  136. va_start( arg_ptr, Response );
  137. _vsntprintf( buf, BUFSIZE, MsgString, arg_ptr );
  138. va_end( arg_ptr );
  139. if (UseThread) {
  140. MsgBox = (PMESSAGEBOX_DATA) MemAlloc( sizeof(MESSAGEBOX_DATA) );
  141. if (!MsgBox) {
  142. return FALSE;
  143. }
  144. MsgBox->Text = buf;
  145. MsgBox->Response = Response;
  146. MsgBox->Type = Type;
  147. hThread = CreateThread(
  148. NULL,
  149. 0,
  150. (LPTHREAD_START_ROUTINE) MessageBoxThread,
  151. (LPVOID) MsgBox,
  152. 0,
  153. &ThreadId
  154. );
  155. if (!hThread) {
  156. return FALSE;
  157. }
  158. return TRUE;
  159. }
  160. Answer = MessageBox(
  161. NULL,
  162. buf,
  163. GetString( IDS_SERVICE_NAME ),
  164. Type | MB_SERVICE_NOTIFICATION
  165. );
  166. if (Response) {
  167. *Response = Answer;
  168. }
  169. MemFree( buf );
  170. return TRUE;
  171. }