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.

145 lines
4.1 KiB

  1. /* CB.C
  2. Resident Code Segment // Tweak: make non-resident
  3. Utility routines for checkboxes.
  4. Frosting: Master Theme Selector for Windows '95
  5. Copyright (c) 1994-1998 Microsoft Corporation
  6. */
  7. // ---------------------------------------------
  8. // Brief file history:
  9. // Alpha:
  10. // Beta:
  11. // Bug fixes
  12. // ---------
  13. //
  14. // ---------------------------------------------
  15. #include "windows.h"
  16. #include "frost.h"
  17. #include "global.h"
  18. //
  19. // InitCheckboxes
  20. // Actually, you are init'ing the stored state of the checkboxes.
  21. // All from saved registry values initially; or just checked if no stored
  22. // values. This gets picked up on the first call to EnableThemeButtons().
  23. //
  24. void FAR InitCheckboxes()
  25. {
  26. extern TCHAR szPlus_CBs[];
  27. LONG lret;
  28. HKEY hKey;
  29. int iter;
  30. TCHAR szState[5];
  31. DWORD dwSize;
  32. DWORD dwType;
  33. // we're going to try to read from the registry
  34. lret = RegOpenKeyEx( HKEY_CURRENT_USER, szPlus_CBs,
  35. (DWORD)0, KEY_QUERY_VALUE, (PHKEY)&hKey );
  36. // check that you got a good key here
  37. if (lret == ERROR_SUCCESS) {
  38. // go through each checkbox and read stored state from registry
  39. for (iter = 0; iter < MAX_FCHECKS; iter ++) {
  40. // first do paranoid check of data size
  41. lret = RegQueryValueEx(hKey, (LPTSTR)szCBNames[iter], (LPDWORD)NULL,
  42. (LPDWORD)&dwType, (LPBYTE)NULL, (LPDWORD)&dwSize);
  43. if (ERROR_SUCCESS == lret) {
  44. // here's the size check before getting the data
  45. if (dwSize > ((DWORD)5 * sizeof(TCHAR))) {
  46. Assert(FALSE, TEXT("Large entry for checkbox state!\n"));
  47. lret = ERROR_SUCCESS - 5; // set error flag for check below
  48. }
  49. else
  50. //
  51. // now really get the value
  52. lret = RegQueryValueEx(hKey, (LPTSTR)szCBNames[iter], (LPDWORD)NULL,
  53. (LPDWORD)&dwType, (LPBYTE)szState, (LPDWORD)&dwSize);
  54. }
  55. //
  56. // if you got something, go ahead and use it to set checkbox state!
  57. //
  58. if (ERROR_SUCCESS == lret) {
  59. // invalid value defaults to TRUE/checked, so check for valid FALSE/unchecked
  60. bCBStates[iter] = (szState[0] == TEXT('0') ? FALSE : TRUE);
  61. }
  62. // otherwise, use ultimate error case
  63. else {
  64. Assert(FALSE, TEXT("couldn't read one of the checkbox states\n"));
  65. // always easy worst case default: just init to checked
  66. // Except for CB_SCHEDULE -- if it can't be read we want
  67. // to default to off.
  68. if (FC_SCHEDULE == iter) bCBStates[iter] = FALSE;
  69. else bCBStates[iter] = TRUE;
  70. }
  71. }
  72. // cleanup
  73. RegCloseKey(hKey);
  74. }
  75. else { // couldn't open key, so just set to checked
  76. Assert(FALSE, TEXT("problem opening Checkbox registry to init checkboxes\n"));
  77. for (iter = 0; iter < MAX_FCHECKS; iter ++) {
  78. if (FC_SCHEDULE == iter) bCBStates[iter] = FALSE;
  79. else bCBStates[iter] = TRUE;
  80. }
  81. }
  82. }
  83. //
  84. // Save/RestoreCheckboxes
  85. // Save/Restore the state of the checkboxes to/from the states array.
  86. // The checkbox ID array defines order saved in the states array.
  87. //
  88. // Globals: sets values in global bCBStates[] array.
  89. //
  90. void FAR SaveCheckboxes()
  91. {
  92. int iter;
  93. for (iter = 0; iter < MAX_FCHECKS; iter ++) {
  94. bCBStates[iter] = IsDlgButtonChecked(hWndApp, iCBIDs[iter]);
  95. }
  96. }
  97. //
  98. // Assumes caller has already enabled all the buttons so they can be checked.
  99. void FAR RestoreCheckboxes()
  100. {
  101. int iter;
  102. for (iter = 0; iter < MAX_FCHECKS; iter ++) {
  103. CheckDlgButton(hWndApp, iCBIDs[iter], bCBStates[iter]);
  104. }
  105. }
  106. // IsAnyBoxChecked()
  107. //
  108. // Returns TRUE if any of the theme setting checkboxes are checked.
  109. // We ignore the SCHEDULE checkbox setting.
  110. BOOL FAR IsAnyBoxChecked()
  111. {
  112. BOOL bRet = FALSE;
  113. int iter;
  114. for (iter = 0;
  115. (iter < MAX_FCHECKS) && !bRet;
  116. iter ++) {
  117. if (FC_SCHEDULE != iter)
  118. {
  119. bRet = bRet | IsDlgButtonChecked(hWndApp, iCBIDs[iter]);
  120. }
  121. }
  122. return (bRet);
  123. }