Regedit: Now restores last position on startup

Still need to save position on exit
Modified: trunk/reactos/subsys/system/regedit/main.c
Modified: trunk/reactos/subsys/system/regedit/regproc.c
Modified: trunk/reactos/subsys/system/regedit/regproc.h

Modified: trunk/reactos/subsys/system/regedit/main.c
--- trunk/reactos/subsys/system/regedit/main.c	2005-10-05 13:08:59 UTC (rev 18269)
+++ trunk/reactos/subsys/system/regedit/main.c	2005-10-05 13:25:14 UTC (rev 18270)
@@ -34,6 +34,7 @@
 #include "main.h"
 #include "hexedit.h"
 #include "security.h"
+#include "regproc.h"
 
 BOOL ProcessCmdLine(LPSTR lpCmdLine);
 
@@ -74,6 +75,8 @@
 {
     BOOL AclUiAvailable;
     HMENU hEditMenu;
+    TCHAR szBuffer[256];
+    LPCTSTR s;
 
     WNDCLASSEX wcFrame = {
                              sizeof(WNDCLASSEX),
@@ -158,6 +161,19 @@
         SetupStatusBar(hFrameWnd, FALSE);
         CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
     }
+
+    /* Restore position */
+    if (RegQueryStringValue(HKEY_CURRENT_USER,
+        _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit"),
+        _T("LastKey"),
+        szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
+    {
+        s = szBuffer;
+        if (!_tcsncmp(s, _T("My Computer\\"), 12))
+            s += 12;
+        SelectNode(g_pChildWnd->hTreeWnd, s);
+    }
+
     ShowWindow(hFrameWnd, nCmdShow);
     UpdateWindow(hFrameWnd);
     return TRUE;

Modified: trunk/reactos/subsys/system/regedit/regproc.c
--- trunk/reactos/subsys/system/regedit/regproc.c	2005-10-05 13:08:59 UTC (rev 18269)
+++ trunk/reactos/subsys/system/regedit/regproc.c	2005-10-05 13:25:14 UTC (rev 18270)
@@ -1659,11 +1659,45 @@
     RegDeleteValue(hKey, lpSrcValue);
 
 done:
-    if (hKey)
-        RegCloseKey(hKey);
+    if (hSubKey)
+        RegCloseKey(hSubKey);
     return lResult;
 }
 
+LONG RegQueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
+{
+    LONG lResult;
+    HKEY hSubKey = NULL;
+    DWORD cbData, dwType;
+
+    if (lpSubKey)
+    {
+        lResult = RegOpenKey(hKey, lpSubKey, &hSubKey);
+        if (lResult != ERROR_SUCCESS)
+            goto done;
+        hKey = hSubKey;
+    }
+
+    cbData = (dwBufferLen - 1) * sizeof(*pszBuffer);
+    lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE) pszBuffer, &cbData);
+    if (lResult != ERROR_SUCCESS)
+        goto done;
+    if (dwType != REG_SZ)
+    {
+        lResult = -1;
+        goto done;
+    }
+
+    pszBuffer[cbData / sizeof(*pszBuffer)] = '\0';
+
+done:
+    if (lResult != ERROR_SUCCESS)
+        pszBuffer[0] = '\0';
+    if (hSubKey)
+        RegCloseKey(hSubKey);
+    return lResult;
+}
+
 /******************************************************************************
  * Key naming and parsing
  */
@@ -1674,22 +1708,22 @@
 
     if (hRootKey == HKEY_CLASSES_ROOT)
         pszRootKey = TEXT("HKEY_CLASSES_ROOT");
-	else if (hRootKey == HKEY_CURRENT_USER)
+    else if (hRootKey == HKEY_CURRENT_USER)
         pszRootKey = TEXT("HKEY_CURRENT_USER");
-	else if (hRootKey == HKEY_LOCAL_MACHINE)
+    else if (hRootKey == HKEY_LOCAL_MACHINE)
         pszRootKey = TEXT("HKEY_LOCAL_MACHINE");
-	else if (hRootKey == HKEY_USERS)
+    else if (hRootKey == HKEY_USERS)
         pszRootKey = TEXT("HKEY_USERS");
-	else if (hRootKey == HKEY_CURRENT_CONFIG)
+    else if (hRootKey == HKEY_CURRENT_CONFIG)
         pszRootKey = TEXT("HKEY_CURRENT_CONFIG");
-	else if (hRootKey == HKEY_DYN_DATA)
+    else if (hRootKey == HKEY_DYN_DATA)
         pszRootKey = TEXT("HKEY_DYN_DATA");
     else
         return FALSE;
 
     if (lpSubKey[0])
         _sntprintf(pszDest, iDestLength, TEXT("%s\\%s"), pszRootKey, lpSubKey);
-	else
+    else
         _sntprintf(pszDest, iDestLength, TEXT("%s"), pszRootKey);
     return TRUE;
 }

Modified: trunk/reactos/subsys/system/regedit/regproc.h
--- trunk/reactos/subsys/system/regedit/regproc.h	2005-10-05 13:08:59 UTC (rev 18269)
+++ trunk/reactos/subsys/system/regedit/regproc.h	2005-10-05 13:25:14 UTC (rev 18270)
@@ -90,6 +90,7 @@
 LONG RegMoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey);
 LONG RegRenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName);
 LONG RegRenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue);
+LONG RegQueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen);
 
 /*
  * Miscellaneous