From 6827724e54c49a5f15993ba7e24dddafa68e8502 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sat, 13 Jun 2015 19:26:22 +0300 Subject: [PATCH] regedit: Make it possible for save/restore position on tree root. --- programs/regedit/childwnd.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/programs/regedit/childwnd.c b/programs/regedit/childwnd.c index 6dc7d0caaa4..55b11de9d34 100644 --- a/programs/regedit/childwnd.c +++ b/programs/regedit/childwnd.c @@ -243,7 +243,14 @@ static void get_last_key(HWND hwndTV) if (RegCreateKeyExW(HKEY_CURRENT_USER, wszKeyName, 0, NULL, 0, KEY_READ, NULL, &hkey, NULL) == ERROR_SUCCESS) { if (RegQueryValueExW(hkey, wszLastKey, NULL, NULL, (LPBYTE)wszVal, &dwSize) == ERROR_SUCCESS) - SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)FindPathInTree(hwndTV, wszVal)); + { + HTREEITEM selection; + if (!strcmpW(wszVal, g_pChildWnd->szPath)) + selection = (HTREEITEM)SendMessageW(g_pChildWnd->hTreeWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0); + else + selection = FindPathInTree(hwndTV, wszVal); + SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)selection); + } RegCloseKey(hkey); } @@ -258,15 +265,20 @@ static void get_last_key(HWND hwndTV) static void set_last_key(HWND hwndTV) { HKEY hkey; - WCHAR *wszVal; if (RegCreateKeyExW(HKEY_CURRENT_USER, wszKeyName, 0, NULL, 0, KEY_WRITE, NULL, &hkey, NULL) == ERROR_SUCCESS) { HTREEITEM selection = (HTREEITEM)SendMessageW(g_pChildWnd->hTreeWnd, TVM_GETNEXTITEM, TVGN_CARET, 0); + HTREEITEM root = (HTREEITEM)SendMessageW(g_pChildWnd->hTreeWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0); + WCHAR *value; - wszVal = GetItemFullPath(g_pChildWnd->hTreeWnd, selection, FALSE); - RegSetValueExW(hkey, wszLastKey, 0, REG_SZ, (LPBYTE)wszVal, (lstrlenW(wszVal) + 1) * sizeof(WCHAR)); - HeapFree(GetProcessHeap(), 0, wszVal); + if (selection == root) + value = g_pChildWnd->szPath; + else + value = GetItemFullPath(g_pChildWnd->hTreeWnd, selection, FALSE); + RegSetValueExW(hkey, wszLastKey, 0, REG_SZ, (LPBYTE)value, (lstrlenW(value) + 1) * sizeof(WCHAR)); + if (selection != root) + HeapFree(GetProcessHeap(), 0, value); RegCloseKey(hkey); } }