diff --git a/reactos/subsys/system/regedit/main.c b/reactos/subsys/system/regedit/main.c index de99d30f43d..4f99a70fe78 100644 --- a/reactos/subsys/system/regedit/main.c +++ b/reactos/subsys/system/regedit/main.c @@ -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 InitInstance(HINSTANCE hInstance, int nCmdShow) { BOOL AclUiAvailable; HMENU hEditMenu; + TCHAR szBuffer[256]; + LPCTSTR s; WNDCLASSEX wcFrame = { sizeof(WNDCLASSEX), @@ -158,6 +161,19 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 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; diff --git a/reactos/subsys/system/regedit/regproc.c b/reactos/subsys/system/regedit/regproc.c index 18866eb0423..8d1b0de462a 100644 --- a/reactos/subsys/system/regedit/regproc.c +++ b/reactos/subsys/system/regedit/regproc.c @@ -1659,8 +1659,42 @@ LONG RegRenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lp 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; } @@ -1674,22 +1708,22 @@ BOOL RegKeyGetName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lp 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; } diff --git a/reactos/subsys/system/regedit/regproc.h b/reactos/subsys/system/regedit/regproc.h index bbd039b3ae4..bf286ec0676 100644 --- a/reactos/subsys/system/regedit/regproc.h +++ b/reactos/subsys/system/regedit/regproc.h @@ -90,6 +90,7 @@ LONG RegCopyKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrc 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