Windows NT 4.0 source code leak
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.

230 lines
7.1 KiB

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