Leaked source code of windows server 2003
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.

394 lines
8.8 KiB

  1. /* File: D:\WACKER\tdll\globals.c (Created: 26-Nov-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 7 $
  7. * $Date: 4/16/02 2:38p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include "stdtyp.h"
  12. #include "globals.h"
  13. #include "assert.h"
  14. #include <term\res.h>
  15. #include "htchar.h"
  16. static TCHAR szHelpFileName[FNAME_LEN];
  17. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  18. * FUNCTION:
  19. * glblQueryHelpFileName
  20. *
  21. * DESCRIPTION:
  22. * Return the name of the help file.
  23. *
  24. * RETURNS:
  25. * LPTSTR - pointer to the help file name.
  26. */
  27. LPTSTR glblQueryHelpFileName(void)
  28. {
  29. return ((LPTSTR)szHelpFileName);
  30. }
  31. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  32. * FUNCTION:
  33. * glblSetHelpFileName
  34. *
  35. * DESCRIPTION:
  36. * Load the help file name from the registry or resources.
  37. *
  38. * RETURNS:
  39. */
  40. void glblSetHelpFileName(void)
  41. {
  42. DWORD dwSize = sizeof(szHelpFileName);
  43. HKEY hKey;
  44. TCHAR_Fill(szHelpFileName, TEXT('\0'), dwSize/sizeof(TCHAR));
  45. if (LoadString(glblQueryDllHinst(), IDS_GNRL_HELPFILE, szHelpFileName,
  46. dwSize / sizeof(TCHAR)) == 0)
  47. {
  48. StrCharCopyN(szHelpFileName, TEXT("HYPERTRM.HLP"),
  49. dwSize / sizeof(TCHAR));
  50. }
  51. if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  52. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\HyperTrm.exe"),
  53. 0,
  54. KEY_QUERY_VALUE,
  55. &hKey) == ERROR_SUCCESS)
  56. {
  57. TCHAR_Fill(szHelpFileName, TEXT('\0'), dwSize/sizeof(TCHAR));
  58. if (RegQueryValueEx(hKey, TEXT("HelpFileName"), 0, 0,
  59. szHelpFileName, &dwSize) != ERROR_SUCCESS)
  60. {
  61. if (LoadString(glblQueryDllHinst(), IDS_GNRL_HELPFILE, szHelpFileName,
  62. dwSize / sizeof(TCHAR)) == 0)
  63. {
  64. StrCharCopyN(szHelpFileName, TEXT("HYPERTRM.HLP"),
  65. dwSize / sizeof(TCHAR));
  66. }
  67. }
  68. RegCloseKey(hKey);
  69. }
  70. return;
  71. }
  72. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  73. * Set and Query the program's instance handle. Only the Query function
  74. * is exported.
  75. */
  76. static HINSTANCE hInstance;
  77. HINSTANCE glblQueryHinst(void)
  78. {
  79. return hInstance;
  80. }
  81. void glblSetHinst(const HINSTANCE hInst)
  82. {
  83. hInstance = hInst;
  84. }
  85. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  86. * Set and Query the DLL's instance handle. Only the Query function is
  87. * exported.
  88. */
  89. static HINSTANCE hDllInstance;
  90. HINSTANCE glblQueryDllHinst(void)
  91. {
  92. return hDllInstance;
  93. }
  94. void glblSetDllHinst(const HINSTANCE hInst)
  95. {
  96. hDllInstance = hInst;
  97. }
  98. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  99. * Set and Query the program's accelerator handle.
  100. */
  101. static HACCEL hAccel;
  102. void glblSetAccelHdl(const HACCEL hAccelerator)
  103. {
  104. hAccel = hAccelerator;
  105. }
  106. HACCEL glblQueryAccelHdl(void)
  107. {
  108. return hAccel;
  109. }
  110. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  111. * Set and Query the program's frame window handle. Currently the frame
  112. * window is also the session window, but don't count on it necessarily
  113. * staying that way. Upper wacker may change. I strongly discourge the
  114. * use of the glbl????HwndFrame functions. Why are they here? The message
  115. * loop (ie. TranslateAccelerator()) needs the handle of the window that
  116. * owns the menus in order to process accelerators. - mrw
  117. */
  118. static HWND hwndFrame;
  119. void glblSetHwndFrame(const HWND hwnd)
  120. {
  121. hwndFrame = hwnd;
  122. }
  123. HWND glblQueryHwndFrame(void)
  124. {
  125. return hwndFrame;
  126. }
  127. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  128. * DESCRIPTION:
  129. * This block of global data is used to manage modeless dialogs. It consists
  130. * of two items. The first is a counter to determin how many modeless dialogs
  131. * are currently registered. The second is an array of window handles that
  132. * are for the modeless dialogs. At the present time the array is staticly
  133. * allocated but could be made dynamic if it ever becomes a problem.
  134. *
  135. */
  136. static int glblModelessDlgCount = 0;
  137. static HWND glblModelessDlgArray[64]; /* Think that's enough ? */
  138. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  139. * FUNCTION:
  140. * glblAddModelessDlgHwnd
  141. *
  142. * DESCRIPTION:
  143. * This function adds a window handle to our list of modeless dialog windows.
  144. *
  145. * PARAMETERS:
  146. * hwnd -- the window handle
  147. *
  148. * RETURNS:
  149. * ZERO if everything is OK, otherwise an error code of some sort.
  150. *
  151. */
  152. int glblAddModelessDlgHwnd(const HWND hwnd)
  153. {
  154. int nIndx;
  155. if (!IsWindow(hwnd))
  156. {
  157. assert(FALSE);
  158. return 1;
  159. }
  160. if (glblModelessDlgCount >= 62)
  161. {
  162. assert(FALSE);
  163. return 2;
  164. }
  165. for (nIndx = 0; nIndx < glblModelessDlgCount; nIndx += 1)
  166. {
  167. if (hwnd == glblModelessDlgArray[nIndx])
  168. {
  169. assert(FALSE);
  170. return 3;
  171. }
  172. }
  173. /*
  174. * "It must be safe", he said foolishly.
  175. */
  176. glblModelessDlgArray[glblModelessDlgCount++] = hwnd;
  177. return 0;
  178. }
  179. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  180. * FUNCTION:
  181. * glblDeleteModelessDlgHwnd
  182. *
  183. * DESCRIPTION:
  184. * This function takes a modeless dialog box window handle out of the list
  185. * that the previous function put it into.
  186. *
  187. * PARAMETERS:
  188. * hwnd -- the very window handle
  189. *
  190. * RETURNS:
  191. * ZERO if everything is OK, otherwise an error code of some sort.
  192. *
  193. */
  194. int glblDeleteModelessDlgHwnd(const HWND hwnd)
  195. {
  196. int nIndx;
  197. if (glblModelessDlgCount == 0)
  198. {
  199. assert(FALSE);
  200. return 2;
  201. }
  202. for (nIndx = 0; nIndx < glblModelessDlgCount; nIndx += 1)
  203. {
  204. if (hwnd == glblModelessDlgArray[nIndx])
  205. {
  206. /* remove and adjust the array */
  207. while (nIndx < 62)
  208. {
  209. glblModelessDlgArray[nIndx] = glblModelessDlgArray[nIndx + 1];
  210. nIndx += 1;
  211. }
  212. glblModelessDlgCount -= 1;
  213. return 0;
  214. }
  215. }
  216. /* Never found the puppy */
  217. assert(FALSE);
  218. return 3;
  219. }
  220. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  221. * FUNCTION:
  222. * CheckModelessMessage
  223. *
  224. * DESCRIPTION:
  225. * This function is called to check and see if there are any modeless dialog
  226. * boxes awaiting input and feeds them the messages.
  227. *
  228. * PARAMETERS:
  229. * pmsg -- pointer to the message structure
  230. *
  231. * RETURNS:
  232. * TRUE if it has already processed the message, otherwise FALSE
  233. *
  234. */
  235. int CheckModelessMessage(MSG *pmsg)
  236. {
  237. int nIndx;
  238. /* Avoid unnecessary effort */
  239. if (glblModelessDlgCount == 0)
  240. return FALSE;
  241. for (nIndx = 0; nIndx < glblModelessDlgCount; nIndx += 1)
  242. {
  243. #if 0
  244. #if !defined(NDEBUG)
  245. assert(IsWindow(glblModelessDlgArray[nIndx]));
  246. #endif
  247. #endif
  248. if (IsDialogMessage(glblModelessDlgArray[nIndx], pmsg))
  249. return TRUE;
  250. }
  251. return FALSE;
  252. }
  253. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  254. * It is possible, under some conditions, that the program will shut down
  255. * because of an error. Under some of these conditions, there may not be
  256. * a valid session handle, so it becomes necessary to store the status of
  257. * the shutdown as a static variable.
  258. */
  259. static int nShutdownStatus;
  260. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  261. * FUNCTION:
  262. * glblQueryProgramStatus
  263. *
  264. * DESCRIPTION:
  265. * Returns the startup/shutdown status of the program.
  266. *
  267. * ARGUMENTS:
  268. * None.
  269. *
  270. * RETURNS:
  271. * ZERO if everything is OK, otherwise a shutdown status code.
  272. *
  273. */
  274. int glblQueryProgramStatus()
  275. {
  276. return nShutdownStatus;
  277. }
  278. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  279. * FUNCTION:
  280. * glblSetProgramStatus
  281. *
  282. * DESCRIPTION:
  283. * Changes the startup/shutdown status of the program.
  284. *
  285. * ARGUMENTS:
  286. * nStatus -- the new status.
  287. *
  288. * RETURNS:
  289. * The previous status.
  290. *
  291. */
  292. int glblSetProgramStatus(int nStatus)
  293. {
  294. int nRet;
  295. nRet = nShutdownStatus;
  296. nShutdownStatus = nStatus;
  297. return nShutdownStatus;
  298. }
  299. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  300. * Banner is displayed at program startup
  301. */
  302. static HWND hwndBanner;
  303. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  304. * FUNCTION:
  305. * glblQueryHwndBanner
  306. *
  307. * DESCRIPTION:
  308. * Returns window handle of banner
  309. *
  310. * ARGUMENTS:
  311. * void
  312. *
  313. * RETURNS:
  314. * HWND
  315. *
  316. */
  317. HWND glblQueryHwndBanner(void)
  318. {
  319. return hwndBanner;
  320. }
  321. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  322. * FUNCTION:
  323. * glblSetHwndBanner
  324. *
  325. * DESCRIPTION:
  326. * Sets the value of hwndBanner for later reference
  327. *
  328. * ARGUMENTS:
  329. * hwnd - window handle of banner
  330. *
  331. * RETURNS:
  332. * void
  333. *
  334. */
  335. void glblSetHwndBanner(const HWND hwnd)
  336. {
  337. hwndBanner = hwnd;
  338. return;
  339. }