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 WCHAR g_szGeneralRegKey
[] = L
"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)
52 WINDOWPLACEMENT tPlacement
;
57 BOOL StatusBarVisible
;
58 } RegistryBinaryConfig
;
60 extern void LoadSettings(void)
63 WCHAR szBuffer
[MAX_PATH
];
65 if (RegOpenKeyW(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
67 RegistryBinaryConfig tConfig
;
68 DWORD iBufferSize
= sizeof(tConfig
);
70 if (RegQueryValueExW(hKey
, L
"View", NULL
, NULL
, (LPBYTE
)&tConfig
, &iBufferSize
) == ERROR_SUCCESS
)
72 if (iBufferSize
== sizeof(tConfig
))
76 /* Update status bar settings */
77 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
| (tConfig
.StatusBarVisible
? MF_CHECKED
: MF_UNCHECKED
));
78 ShowWindow(hStatusBar
, (tConfig
.StatusBarVisible
? SW_SHOW
: SW_HIDE
));
80 /* Update listview column width */
81 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 0, tConfig
.NameColumnSize
);
82 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 1, tConfig
.TypeColumnSize
);
83 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 2, tConfig
.DataColumnSize
);
85 /* Update treeview (splitter) */
86 GetClientRect(hFrameWnd
, &rcTemp
);
87 g_pChildWnd
->nSplitPos
= tConfig
.TreeViewSize
;
88 ResizeWnd(rcTemp
.right
, rcTemp
.bottom
);
90 /* Apply program window settings */
91 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
92 if (SetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
) == FALSE
)
93 /* In case we fail, show normal */
94 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
98 /* Restore key position */
99 if (QueryStringValue(HKEY_CURRENT_USER
, g_szGeneralRegKey
, L
"LastKey", szBuffer
, COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
101 SelectNode(g_pChildWnd
->hTreeWnd
, szBuffer
);
108 /* Failed to open key, show normal */
109 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
113 extern void SaveSettings(void)
117 if (RegCreateKeyW(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
119 RegistryBinaryConfig tConfig
;
120 DWORD iBufferSize
= sizeof(tConfig
);
121 WCHAR szBuffer
[MAX_PATH
];
122 LPCWSTR keyPath
, rootName
;
125 /* Save key position */
126 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
129 rootName
= get_root_key_name(hRootKey
);
131 /* Load "My Computer" string and complete it */
132 LoadStringW(hInst
, IDS_MY_COMPUTER
, szBuffer
, COUNT_OF(szBuffer
));
133 wcscat(szBuffer
, L
"\\"); wcscat(szBuffer
, rootName
);
134 wcscat(szBuffer
, L
"\\"); wcscat(szBuffer
, keyPath
);
136 RegSetValueExW(hKey
, L
"LastKey", 0, REG_SZ
, (LPBYTE
)szBuffer
, (DWORD
)wcslen(szBuffer
) * sizeof(WCHAR
));
139 /* Get statusbar settings */
140 tConfig
.StatusBarVisible
= ((GetMenuState(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
) & MF_CHECKED
) ? 1 : 0);
142 /* Get splitter position */
143 tConfig
.TreeViewSize
= g_pChildWnd
->nSplitPos
;
145 /* Get list view column width*/
146 tConfig
.NameColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 0);
147 tConfig
.TypeColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 1);
148 tConfig
.DataColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 2);
150 /* Get program window settings */
151 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
152 GetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
);
154 /* Save all the data */
155 RegSetValueExW(hKey
, L
"View", 0, REG_BINARY
, (LPBYTE
)&tConfig
, iBufferSize
);