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.

174 lines
3.5 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: DMGHSZ.C
  3. *
  4. * This module contains functions used for HSZ control.
  5. *
  6. * Created: 8/2/88 sanfords, Microsoft
  7. * Modified: 6/5/90 Rich Gartland, Aldus (Win 3.0)
  8. *
  9. * Copyright (c) 1988, 1989 Microsoft Corporation
  10. * Copyright (c) 1990 Aldus Corporation
  11. \***************************************************************************/
  12. #include "ddemlp.h"
  13. ATOM FindAddHszHelper(LPSTR psz, BOOL fAdd);
  14. /*********************** HSZ management functions *************************\
  15. * An HSZ is an atom with a NULL tacked onto it in the HIWORD
  16. * of the HSZ.
  17. *
  18. * WINDOWS 3.0 IMPLEMENTATION NOTE:
  19. * Since under Windows there is only the local atom table or the (single)
  20. * global atom table (and we need to use the global table to work right),
  21. * we always have an atom table index of 0. When we run out of atom table
  22. * space, future hsz adds return failure.
  23. *
  24. * History:
  25. * Created 9/12/89 Sanfords
  26. \***************************************************************************/
  27. BOOL FreeHsz(a)
  28. ATOM a;
  29. {
  30. if (!a)
  31. return(TRUE);
  32. #ifdef DEBUG
  33. cAtoms--;
  34. #endif
  35. MONHSZ(a, MH_INTDELETE, GetCurrentTask());
  36. if (GlobalDeleteAtom(a)) {
  37. DEBUGBREAK();
  38. return(FALSE);
  39. }
  40. return(TRUE);
  41. }
  42. BOOL IncHszCount(a)
  43. ATOM a;
  44. {
  45. char aChars[255];
  46. if (a == NULL)
  47. return(TRUE);
  48. #ifdef DEBUG
  49. cAtoms++;
  50. #endif
  51. MONHSZ(a, MH_INTKEEP, GetCurrentTask());
  52. if (GlobalGetAtomName(a, (LPSTR)aChars, 255))
  53. return(GlobalAddAtom((LPSTR)aChars));
  54. else {
  55. AssertF(FALSE, "Cant increment atom");
  56. return(FALSE);
  57. }
  58. }
  59. /***************************** Private Function ****************************\
  60. * Returns the length of the hsz given without NULL terminator.
  61. * Wild HSZs have a length of 0.
  62. *
  63. * History:
  64. * Created 9/12/89 Sanfords
  65. \***************************************************************************/
  66. WORD QueryHszLength(hsz)
  67. HSZ hsz;
  68. {
  69. WORD cb;
  70. char aChars[255];
  71. if (LOWORD(hsz) == 0L)
  72. return(0);
  73. if (!(cb = GlobalGetAtomName(LOWORD(hsz), (LPSTR)aChars, 255))) {
  74. AssertF(FALSE, "Cant get atom length");
  75. return(0);
  76. }
  77. if (HIWORD(hsz))
  78. cb += 7;
  79. return(cb);
  80. }
  81. WORD QueryHszName(hsz, psz, cchMax)
  82. HSZ hsz;
  83. LPSTR psz;
  84. WORD cchMax;
  85. {
  86. register WORD cb;
  87. if (LOWORD(hsz) == 0) {
  88. if (cchMax)
  89. *psz = '\0';
  90. return(0);
  91. }
  92. cb = GlobalGetAtomName(LOWORD(hsz), psz, cchMax);
  93. if (cb && HIWORD(hsz) && (cb < cchMax - 7)) {
  94. wsprintf(&psz[cb], ":(%04x)", HIWORD(hsz));
  95. cb += 7;
  96. }
  97. return cb;
  98. }
  99. /***************************** Private Function ****************************\
  100. * This finds the hsz for psz depending on fAdd.
  101. *
  102. * History:
  103. * Created 9/12/89 Sanfords
  104. \***************************************************************************/
  105. ATOM FindAddHsz(psz, fAdd)
  106. LPSTR psz;
  107. BOOL fAdd;
  108. {
  109. if (psz == NULL || *psz == '\0')
  110. return(0L);
  111. return(FindAddHszHelper(psz, fAdd));
  112. }
  113. ATOM FindAddHszHelper(psz, fAdd)
  114. LPSTR psz;
  115. BOOL fAdd;
  116. {
  117. ATOM atom;
  118. atom = fAdd ? GlobalAddAtom(psz) : GlobalFindAtom(psz);
  119. if (fAdd) {
  120. #ifdef DEBUG
  121. cAtoms++;
  122. #endif
  123. MONHSZ(atom, MH_INTCREATE, GetCurrentTask());
  124. }
  125. return(atom);
  126. }
  127. HSZ MakeInstAppName(
  128. ATOM a,
  129. HWND hwndFrame)
  130. {
  131. // make upper half of HSZ be HWND FRAME for now.
  132. IncHszCount(a);
  133. return((HSZ)MAKELONG(a, hwndFrame));
  134. }