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.

293 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxstrt.cpp
  5. Abstract:
  6. This file implements string table functions.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Darwin Ouyang (t-darouy) 30-Sept-1997
  11. Snagged and Modified from:
  12. Wesley Witt (wesw) 17-Feb-1996
  13. --*/
  14. #include "stdafx.h"
  15. #include "resource.h"
  16. #include "faxstrt.h"
  17. #include "strings.h"
  18. #pragma hdrstop
  19. //===========================//===========================//===========================//===========================
  20. //===========================//===========================//===========================//===========================
  21. #define CountStringTable ( sizeof(StringTable) / sizeof(STRING_TABLE) )
  22. extern CComModule _Module;
  23. ////////////////////////////////////////////////////////////////////////////////////////////////////
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////
  26. ////////////////////////////////////////////////////////////////////////////////////////////////////
  27. //
  28. //
  29. // Constructor and destructor
  30. //
  31. //
  32. CStringTable::CStringTable(
  33. HMODULE thisModule )
  34. /*++
  35. Routine Description:
  36. Constructor
  37. Arguments:
  38. thisModule - instance handle
  39. Return Value:
  40. None.
  41. --*/
  42. {
  43. DWORD i;
  44. TCHAR Buffer[256];
  45. assert( thisModule != NULL );
  46. gInstance = thisModule;
  47. for( i=0; i<CountStringTable; i++ ) {
  48. if( StringTable[i].ResourceId != 0xFFFF ) {
  49. if( LoadString( thisModule, StringTable[i].ResourceId, Buffer, sizeof(Buffer)/sizeof(TCHAR)) != NULL ) {
  50. // if we find the string, allocate an array for the string
  51. // StringSize is a macro found in faxutil.h
  52. StringTable[i].String = new TCHAR[ StringSize(Buffer) ];
  53. if( StringTable[i].String == NULL ) {
  54. // if we can't alloc the memory, just put empty into the table.
  55. StringTable[i].String = TEXT("");
  56. } else {
  57. // otherwise copy it into the table
  58. _tcscpy( StringTable[i].String, Buffer );
  59. }
  60. } else {
  61. // if we don't find the string, put empty into the table
  62. StringTable[i].String = TEXT("");
  63. }
  64. }
  65. }
  66. DebugPrint(( TEXT( "CStringTable Created" ) ));
  67. }
  68. CStringTable::~CStringTable()
  69. /*++
  70. Routine Description:
  71. Destructor
  72. Arguments:
  73. None.
  74. Return Value:
  75. None.
  76. --*/
  77. {
  78. DWORD i;
  79. for( i=0; i<CountStringTable; i++ ) {
  80. if( StringTable[i].String != NULL ) {
  81. delete StringTable[i].String;
  82. }
  83. }
  84. DebugPrint(( TEXT( "CStringTable Destroyed" ) ));
  85. }
  86. const LPTSTR
  87. CStringTable::GetString(
  88. IN DWORD ResourceId )
  89. /*++
  90. Routine Description:
  91. Gets a const string pointer given a resource ID.
  92. Arguments:
  93. pParent - pointer to parent node, in this case unused
  94. pCompData - pointer to IComponentData implementation for snapin global data
  95. Return Value:
  96. a const LPTSTR pointing to the string requested. Do not free this string.
  97. --*/
  98. {
  99. DWORD i;
  100. for(i=0; i<CountStringTable; i++) {
  101. if(StringTable[i].ResourceId == ResourceId) {
  102. return StringTable[i].String;
  103. }
  104. }
  105. // oh oh we didn't find the string!!
  106. assert( 0 );
  107. return NULL;
  108. }
  109. int
  110. CStringTable::PopUpMsg(
  111. IN HWND hwnd,
  112. IN DWORD ResourceId,
  113. IN BOOL Error,
  114. IN DWORD Type )
  115. /*++
  116. Routine Description:
  117. Does a quick popup given a resource ID
  118. Arguments:
  119. hwnd - the parent of the message box
  120. resourceId - the id of the string resource you want in the dialog
  121. error - make this an error or warning
  122. type - flags to affect the appearance of the message box
  123. Return Value:
  124. look up MessageBox in the API.
  125. --*/
  126. {
  127. return MessageBox(
  128. hwnd,
  129. GetString( ResourceId ),
  130. GetString( Error ? IDS_ERR_TITLE : IDS_WRN_TITLE ),
  131. MB_SETFOREGROUND | (Error ? MB_ICONEXCLAMATION : MB_ICONINFORMATION) | (Type == 0 ? MB_OK : Type)
  132. );
  133. }
  134. // **************************************
  135. int
  136. CStringTable::PopUpMsgFmt(
  137. IN HWND hwnd,
  138. IN DWORD ResourceId,
  139. IN BOOL Error,
  140. IN DWORD Type,
  141. ... )
  142. /*++
  143. Routine Description:
  144. Does a quick popup given a resource ID, and some formatting flags
  145. Arguments:
  146. hwnd - the parent of the message box
  147. resourceId - the id of the string resource you want in the dialog
  148. error - make this an error or warning
  149. type - flags to affect the appearance of the message box
  150. ... - strings to sub into the resource string.
  151. Return Value:
  152. look up MessageBox in the API.
  153. --*/
  154. {
  155. TCHAR buf[1024];
  156. va_list arg_ptr;
  157. va_start(arg_ptr, Type);
  158. _vsntprintf( buf, sizeof(buf), GetString( ResourceId ), arg_ptr );
  159. return MessageBox(
  160. hwnd,
  161. buf,
  162. GetString( Error ? IDS_ERR_TITLE : IDS_WRN_TITLE ),
  163. MB_SETFOREGROUND | (Error ? MB_ICONEXCLAMATION : MB_ICONINFORMATION) | (Type == 0 ? MB_OK : Type)
  164. );
  165. }
  166. VOID
  167. CStringTable::SystemErrorMsg(
  168. DWORD ErrorCode)
  169. /*++
  170. Routine Description:
  171. Does a quick popup with the system error code
  172. Arguments:
  173. ErrorCode - the error code returned from GetLastError.
  174. Return Value:
  175. None.
  176. --*/
  177. {
  178. LPTSTR lpMsgBuf;
  179. FormatMessage(
  180. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  181. NULL,
  182. ErrorCode,
  183. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  184. (LPTSTR) &lpMsgBuf,
  185. 0,
  186. NULL
  187. );
  188. MessageBox( NULL,
  189. lpMsgBuf,
  190. GetString( IDS_ERR_TITLE ),
  191. MB_SETFOREGROUND | MB_ICONEXCLAMATION | MB_OK );
  192. LocalFree( lpMsgBuf );
  193. }
  194. HMODULE
  195. CStringTable::GetInstance()
  196. /*++
  197. Routine Description:
  198. Returns the instance.
  199. Arguments:
  200. None.
  201. Return Value:
  202. The instance handle.
  203. --*/
  204. {
  205. return gInstance;
  206. }