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.

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