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.

202 lines
5.0 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // Microsoft Internet Explorer //
  3. // Copyright(c) Microsoft Corp., 1995-1996 //
  4. //////////////////////////////////////////////////////////////////////
  5. //
  6. // REGUTIL.C - registry functions common between MSHTML and INETCPL.
  7. //
  8. // HISTORY:
  9. //
  10. // 8/7/96 t-gpease created.
  11. //
  12. #include "inetcplp.h"
  13. //
  14. // Definintions
  15. //
  16. #define SMALLBUFFER 64
  17. //
  18. // Procedures
  19. //
  20. const TCHAR g_cszYes[] = TEXT("yes");
  21. const TCHAR g_cszNo[] = TEXT("no");
  22. // Conveters and int into a string... ONLY BYTE VALUES!!
  23. TCHAR *MyIntToStr(TCHAR *pBuf, BYTE iVal)
  24. {
  25. int i, t;
  26. ASSERT(iVal < 1000);
  27. i=0;
  28. if (t = iVal/100)
  29. {
  30. pBuf[i] = L'0' + t;
  31. i++;
  32. }
  33. if ((t = (iVal % 100) / 10) || (i!=0))
  34. {
  35. pBuf[i] = L'0' + t;
  36. i++;
  37. }
  38. pBuf[i] = L'0' + iVal % 10;
  39. i++;
  40. pBuf[i] = L'\0';
  41. return pBuf;
  42. }
  43. // Read the registry for a string (REG_SZ) of comma separated RGB values
  44. COLORREF RegGetColorRefString( HUSKEY huskey, LPTSTR RegValue, COLORREF Value)
  45. {
  46. TCHAR SmallBuf[SMALLBUFFER];
  47. TCHAR *pBuf;
  48. DWORD cb;
  49. int iRed, iGreen, iBlue;
  50. cb = ARRAYSIZE(SmallBuf);
  51. if (SHRegQueryUSValue(huskey,
  52. RegValue,
  53. NULL,
  54. (LPBYTE)&SmallBuf,
  55. &cb,
  56. FALSE,
  57. NULL,
  58. NULL) == ERROR_SUCCESS)
  59. {
  60. iRed = StrToInt(SmallBuf);
  61. pBuf = SmallBuf;
  62. // find the next comma
  63. while(pBuf && *pBuf && *pBuf!=L',')
  64. pBuf++;
  65. // if valid and not NULL...
  66. if (pBuf && *pBuf)
  67. pBuf++; // increment
  68. iGreen = StrToInt(pBuf);
  69. // find the next comma
  70. while(pBuf && *pBuf && *pBuf!=L',')
  71. pBuf++;
  72. // if valid and not NULL...
  73. if (pBuf && *pBuf)
  74. pBuf++; // increment
  75. iBlue = StrToInt(pBuf);
  76. // make sure all values are valid
  77. iRed %= 256;
  78. iGreen %= 256;
  79. iBlue %= 256;
  80. Value = RGB(iRed, iGreen, iBlue);
  81. }
  82. return Value;
  83. }
  84. // Writes the registry for a string (REG_SZ) of comma separated RGB values
  85. COLORREF RegSetColorRefString( HUSKEY huskey, LPTSTR RegValue, COLORREF Value)
  86. {
  87. TCHAR SmallBuf[SMALLBUFFER];
  88. TCHAR DigitBuf[4]; // that all we need for '255\0'
  89. int iRed, iGreen, iBlue;
  90. iRed = GetRValue(Value);
  91. iGreen = GetGValue(Value);
  92. iBlue = GetBValue(Value);
  93. ASSERT(ARRAYSIZE(SmallBuf) >= 3 + 3 + 3 + 2 + 1) // "255,255,255"
  94. MyIntToStr(SmallBuf, (BYTE)iRed);
  95. StrCat(SmallBuf, TEXT(","));
  96. StrCat(SmallBuf, MyIntToStr(DigitBuf, (BYTE)iGreen));
  97. StrCat(SmallBuf, TEXT(","));
  98. StrCat(SmallBuf, MyIntToStr(DigitBuf, (BYTE)iBlue));
  99. SHRegWriteUSValue(huskey,
  100. RegValue,
  101. REG_SZ,
  102. (LPVOID)&SmallBuf,
  103. (lstrlen(SmallBuf)+1) * sizeof(TCHAR),
  104. SHREGSET_DEFAULT);
  105. //
  106. // FEATURE: Should we do something if this fails?
  107. //
  108. return Value;
  109. }
  110. // Read the registry for a string (REG_SZ = "yes" | "no") and return a BOOL value
  111. BOOL RegGetBooleanString(HUSKEY huskey, LPTSTR pszRegValue, BOOL bValue)
  112. {
  113. TCHAR szBuf[SMALLBUFFER];
  114. LPCTSTR pszDefault;
  115. DWORD cb;
  116. DWORD cbDef;
  117. // get the default setting
  118. if (bValue)
  119. pszDefault = g_cszYes;
  120. else
  121. pszDefault = g_cszNo;
  122. cb = ARRAYSIZE(szBuf);
  123. cbDef = (lstrlen(pszDefault)+1)*sizeof(TCHAR); // +1 for null term
  124. if (SHRegQueryUSValue(huskey,
  125. pszRegValue,
  126. NULL,
  127. (LPVOID)&szBuf,
  128. &cb,
  129. FALSE,
  130. (LPVOID)pszDefault,
  131. cbDef) == ERROR_SUCCESS)
  132. {
  133. if (!StrCmpI(szBuf, g_cszYes))
  134. bValue = TRUE;
  135. else if (!StrCmpI(szBuf, g_cszNo))
  136. bValue = FALSE;
  137. // else fall thru and return the Default that was passed in
  138. }
  139. return bValue;
  140. }
  141. // Write the registry for a string (REG_SZ) TRUE = "yes", FALSE = "no"
  142. BOOL RegSetBooleanString(HUSKEY huskey, LPTSTR pszRegValue, BOOL bValue)
  143. {
  144. TCHAR szBuf[SMALLBUFFER];
  145. if (bValue)
  146. StrCpyN(szBuf, g_cszYes, ARRAYSIZE(szBuf));
  147. else
  148. StrCpyN(szBuf, g_cszNo, ARRAYSIZE(szBuf));
  149. SHRegWriteUSValue(huskey,
  150. pszRegValue,
  151. REG_SZ,
  152. (LPVOID)&szBuf,
  153. (lstrlen(szBuf)+1) * sizeof(TCHAR),
  154. SHREGSET_DEFAULT);
  155. //
  156. // FEATURE: Should we try to do something if this fails?
  157. //
  158. return bValue;
  159. }