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.

244 lines
7.8 KiB

  1. /*****************************************************************************
  2. *
  3. * Registry.c - This module handles requests for registry data, and
  4. * reading/writing of window placement data
  5. *
  6. * Microsoft Confidential
  7. * Copyright (c) 1992-1993 Microsoft Corporation
  8. *
  9. *
  10. ****************************************************************************/
  11. #include <stdio.h>
  12. #include "perfmon.h"
  13. #include "registry.h"
  14. #include "utils.h"
  15. #include "sizes.h"
  16. static TCHAR PerfmonNamesKey[] = TEXT("SOFTWARE\\Microsoft\\PerfMon") ;
  17. static TCHAR WindowKeyName[] = TEXT("WindowPos") ;
  18. static TCHAR TimeOutKeyName[] = TEXT("DataTimeOut") ;
  19. static TCHAR DupInstanceKeyName[] = TEXT("MonitorDuplicateInstances") ;
  20. static TCHAR ReportEventsToEventLog[] = TEXT("ReportEventsToEventLog");
  21. static TCHAR CapPercentsAt100[] = TEXT("CapPercentsAt100");
  22. VOID LoadLineGraphSettings(PGRAPHSTRUCT lgraph)
  23. {
  24. lgraph->gMaxValues = DEFAULT_MAX_VALUES;
  25. lgraph->gOptions.bLegendChecked = DEFAULT_F_DISPLAY_LEGEND;
  26. lgraph->gOptions.bLabelsChecked = DEFAULT_F_DISPLAY_CALIBRATION;
  27. return;
  28. }
  29. VOID LoadRefreshSettings(PGRAPHSTRUCT lgraph)
  30. {
  31. lgraph->gInterval = DEF_GRAPH_INTERVAL;
  32. lgraph->gOptions.eTimeInterval = (FLOAT) lgraph->gInterval / (FLOAT) 1000.0 ;
  33. return;
  34. }
  35. BOOL LoadMainWindowPlacement (HWND hWnd)
  36. {
  37. WINDOWPLACEMENT WindowPlacement ;
  38. TCHAR szWindowPlacement [TEMP_BUF_LEN] ;
  39. HKEY hKeyNames ;
  40. DWORD Size;
  41. DWORD Type;
  42. DWORD Status;
  43. DWORD localDataTimeOut;
  44. DWORD localFlag;
  45. STARTUPINFO StartupInfo ;
  46. GetStartupInfo (&StartupInfo) ;
  47. DataTimeOut = DEFAULT_DATA_TIMEOUT ;
  48. Status = RegOpenKeyEx(HKEY_CURRENT_USER, PerfmonNamesKey,
  49. 0L, KEY_READ | KEY_WRITE, &hKeyNames) ;
  50. if (Status == ERROR_SUCCESS)
  51. {
  52. // get the data timeout value
  53. Size = sizeof(localDataTimeOut) ;
  54. Status = RegQueryValueEx(hKeyNames, TimeOutKeyName, NULL,
  55. &Type, (LPBYTE)&localDataTimeOut, &Size) ;
  56. if (Status == ERROR_SUCCESS && Type == REG_DWORD)
  57. {
  58. DataTimeOut = localDataTimeOut ;
  59. }
  60. // check the duplicate entry value
  61. Size = sizeof (localFlag);
  62. Status = RegQueryValueEx (hKeyNames, DupInstanceKeyName, NULL,
  63. &Type, (LPBYTE)&localFlag, &Size);
  64. if ((Status == ERROR_SUCCESS) && (Type == REG_DWORD)) {
  65. bMonitorDuplicateInstances = (BOOL)(localFlag == 1);
  66. } else {
  67. // value not found or not correct so set to default value
  68. bMonitorDuplicateInstances = TRUE;
  69. // and try to save it back in the registry
  70. localFlag = 1;
  71. Status = RegSetValueEx(hKeyNames, DupInstanceKeyName, 0,
  72. REG_DWORD, (LPBYTE)&localFlag, sizeof(localFlag));
  73. }
  74. // check the duplicate entry value
  75. Size = sizeof (localFlag);
  76. Status = RegQueryValueEx (hKeyNames, CapPercentsAt100, NULL,
  77. &Type, (LPBYTE)&localFlag, &Size);
  78. if ((Status == ERROR_SUCCESS) && (Type == REG_DWORD)) {
  79. bCapPercentsAt100 = (BOOL)(localFlag == 1);
  80. } else {
  81. // value not found or not correct so set to default value
  82. bCapPercentsAt100 = TRUE;
  83. // and try to save it back in the registry
  84. localFlag = 1;
  85. Status = RegSetValueEx(hKeyNames, CapPercentsAt100, 0,
  86. REG_DWORD, (LPBYTE)&localFlag, sizeof(localFlag));
  87. }
  88. // check the Report To Event Log entry value
  89. Size = sizeof (localFlag);
  90. Status = RegQueryValueEx (hKeyNames, ReportEventsToEventLog, NULL,
  91. &Type, (LPBYTE)&localFlag, &Size);
  92. if ((Status == ERROR_SUCCESS) && (Type == REG_DWORD)) {
  93. bReportEvents = (BOOL)(localFlag == 1);
  94. } else {
  95. // value not found or not correct so set to default value
  96. // which is disabled.
  97. bReportEvents = FALSE;
  98. // and try to save it back in the registry
  99. localFlag = 0;
  100. Status = RegSetValueEx(hKeyNames, ReportEventsToEventLog, 0,
  101. REG_DWORD, (LPBYTE)&localFlag, sizeof(localFlag));
  102. }
  103. // get the window placement data
  104. Size = sizeof(szWindowPlacement) ;
  105. Status = RegQueryValueEx(hKeyNames, WindowKeyName, NULL,
  106. &Type, (LPBYTE)szWindowPlacement, &Size) ;
  107. RegCloseKey (hKeyNames) ;
  108. if (Status == ERROR_SUCCESS)
  109. {
  110. int iNumScanned ;
  111. iNumScanned = swscanf (szWindowPlacement,
  112. TEXT("%d %d %d %d %d %d %d %d %d"),
  113. &WindowPlacement.showCmd,
  114. &WindowPlacement.ptMinPosition.x,
  115. &WindowPlacement.ptMinPosition.y,
  116. &WindowPlacement.ptMaxPosition.x,
  117. &WindowPlacement.ptMaxPosition.y,
  118. &WindowPlacement.rcNormalPosition.left,
  119. &WindowPlacement.rcNormalPosition.top,
  120. &WindowPlacement.rcNormalPosition.right,
  121. &WindowPlacement.rcNormalPosition.bottom) ;
  122. if (StartupInfo.dwFlags == STARTF_USESHOWWINDOW)
  123. {
  124. WindowPlacement.showCmd = StartupInfo.wShowWindow ;
  125. }
  126. WindowPlacement.length = sizeof(WINDOWPLACEMENT);
  127. WindowPlacement.flags = WPF_SETMINPOSITION;
  128. if (!SetWindowPlacement (hWnd, &WindowPlacement)) {
  129. return (FALSE);
  130. }
  131. bPerfmonIconic = IsIconic(hWnd) ;
  132. return (TRUE) ;
  133. }
  134. }
  135. if (Status != ERROR_SUCCESS)
  136. {
  137. // open registry failed, use input from startup info or Max as default
  138. if (StartupInfo.dwFlags == STARTF_USESHOWWINDOW)
  139. {
  140. ShowWindow (hWnd, StartupInfo.wShowWindow) ;
  141. }
  142. else
  143. {
  144. ShowWindow (hWnd, SW_SHOWMAXIMIZED) ;
  145. }
  146. return (FALSE) ;
  147. }
  148. else
  149. return TRUE;
  150. }
  151. BOOL SaveMainWindowPlacement (HWND hWnd)
  152. {
  153. WINDOWPLACEMENT WindowPlacement ;
  154. TCHAR ObjectType [2] ;
  155. TCHAR szWindowPlacement [TEMP_BUF_LEN] ;
  156. HKEY hKeyNames = 0 ;
  157. DWORD Size ;
  158. DWORD Status ;
  159. DWORD dwDisposition ;
  160. ObjectType [0] = TEXT(' ') ;
  161. ObjectType [1] = TEXT('\0') ;
  162. WindowPlacement.length = sizeof(WINDOWPLACEMENT);
  163. if (!GetWindowPlacement (hWnd, &WindowPlacement)) {
  164. return FALSE;
  165. }
  166. TSPRINTF (szWindowPlacement, TEXT("%d %d %d %d %d %d %d %d %d"),
  167. WindowPlacement.showCmd,
  168. WindowPlacement.ptMinPosition.x,
  169. WindowPlacement.ptMinPosition.y,
  170. WindowPlacement.ptMaxPosition.x,
  171. WindowPlacement.ptMaxPosition.y,
  172. WindowPlacement.rcNormalPosition.left,
  173. WindowPlacement.rcNormalPosition.top,
  174. WindowPlacement.rcNormalPosition.right,
  175. WindowPlacement.rcNormalPosition.bottom) ;
  176. // try to create it first
  177. Status = RegCreateKeyEx(HKEY_CURRENT_USER, PerfmonNamesKey, 0L,
  178. ObjectType, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WRITE,
  179. NULL, &hKeyNames, &dwDisposition) ;
  180. // if it has been created before, then open it
  181. if (dwDisposition == REG_OPENED_EXISTING_KEY)
  182. {
  183. Status = RegOpenKeyEx(HKEY_CURRENT_USER, PerfmonNamesKey, 0L,
  184. KEY_WRITE, &hKeyNames) ;
  185. }
  186. // we got the handle, now store the window placement data
  187. if (Status == ERROR_SUCCESS)
  188. {
  189. Size = (lstrlen (szWindowPlacement) + 1) * sizeof (TCHAR) ;
  190. Status = RegSetValueEx(hKeyNames, WindowKeyName, 0,
  191. REG_SZ, (LPBYTE)szWindowPlacement, Size) ;
  192. if (dwDisposition != REG_OPENED_EXISTING_KEY && Status == ERROR_SUCCESS)
  193. {
  194. // now add the DataTimeOut key for the first time
  195. Status = RegSetValueEx(hKeyNames, TimeOutKeyName, 0,
  196. REG_DWORD, (LPBYTE)&DataTimeOut, sizeof(DataTimeOut)) ;
  197. }
  198. RegCloseKey (hKeyNames) ;
  199. }
  200. return (Status == ERROR_SUCCESS) ;
  201. }
  202. 
  203.