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.

331 lines
9.0 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*******************************************************************************
  3. *
  4. * common.c
  5. *
  6. * WINUTILS common C helper functions
  7. *
  8. * copyright notice: Copyright 1995, Citrix Systems Inc.
  9. *
  10. * $Author: butchd $ Butch Davis
  11. *
  12. * $Log: N:\NT\PRIVATE\UTILS\CITRIX\WINUTILS\COMMON\VCS\COMMON.C $
  13. *
  14. * Rev 1.3 16 Nov 1995 17:16:18 butchd
  15. * update
  16. *
  17. * Rev 1.2 24 Mar 1995 17:23:58 butchd
  18. * Added WINUTILS global instance handle
  19. *
  20. * Rev 1.1 20 Mar 1995 16:06:34 butchd
  21. * Segregated code for WIN32 & WIN16 library builds
  22. *
  23. * Rev 1.0 28 Feb 1995 17:37:12 butchd
  24. * Initial revision.
  25. *
  26. *******************************************************************************/
  27. /*
  28. * include files
  29. */
  30. #include <windows.h>
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include "common.h"
  34. /*
  35. * Common WINUTIL external variables
  36. */
  37. extern LPCTSTR WinUtilsAppName;
  38. extern HWND WinUtilsAppWindow;
  39. extern HINSTANCE WinUtilsAppInstance;
  40. ////////////////////////////////////////////////////////////////////////////////
  41. // common helper functions
  42. /*******************************************************************************
  43. *
  44. * ErrorMessage - WINUTILS helper function
  45. *
  46. * Display an error message with variable arguments - main application
  47. * window is owner of message box.
  48. *
  49. * ENTRY:
  50. * nErrorResourceID (input)
  51. * Resource ID of the format string to use in the error message.
  52. * ... (input)
  53. * Optional additional arguments to be used with format string.
  54. *
  55. * EXIT:
  56. *
  57. ******************************************************************************/
  58. void
  59. ErrorMessage( int nErrorResourceID, ...)
  60. {
  61. TCHAR sz1[256], sz2[1024];
  62. int length;
  63. va_list args;
  64. va_start( args, nErrorResourceID );
  65. length = LoadString(WinUtilsAppInstance, nErrorResourceID, sz1, 256);
  66. wvsprintf( sz2, sz1, args );
  67. lstrcpy(sz1, WinUtilsAppName);
  68. lstrcat(sz1, TEXT(" ERROR"));
  69. MessageBox( WinUtilsAppWindow,
  70. sz2, sz1, MB_OK | MB_ICONEXCLAMATION );
  71. va_end(args);
  72. } // end ErrorMessage
  73. /*******************************************************************************
  74. *
  75. * ErrorMessageStr - WINUTILS helper function
  76. *
  77. * Load the specified error resource format string and format an error
  78. * message string into the specified output buffer.
  79. *
  80. * ENTRY:
  81. * pErrorString (output)
  82. * Buffer to place formatted error string into.
  83. * nErrorStringLen (input)
  84. * Specifies maximum number of characters, including the terminator,
  85. * that can be written to pErrorString.
  86. * nErrorResourceID (input)
  87. * Resource ID of the format string to use in the error message.
  88. * ... (input)
  89. * Optional additional arguments to be used with format string.
  90. *
  91. * EXIT:
  92. *
  93. ******************************************************************************/
  94. void
  95. ErrorMessageStr( LPTSTR pErrorString,
  96. int nErrorStringLen,
  97. int nErrorResourceID, ...)
  98. {
  99. TCHAR sz1[256], sz2[1024];
  100. int length;
  101. va_list args;
  102. va_start( args, nErrorResourceID );
  103. length = LoadString(WinUtilsAppInstance, nErrorResourceID, sz1, 256);
  104. wvsprintf( sz2, sz1, args );
  105. lstrncpy(pErrorString, sz2, nErrorStringLen);
  106. pErrorString[nErrorStringLen-1] = TEXT('\0');
  107. va_end(args);
  108. } // end ErrorMessage
  109. /*******************************************************************************
  110. *
  111. * ErrorMessageWndA - WINUTILS helper function (ANSI version)
  112. *
  113. * Display an error message with variable arguments - caller specifies the
  114. * owner of message box.
  115. *
  116. * ENTRY:
  117. * hWnd (input)
  118. * Window handle of owner window for the message box. If this is
  119. * NULL, the main application window will be the owner.
  120. * nErrorResourceID (input)
  121. * Resource ID of the format string to use in the error message.
  122. * ... (input)
  123. * Optional additional arguments to be used with format string.
  124. *
  125. * EXIT:
  126. *
  127. ******************************************************************************/
  128. void
  129. #ifdef WIN16
  130. #define LoadStringA LoadString
  131. #define wvsprintfA wvsprintf
  132. #define lstrcpyA lstrcpy
  133. #define lstrcatA lstrcat
  134. #define MessageBoxA MessageBox
  135. ErrorMessageWnd(
  136. #else
  137. ErrorMessageWndA(
  138. #endif
  139. HWND hWnd,
  140. int nErrorResourceID, ...)
  141. {
  142. char sz1[256], sz2[1024];
  143. int length;
  144. va_list args;
  145. va_start( args, nErrorResourceID );
  146. length = LoadStringA(WinUtilsAppInstance, nErrorResourceID, sz1, 256);
  147. wvsprintfA( sz2, sz1, args );
  148. #ifdef UNICODE
  149. wcstombs(sz1, WinUtilsAppName, sizeof(sz1));
  150. #else
  151. lstrcpyA(sz1, WinUtilsAppName);
  152. #endif
  153. lstrcatA(sz1, " ERROR");
  154. MessageBoxA(
  155. hWnd ? hWnd : WinUtilsAppWindow,
  156. sz2, sz1, MB_OK | MB_ICONEXCLAMATION );
  157. va_end(args);
  158. } // end ErrorMessageWndA
  159. #ifndef WIN16
  160. /*******************************************************************************
  161. *
  162. * ErrorMessageWndW - WINUTILS helper function (UNICODE version)
  163. *
  164. * Display an error message with variable arguments - caller specifies the
  165. * owner of message box.
  166. *
  167. * ENTRY:
  168. * hWnd (input)
  169. * Window handle of owner window for the message box. If this is
  170. * NULL, the main application window will be the owner.
  171. * nErrorResourceID (input)
  172. * Resource ID of the format string to use in the error message.
  173. * ... (input)
  174. * Optional additional arguments to be used with format string.
  175. *
  176. * EXIT:
  177. *
  178. ******************************************************************************/
  179. void
  180. ErrorMessageWndW( HWND hWnd,
  181. int nErrorResourceID, ...)
  182. {
  183. WCHAR sz1[256], sz2[1024];
  184. int length;
  185. va_list args;
  186. va_start( args, nErrorResourceID );
  187. length = LoadStringW(WinUtilsAppInstance, nErrorResourceID, sz1, 256);
  188. wvsprintfW( sz2, sz1, args );
  189. #ifndef UNICODE
  190. mbstowcs(sz1, WinUtilsAppName, lstrlenA(WinUtilsAppName)+1);
  191. #else
  192. lstrcpyW(sz1, WinUtilsAppName);
  193. #endif
  194. lstrcatW(sz1, L" ERROR");
  195. MessageBoxW( hWnd ? hWnd : WinUtilsAppWindow,
  196. sz2, sz1, MB_OK | MB_ICONEXCLAMATION );
  197. va_end(args);
  198. } // end ErrorMessageWndW
  199. #endif // WIN16
  200. /*******************************************************************************
  201. *
  202. * QuestionMessage - WINUTILS helper function
  203. *
  204. * Display a 'question' message with variable arguments and return the
  205. * user's response - main application window is owner of message box.
  206. *
  207. * ENTRY:
  208. * nType (input)
  209. * Message box 'type' flags to determine the apperance and function
  210. * of the generated MessageBox.
  211. * nErrorResourceID (input)
  212. * Resource ID of the format string to use in the error message.
  213. * ... (input)
  214. * Optional additional arguments to be used with format string.
  215. *
  216. * EXIT:
  217. * (int) Returns the user response from the MessageBox function.
  218. *
  219. ******************************************************************************/
  220. int
  221. QuestionMessage( UINT nType,
  222. int nQuestionResourceID, ...)
  223. {
  224. TCHAR sz1[256], sz2[1024];
  225. int reply, length;
  226. va_list args;
  227. va_start( args, nQuestionResourceID );
  228. length = LoadString(WinUtilsAppInstance, nQuestionResourceID, sz1, 256);
  229. wvsprintf( sz2, sz1, args );
  230. reply = MessageBox( WinUtilsAppWindow,
  231. sz2, WinUtilsAppName, nType );
  232. va_end(args);
  233. return(reply);
  234. } // end QuestionMessage
  235. /*******************************************************************************
  236. *
  237. * QuestionMessageWnd - WINUTILS helper function
  238. *
  239. * Display a 'question' message with variable arguments and return the
  240. * user's response - caller specifies the owner of message box.
  241. *
  242. * ENTRY:
  243. * hWnd (input)
  244. * Window handle of owner window for the message box. If this is
  245. * NULL, the main application window will be the owner.
  246. * nType (input)
  247. * Message box 'type' flags to determine the apperance and function
  248. * of the generated MessageBox.
  249. * nErrorResourceID (input)
  250. * Resource ID of the format string to use in the error message.
  251. * ... (input)
  252. * Optional additional arguments to be used with format string.
  253. *
  254. * EXIT:
  255. * (int) Returns the user response from the MessageBox function.
  256. *
  257. ******************************************************************************/
  258. int
  259. QuestionMessageWnd( HWND hWnd,
  260. UINT nType,
  261. int nQuestionResourceID, ...)
  262. {
  263. TCHAR sz1[256], sz2[1024];
  264. int reply, length;
  265. va_list args;
  266. va_start( args, nQuestionResourceID );
  267. length = LoadString(WinUtilsAppInstance, nQuestionResourceID, sz1, 256);
  268. wvsprintf( sz2, sz1, args );
  269. reply = MessageBox( hWnd ? hWnd : WinUtilsAppWindow,
  270. sz2, WinUtilsAppName, nType );
  271. va_end(args);
  272. return(reply);
  273. } // end QuestionMessageWnd