Index: base/applications/regedit/childwnd.c =================================================================== --- base/applications/regedit/childwnd.c (revision 55785) +++ base/applications/regedit/childwnd.c (working copy) @@ -26,11 +26,7 @@ HBRUSH SizingBrush = 0; static TCHAR Suggestions[256]; -/******************************************************************************* - * Local module support methods - */ - -static LPCTSTR get_root_key_name(HKEY hRootKey) +extern LPCTSTR get_root_key_name(HKEY hRootKey) { if (hRootKey == HKEY_CLASSES_ROOT) return _T("HKEY_CLASSES_ROOT"); if (hRootKey == HKEY_CURRENT_USER) return _T("HKEY_CURRENT_USER"); @@ -41,6 +37,31 @@ return _T("UKNOWN HKEY, PLEASE REPORT"); } +extern void ResizeWnd(int cx, int cy) +{ + HDWP hdwp = BeginDeferWindowPos(3); + RECT rt, rs, rb; + const int tHeight = 18; + SetRect(&rt, 0, 0, cx, cy); + cy = 0; + if (hStatusBar != NULL) + { + GetWindowRect(hStatusBar, &rs); + cy = rs.bottom - rs.top; + } + GetWindowRect(g_pChildWnd->hAddressBtnWnd, &rb); + cx = g_pChildWnd->nSplitPos + SPLIT_WIDTH/2; + DeferWindowPos(hdwp, g_pChildWnd->hAddressBarWnd, 0, rt.left, rt.top, rt.right-rt.left - tHeight-2, tHeight, SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, g_pChildWnd->hAddressBtnWnd, 0, rt.right - tHeight, rt.top, tHeight, tHeight, SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, g_pChildWnd->hTreeWnd, 0, rt.left, rt.top + tHeight+2, g_pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, g_pChildWnd->hListWnd, 0, rt.left+cx, rt.top + tHeight+2, rt.right-cx, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); + EndDeferWindowPos(hdwp); +} + +/******************************************************************************* + * Local module support methods + */ + static void draw_splitbar(HWND hWnd, int x) { RECT rt; @@ -65,27 +86,6 @@ ReleaseDC(hWnd, hdc); } -static void ResizeWnd(int cx, int cy) -{ - HDWP hdwp = BeginDeferWindowPos(3); - RECT rt, rs, rb; - const int tHeight = 18; - SetRect(&rt, 0, 0, cx, cy); - cy = 0; - if (hStatusBar != NULL) - { - GetWindowRect(hStatusBar, &rs); - cy = rs.bottom - rs.top; - } - GetWindowRect(g_pChildWnd->hAddressBtnWnd, &rb); - cx = g_pChildWnd->nSplitPos + SPLIT_WIDTH/2; - DeferWindowPos(hdwp, g_pChildWnd->hAddressBarWnd, 0, rt.left, rt.top, rt.right-rt.left - tHeight-2, tHeight, SWP_NOZORDER|SWP_NOACTIVATE); - DeferWindowPos(hdwp, g_pChildWnd->hAddressBtnWnd, 0, rt.right - tHeight, rt.top, tHeight, tHeight, SWP_NOZORDER|SWP_NOACTIVATE); - DeferWindowPos(hdwp, g_pChildWnd->hTreeWnd, 0, rt.left, rt.top + tHeight+2, g_pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); - DeferWindowPos(hdwp, g_pChildWnd->hListWnd, 0, rt.left+cx, rt.top + tHeight+2, rt.right-cx, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); - EndDeferWindowPos(hdwp); -} - static void OnPaint(HWND hWnd) { PAINTSTRUCT ps; @@ -527,20 +527,6 @@ else if(!_tcschr(keyPath, _T('\\'))) EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_ENABLED); } - - { - HKEY hKey; - TCHAR szBuffer[MAX_PATH]; - _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("My Computer\\%s\\%s"), rootName, keyPath); - - if (RegCreateKey(HKEY_CURRENT_USER, - g_szGeneralRegKey, - &hKey) == ERROR_SUCCESS) - { - RegSetValueEx(hKey, _T("LastKey"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) _tcslen(szBuffer) * sizeof(szBuffer[0])); - RegCloseKey(hKey); - } - } } } } Index: base/applications/regedit/CMakeLists.txt =================================================================== --- base/applications/regedit/CMakeLists.txt (revision 55785) +++ base/applications/regedit/CMakeLists.txt (working copy) @@ -16,6 +16,7 @@ regedit.c regproc.c security.c + settings.c treeview.c regedit.rc) Index: base/applications/regedit/framewnd.c =================================================================== --- base/applications/regedit/framewnd.c (revision 55785) +++ base/applications/regedit/framewnd.c (working copy) @@ -1188,6 +1188,7 @@ break; case WM_DESTROY: WinHelp(hWnd, _T("regedit"), HELP_QUIT, 0); + SaveSettings(); PostQuitMessage(0); default: return DefWindowProc(hWnd, message, wParam, lParam); Index: base/applications/regedit/main.c =================================================================== --- base/applications/regedit/main.c (revision 55785) +++ base/applications/regedit/main.c (working copy) @@ -34,9 +34,7 @@ HMENU hPopupMenus = 0; UINT nClipboardFormat; LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT"); -const TCHAR g_szGeneralRegKey[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit"); - #define MAX_LOADSTRING 100 TCHAR szTitle[MAX_LOADSTRING]; TCHAR szFrameClass[MAX_LOADSTRING]; @@ -60,7 +58,6 @@ { BOOL AclUiAvailable; HMENU hEditMenu; - TCHAR szBuffer[256]; WNDCLASSEX wcFrame; WNDCLASSEX wcChild; @@ -142,14 +139,7 @@ CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); } - /* Restore position */ - if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("LastKey"), - szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) - { - SelectNode(g_pChildWnd->hTreeWnd, szBuffer); - } - - ShowWindow(hFrameWnd, nCmdShow); + LoadSettings(); UpdateWindow(hFrameWnd); return TRUE; } Index: base/applications/regedit/main.h =================================================================== --- base/applications/regedit/main.h (revision 55785) +++ base/applications/regedit/main.h (working copy) @@ -90,6 +90,8 @@ /* childwnd.c */ extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); +extern void ResizeWnd(int cx, int cy); +extern LPCTSTR get_root_key_name(HKEY hRootKey); /* error.c */ extern void ErrorMessageBox(HWND hWnd, LPCTSTR title, DWORD code); @@ -137,3 +139,7 @@ /* security.c */ extern BOOL RegKeyEditPermissions(HWND hWndOwner, HKEY hKey, LPCTSTR lpMachine, LPCTSTR lpKeyName); + +/* settings.c */ +extern void LoadSettings(void); +extern void SaveSettings(void); Index: base/applications/regedit/regedit.rbuild =================================================================== --- base/applications/regedit/regedit.rbuild (revision 55785) +++ base/applications/regedit/regedit.rbuild (working copy) @@ -27,6 +27,7 @@ regedit.c regproc.c security.c + settings.c treeview.c regedit.rc regedit.h Index: base/applications/regedit/settings.c =================================================================== --- base/applications/regedit/settings.c (revision 0) +++ base/applications/regedit/settings.c (working copy) @@ -0,0 +1,156 @@ +/* +* regedit (settings.c) +* +* Copyright 2012 Edijs Kolesnikovics +* Copyright 2012 Grégori Macário Harbs +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include + +const TCHAR g_szGeneralRegKey[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit"); + +/* +VV,VV,VV,VV,WA,WA,WA,WA,WB,WB,WB,WB,R1,R1,R1,R1 +R2,R2,R2,R2,R3,R3,R3,R3,R4,R4,R4,r4,LL,LL,LL,LL +TT,TT,TT,TT,RR,RR,RR,RR,BB,BB,BB,BB,SS,SS,SS,SS +NN,NN,NN,NN,KK,KK,KK,KK,DD,DD,DD,DD,SB,SB,SB,SB + +VV = Version or Sanity? WINDOWPLACEMENT? (2C?) +WA = (0=restored / 1=maximized) +WB = (1=restored / 3=maximized) +R1 = ???? \ +R2 = ???? | either those are reserved unused or they will +R3 = ???? | have IP/INFO if connected to remote registry +R4 = ???? / +LL = Left position of window +TT = top position of window +RR = right position of window +BB = bottom position of window +SS = size of key tree view (splitter) +NN = size of 'name' column +KK = size of 'type' column (kind) +DD = size of 'data' coumn +SB = status bar (1=visible / 0=hidden) +*/ + +typedef struct{ +WINDOWPLACEMENT tPlacement; +int TreeViewSize; +int NameColumnSize; +int TypeColumnSize; +int DataColumnSize; +BOOL StatusBarVisible; +} RegistryBinaryConfig; + +extern void LoadSettings(void) +{ + HKEY hKey = NULL; + TCHAR szBuffer[MAX_PATH]; + + if (RegOpenKey(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS) + { + RegistryBinaryConfig tConfig; + DWORD iBufferSize = sizeof(tConfig); + + if (RegQueryValueEx(hKey, L"View", NULL, NULL, (LPBYTE)&tConfig, &iBufferSize) == ERROR_SUCCESS) + { + if ( iBufferSize == sizeof(tConfig) ) + { + RECT rcTemp; + + /* Update status bar settings */ + CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|(tConfig.StatusBarVisible ? MF_CHECKED : MF_UNCHECKED)); + ShowWindow(hStatusBar, (tConfig.StatusBarVisible ? SW_SHOW : SW_HIDE)); + + /* Update listview column width */ + (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 0, tConfig.NameColumnSize); + (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 1, tConfig.TypeColumnSize); + (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 2, tConfig.DataColumnSize); + + /* Update treeview (splitter) */ + GetClientRect(hFrameWnd, &rcTemp); + g_pChildWnd->nSplitPos = tConfig.TreeViewSize; + ResizeWnd(rcTemp.right, rcTemp.bottom); + + /* Apply program window settings */ + tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT); + if (SetWindowPlacement(hFrameWnd, &tConfig.tPlacement) == FALSE) + /* In case we fail, show normal */ + ShowWindow(hFrameWnd, SW_SHOWNORMAL); + } + } + + /* Restore key position */ + if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("LastKey"), szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) + { + SelectNode(g_pChildWnd->hTreeWnd, szBuffer); + } + + RegCloseKey(hKey); + } + else + { + /* Failed to open key, show normal */ + ShowWindow(hFrameWnd, SW_SHOWNORMAL); + } +} + +extern void SaveSettings(void) +{ + HKEY hKey = NULL; + + if (RegCreateKey(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS) + { + if (RegOpenKey(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS) + { + RegistryBinaryConfig tConfig; + DWORD iBufferSize = sizeof(tConfig); + TCHAR szBuffer[MAX_PATH]; + LPCTSTR keyPath, rootName; + HKEY hRootKey; + + /* Save key position */ + keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); + if (keyPath) + { + rootName = get_root_key_name(hRootKey); + _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("My Computer\\%s\\%s"), rootName, keyPath); + RegSetValueEx(hKey, _T("LastKey"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) _tcslen(szBuffer) * sizeof(szBuffer[0])); + } + + /* Get statusbar settings */ + tConfig.StatusBarVisible = ((GetMenuState(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND) & MF_CHECKED) ? 1 : 0 ); + + /* Get splitter position */ + tConfig.TreeViewSize = g_pChildWnd->nSplitPos; + + /* Get list view column width*/ + tConfig.NameColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 0); + tConfig.TypeColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 1); + tConfig.DataColumnSize = ListView_GetColumnWidth(g_pChildWnd->hListWnd, 2); + + /* Get program window settings */ + tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(hFrameWnd , &tConfig.tPlacement); + + /* Save all the data */ + RegSetValueEx(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize); + + RegCloseKey(hKey); + } + } +}