4 * Copyright (C) 2012 Edijs Kolesnikovics <terminedijs@yahoo.com>
5 * Copyright (C) 2012 Grégori Macário Harbs <mysoft64bits at gmail dot com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 const TCHAR g_szGeneralRegKey
[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit");
27 VV,VV,VV,VV,WA,WA,WA,WA,WB,WB,WB,WB,R1,R1,R1,R1
28 R2,R2,R2,R2,R3,R3,R3,R3,R4,R4,R4,r4,LL,LL,LL,LL
29 TT,TT,TT,TT,RR,RR,RR,RR,BB,BB,BB,BB,SS,SS,SS,SS
30 NN,NN,NN,NN,KK,KK,KK,KK,DD,DD,DD,DD,SB,SB,SB,SB
32 VV = Version or Sanity? WINDOWPLACEMENT? (2C?)
33 WA = (0=restored / 1=maximized)
34 WB = (1=restored / 3=maximized)
36 R2 = ???? | either those are reserved unused or they will
37 R3 = ???? | have IP/INFO if connected to remote registry
39 LL = Left position of window
40 TT = top position of window
41 RR = right position of window
42 BB = bottom position of window
43 SS = size of key tree view (splitter)
44 NN = size of 'name' column
45 KK = size of 'type' column (kind)
46 DD = size of 'data' coumn
47 SB = status bar (1=visible / 0=hidden)
51 WINDOWPLACEMENT tPlacement
;
56 BOOL StatusBarVisible
;
57 } RegistryBinaryConfig
;
59 extern void LoadSettings(void)
62 TCHAR szBuffer
[MAX_PATH
];
64 if (RegOpenKey(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
66 RegistryBinaryConfig tConfig
;
67 DWORD iBufferSize
= sizeof(tConfig
);
69 if (RegQueryValueEx(hKey
, L
"View", NULL
, NULL
, (LPBYTE
)&tConfig
, &iBufferSize
) == ERROR_SUCCESS
)
71 if ( iBufferSize
== sizeof(tConfig
) )
75 /* Update status bar settings */
76 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|(tConfig
.StatusBarVisible
? MF_CHECKED
: MF_UNCHECKED
));
77 ShowWindow(hStatusBar
, (tConfig
.StatusBarVisible
? SW_SHOW
: SW_HIDE
));
79 /* Update listview column width */
80 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 0, tConfig
.NameColumnSize
);
81 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 1, tConfig
.TypeColumnSize
);
82 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 2, tConfig
.DataColumnSize
);
84 /* Update treeview (splitter) */
85 GetClientRect(hFrameWnd
, &rcTemp
);
86 g_pChildWnd
->nSplitPos
= tConfig
.TreeViewSize
;
87 ResizeWnd(rcTemp
.right
, rcTemp
.bottom
);
89 /* Apply program window settings */
90 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
91 if (SetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
) == FALSE
)
92 /* In case we fail, show normal */
93 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
97 /* Restore key position */
98 if (QueryStringValue(HKEY_CURRENT_USER
, g_szGeneralRegKey
, _T("LastKey"), szBuffer
, COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
100 SelectNode(g_pChildWnd
->hTreeWnd
, szBuffer
);
107 /* Failed to open key, show normal */
108 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
112 extern void SaveSettings(void)
116 if (RegCreateKey(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
118 if (RegOpenKey(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
120 RegistryBinaryConfig tConfig
;
121 DWORD iBufferSize
= sizeof(tConfig
);
122 TCHAR szBuffer
[MAX_PATH
];
123 LPCTSTR keyPath
, rootName
;
126 /* Save key position */
127 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
130 rootName
= get_root_key_name(hRootKey
);
131 _sntprintf(szBuffer
, COUNT_OF(szBuffer
), _T("My Computer\\%s\\%s"), rootName
, keyPath
);
132 RegSetValueEx(hKey
, _T("LastKey"), 0, REG_SZ
, (LPBYTE
) szBuffer
, (DWORD
) _tcslen(szBuffer
) * sizeof(szBuffer
[0]));
135 /* Get statusbar settings */
136 tConfig
.StatusBarVisible
= ((GetMenuState(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
) & MF_CHECKED
) ? 1 : 0 );
138 /* Get splitter position */
139 tConfig
.TreeViewSize
= g_pChildWnd
->nSplitPos
;
141 /* Get list view column width*/
142 tConfig
.NameColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 0);
143 tConfig
.TypeColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 1);
144 tConfig
.DataColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 2);
146 /* Get program window settings */
147 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
148 GetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
);
150 /* Save all the data */
151 RegSetValueEx(hKey
, L
"View", 0, REG_BINARY
, (LPBYTE
)&tConfig
, iBufferSize
);