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.

279 lines
9.2 KiB

  1. /****************************************************************************\
  2. FONT.C / Factory / WinBOM (FACTORY.EXE)
  3. Microsoft Confidential
  4. Copyright (c) Microsoft Corporation 2001
  5. All rights reserved
  6. State code for customizing the font smoothing and cleartype settings.
  7. WINBOM.INI
  8. [ComputerSettings]
  9. FontSmoothing = ; Default is 'Standard'.
  10. Standard | ; Will determine, based on the system speed, if font
  11. ; smoothing is turned on or not.
  12. On | ; Forces font smoothing on. Should only be used if the
  13. ; performance of the video card is known to give an
  14. ; acceptable user experience with this option enabled.
  15. Off | ; Forces font smoothing off.
  16. ClearType ; Turns clear type and font smoothing on. Should only be
  17. ; used if the monitor is known to be an LCD screen and
  18. ; that the system performance is known to be acceptable
  19. ; with this option enabled.
  20. 04/2001 - Jason Cohen (JCOHEN)
  21. Added source file for the state that customizes the font and
  22. cleartype settings.
  23. \****************************************************************************/
  24. //
  25. // Includes
  26. //
  27. #include "factoryp.h"
  28. //
  29. // Internal Defined Value(s):
  30. //
  31. #define REG_KEY_FONTSMOOTHING _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VisualEffects\\FontSmoothing")
  32. #define REG_VAL_DEFAULTBYFONTTEST _T("DefaultByFontTest")
  33. #define REG_VAL_DEFAULTVALUE _T("DefaultValue")
  34. #define REG_KEY_CLEARTYPE _T("Control Panel\\Desktop")
  35. #define REG_VAL_FONTSMOOTHING _T("FontSmoothing")
  36. #define REG_VAL_FONTSMOOTHINGTYPE _T("FontSmoothingType")
  37. #define REG_KEY_HORRID_CLASSES _T("_Classes")
  38. #define REG_KEY_HORRID_CLASSES_LEN ( AS(REG_KEY_HORRID_CLASSES) - 1 )
  39. //
  40. // Internal Function Prototype(s):
  41. //
  42. static BOOL RegSetAllUsers(LPTSTR lpszSubKey, LPTSTR lpszValue, LPBYTE lpData, DWORD dwType);
  43. //
  44. // Exported Function(s):
  45. //
  46. BOOL SetFontOptions(LPSTATEDATA lpStateData)
  47. {
  48. LPTSTR lpszWinBOMPath = lpStateData->lpszWinBOMPath;
  49. TCHAR szFontSmoothing[256] = NULLSTR,
  50. szFontSmoothingData[] = _T("_");
  51. DWORD dwDefaultByFontTest,
  52. dwDefaultValue,
  53. dwFontSmoothingType;
  54. BOOL bRet = TRUE;
  55. // Get the option from the winbom.
  56. //
  57. GetPrivateProfileString(INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_FONTSMOOTHING, NULLSTR, szFontSmoothing, AS(szFontSmoothing), lpszWinBOMPath);
  58. // Figure out what values to write based on the value in the winbom.
  59. //
  60. if ( NULLCHR == szFontSmoothing[0] )
  61. {
  62. // No key, do nothing and do not touch whatever options already set.
  63. //
  64. return TRUE;
  65. }
  66. else if ( LSTRCMPI(szFontSmoothing, INI_VAL_WBOM_FONTSMOOTHING_ON) == 0 )
  67. {
  68. // Force font smoothing on.
  69. //
  70. dwDefaultByFontTest = 0;
  71. dwDefaultValue = 1;
  72. dwFontSmoothingType = 1;
  73. szFontSmoothingData[0] = _T('2');
  74. }
  75. else if ( LSTRCMPI(szFontSmoothing, INI_VAL_WBOM_FONTSMOOTHING_OFF) == 0 )
  76. {
  77. // Force font smoothing off.
  78. //
  79. dwDefaultByFontTest = 0;
  80. dwDefaultValue = 0;
  81. dwFontSmoothingType = 0;
  82. szFontSmoothingData[0] = _T('0');
  83. }
  84. else if ( LSTRCMPI(szFontSmoothing, INI_VAL_WBOM_FONTSMOOTHING_CLEARTYPE) == 0 )
  85. {
  86. // Force font smoothing and cleartype on.
  87. //
  88. dwDefaultByFontTest = 0;
  89. dwDefaultValue = 1;
  90. dwFontSmoothingType = 2;
  91. szFontSmoothingData[0] = _T('2');
  92. }
  93. else if ( LSTRCMPI(szFontSmoothing, INI_VAL_WBOM_FONTSMOOTHING_DEFAULT) == 0 )
  94. {
  95. // Let system decide if font smoothing should be on or not.
  96. //
  97. dwDefaultByFontTest = 1;
  98. dwDefaultValue = 0;
  99. dwFontSmoothingType = 0;
  100. szFontSmoothingData[0] = _T('0');
  101. }
  102. else
  103. {
  104. FacLogFile(0 | LOG_ERR, IDS_ERR_WINBOMVALUE, lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_FONTSMOOTHING, szFontSmoothing);
  105. bRet = FALSE;
  106. }
  107. // Now save the settings if valid option passed in.
  108. //
  109. if ( bRet )
  110. {
  111. if ( !RegSetDword(HKLM, REG_KEY_FONTSMOOTHING, REG_VAL_DEFAULTBYFONTTEST, dwDefaultByFontTest) )
  112. {
  113. bRet = FALSE;
  114. }
  115. if ( !RegSetDword(HKLM, REG_KEY_FONTSMOOTHING, REG_VAL_DEFAULTVALUE, dwDefaultValue) )
  116. {
  117. bRet = FALSE;
  118. }
  119. if ( !RegSetAllUsers(REG_KEY_CLEARTYPE, REG_VAL_FONTSMOOTHINGTYPE, (LPBYTE) &dwFontSmoothingType, REG_DWORD) )
  120. {
  121. bRet = FALSE;
  122. }
  123. if ( !RegSetAllUsers(REG_KEY_CLEARTYPE, REG_VAL_FONTSMOOTHING, (LPBYTE) szFontSmoothingData, REG_SZ) )
  124. {
  125. bRet = FALSE;
  126. }
  127. //
  128. // ISSUE-2002/02/25-acosma,robertko - this is a duplicate of the REG_VAL_FONTSMOOTHINGTYPE set above - should be removed.
  129. //
  130. if ( !RegSetAllUsers(REG_KEY_CLEARTYPE, REG_VAL_FONTSMOOTHINGTYPE, (LPBYTE) &dwFontSmoothingType, REG_DWORD) )
  131. {
  132. bRet = FALSE;
  133. }
  134. }
  135. return bRet;
  136. }
  137. BOOL DisplaySetFontOptions(LPSTATEDATA lpStateData)
  138. {
  139. return IniSettingExists(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_FONTSMOOTHING, NULL);
  140. }
  141. //
  142. // Internal Function(s):
  143. //
  144. static BOOL RegSetAllUsers(LPTSTR lpszSubKey, LPTSTR lpszValue, LPBYTE lpData, DWORD dwType)
  145. {
  146. BOOL bRet = TRUE,
  147. bErr;
  148. LPTSTR lpszKeyName;
  149. HKEY hkeyEnum,
  150. hkeySub;
  151. DWORD dwIndex = 0,
  152. dwSize,
  153. dwDis,
  154. dwMaxSize;
  155. int iLen;
  156. // Figure out the max length of any sub key and allocate a buffer for it.
  157. //
  158. if ( ( ERROR_SUCCESS == RegQueryInfoKey(HKEY_USERS,
  159. NULL,
  160. NULL,
  161. NULL,
  162. NULL,
  163. &dwMaxSize,
  164. NULL,
  165. NULL,
  166. NULL,
  167. NULL,
  168. NULL,
  169. NULL) ) &&
  170. ( lpszKeyName = (LPTSTR) MALLOC((++dwMaxSize) * sizeof(TCHAR)) ) )
  171. {
  172. // Now enumerate all the sub keys.
  173. //
  174. dwSize = dwMaxSize;
  175. while ( ERROR_SUCCESS == RegEnumKeyEx(HKEY_USERS,
  176. dwIndex++,
  177. lpszKeyName,
  178. &dwSize,
  179. NULL,
  180. NULL,
  181. NULL,
  182. NULL) )
  183. {
  184. // Iterate over all users ignoring the keys with the "_Classes" suffix
  185. //
  186. if ( ( dwSize < REG_KEY_HORRID_CLASSES_LEN ) ||
  187. ( 0 != LSTRCMPI(lpszKeyName + (dwSize - REG_KEY_HORRID_CLASSES_LEN), REG_KEY_HORRID_CLASSES) ) )
  188. {
  189. // Open up the sub key.
  190. //
  191. if ( ERROR_SUCCESS == RegOpenKeyEx(HKEY_USERS,
  192. lpszKeyName,
  193. 0,
  194. KEY_ALL_ACCESS,
  195. &hkeyEnum) )
  196. {
  197. // Set the value that was passed in.
  198. //
  199. switch ( dwType )
  200. {
  201. case REG_DWORD:
  202. bErr = !RegSetDword(hkeyEnum, lpszSubKey, lpszValue, *((LPDWORD) lpData));
  203. break;
  204. case REG_SZ:
  205. bErr = !RegSetString(hkeyEnum, lpszSubKey, lpszValue, (LPTSTR) lpData);
  206. break;
  207. default:
  208. bErr = TRUE;
  209. break;
  210. }
  211. // If anything fails, we keep going but return an error.
  212. //
  213. if ( bErr )
  214. {
  215. bRet = FALSE;
  216. }
  217. // Close the sub key that we enumerated.
  218. //
  219. RegCloseKey(hkeyEnum);
  220. }
  221. }
  222. // Reset the size for the next call to RegEnumKeyEx().
  223. //
  224. dwSize = dwMaxSize;
  225. }
  226. // Free the buffer we allocated.
  227. //
  228. FREE(lpszKeyName);
  229. }
  230. else
  231. {
  232. bRet = FALSE;
  233. }
  234. // Return TRUE if everything worked okay.
  235. //
  236. return bRet;
  237. }