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
25 const WCHAR g_szGeneralRegKey
[] = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit";
26 DECLSPEC_IMPORT ULONG WINAPIV
DbgPrint(PCH Format
,...);
29 VV,VV,VV,VV,WA,WA,WA,WA,WB,WB,WB,WB,R1,R1,R1,R1
30 R2,R2,R2,R2,R3,R3,R3,R3,R4,R4,R4,r4,LL,LL,LL,LL
31 TT,TT,TT,TT,RR,RR,RR,RR,BB,BB,BB,BB,SS,SS,SS,SS
32 NN,NN,NN,NN,KK,KK,KK,KK,DD,DD,DD,DD,SB,SB,SB,SB
34 VV = Version or Sanity? WINDOWPLACEMENT? (2C?)
35 WA = (0=restored / 1=maximized)
36 WB = (1=restored / 3=maximized)
38 R2 = ???? | either those are reserved unused or they will
39 R3 = ???? | have IP/INFO if connected to remote registry
41 LL = Left position of window
42 TT = top position of window
43 RR = right position of window
44 BB = bottom position of window
45 SS = size of key tree view (splitter)
46 NN = size of 'name' column
47 KK = size of 'type' column (kind)
48 DD = size of 'data' coumn
49 SB = status bar (1=visible / 0=hidden)
54 WINDOWPLACEMENT tPlacement
;
59 BOOL StatusBarVisible
;
60 } RegistryBinaryConfig
;
62 extern void LoadSettings(void)
65 WCHAR szBuffer
[MAX_PATH
];
67 if (RegOpenKeyW(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
69 RegistryBinaryConfig tConfig
;
70 DWORD iBufferSize
= sizeof(tConfig
);
71 BOOL bVisible
= FALSE
;
73 if (RegQueryValueExW(hKey
, L
"View", NULL
, NULL
, (LPBYTE
)&tConfig
, &iBufferSize
) == ERROR_SUCCESS
)
75 if (iBufferSize
== sizeof(tConfig
))
79 /* Update status bar settings */
80 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
| (tConfig
.StatusBarVisible
? MF_CHECKED
: MF_UNCHECKED
));
81 ShowWindow(hStatusBar
, (tConfig
.StatusBarVisible
? SW_SHOW
: SW_HIDE
));
83 /* Update listview column width */
84 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 0, tConfig
.NameColumnSize
);
85 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 1, tConfig
.TypeColumnSize
);
86 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 2, tConfig
.DataColumnSize
);
88 /* Update treeview (splitter) */
89 GetClientRect(hFrameWnd
, &rcTemp
);
90 g_pChildWnd
->nSplitPos
= tConfig
.TreeViewSize
;
91 ResizeWnd(rcTemp
.right
, rcTemp
.bottom
);
93 /* Apply program window settings */
94 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
95 bVisible
= SetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
);
99 /* In case we fail to restore the window, or open the key, show normal */
101 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
103 /* Restore key position */
104 if (QueryStringValue(HKEY_CURRENT_USER
, g_szGeneralRegKey
, L
"LastKey", szBuffer
, COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
106 SelectNode(g_pChildWnd
->hTreeWnd
, szBuffer
);
113 /* Failed to open key, show normal */
114 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
118 extern void SaveSettings(void)
122 if (RegCreateKeyW(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
124 RegistryBinaryConfig tConfig
;
125 DWORD iBufferSize
= sizeof(tConfig
);
126 WCHAR szBuffer
[MAX_PATH
]; /* FIXME: a complete registry path can be longer than that */
127 LPCWSTR keyPath
, rootName
;
130 /* Save key position */
131 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
132 rootName
= get_root_key_name(hRootKey
);
134 /* Load "My Computer" string and complete it */
135 if (LoadStringW(hInst
, IDS_MY_COMPUTER
, szBuffer
, COUNT_OF(szBuffer
)) &&
136 SUCCEEDED(StringCbCatW(szBuffer
, sizeof(szBuffer
), L
"\\")) &&
137 SUCCEEDED(StringCbCatW(szBuffer
, sizeof(szBuffer
), rootName
)) &&
138 SUCCEEDED(StringCbCatW(szBuffer
, sizeof(szBuffer
), L
"\\")))
142 hr
= StringCbCatW(szBuffer
, sizeof(szBuffer
), keyPath
);
144 RegSetValueExW(hKey
, L
"LastKey", 0, REG_SZ
, (LPBYTE
)szBuffer
, (DWORD
)wcslen(szBuffer
) * sizeof(WCHAR
));
146 DbgPrint("err: (%s:%d): Buffer not big enough for '%S + %S'\n", __FILE__
, __LINE__
, rootName
, keyPath
);
150 DbgPrint("err: (%s:%d): Buffer not big enough for '%S'\n", __FILE__
, __LINE__
, rootName
);
153 /* Get statusbar settings */
154 tConfig
.StatusBarVisible
= ((GetMenuState(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
) & MF_CHECKED
) ? 1 : 0);
156 /* Get splitter position */
157 tConfig
.TreeViewSize
= g_pChildWnd
->nSplitPos
;
159 /* Get list view column width*/
160 tConfig
.NameColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 0);
161 tConfig
.TypeColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 1);
162 tConfig
.DataColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 2);
164 /* Get program window settings */
165 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
166 GetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
);
168 /* Save all the data */
169 RegSetValueExW(hKey
, L
"View", 0, REG_BINARY
, (LPBYTE
)&tConfig
, iBufferSize
);