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";
25 DECLSPEC_IMPORT ULONG WINAPIV
DbgPrint(PCCH Format
,...);
28 VV,VV,VV,VV,WA,WA,WA,WA,WB,WB,WB,WB,R1,R1,R1,R1
29 R2,R2,R2,R2,R3,R3,R3,R3,R4,R4,R4,r4,LL,LL,LL,LL
30 TT,TT,TT,TT,RR,RR,RR,RR,BB,BB,BB,BB,SS,SS,SS,SS
31 NN,NN,NN,NN,KK,KK,KK,KK,DD,DD,DD,DD,SB,SB,SB,SB
33 VV = Version or Sanity? WINDOWPLACEMENT? (2C?)
34 WA = (0=restored / 1=maximized)
35 WB = (1=restored / 3=maximized)
37 R2 = ???? | either those are reserved unused or they will
38 R3 = ???? | have IP/INFO if connected to remote registry
40 LL = Left position of window
41 TT = top position of window
42 RR = right position of window
43 BB = bottom position of window
44 SS = size of key tree view (splitter)
45 NN = size of 'name' column
46 KK = size of 'type' column (kind)
47 DD = size of 'data' coumn
48 SB = status bar (1=visible / 0=hidden)
53 WINDOWPLACEMENT tPlacement
;
58 BOOL StatusBarVisible
;
59 } RegistryBinaryConfig
;
61 extern void LoadSettings(void)
64 WCHAR szBuffer
[MAX_PATH
];
66 if (RegOpenKeyW(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
68 RegistryBinaryConfig tConfig
;
69 DWORD iBufferSize
= sizeof(tConfig
);
70 BOOL bVisible
= FALSE
;
72 if (RegQueryValueExW(hKey
, L
"View", NULL
, NULL
, (LPBYTE
)&tConfig
, &iBufferSize
) == ERROR_SUCCESS
)
74 if (iBufferSize
== sizeof(tConfig
))
78 /* Update status bar settings */
79 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
| (tConfig
.StatusBarVisible
? MF_CHECKED
: MF_UNCHECKED
));
80 ShowWindow(hStatusBar
, (tConfig
.StatusBarVisible
? SW_SHOW
: SW_HIDE
));
82 /* Update listview column width */
83 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 0, tConfig
.NameColumnSize
);
84 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 1, tConfig
.TypeColumnSize
);
85 (void)ListView_SetColumnWidth(g_pChildWnd
->hListWnd
, 2, tConfig
.DataColumnSize
);
87 /* Update treeview (splitter) */
88 GetClientRect(hFrameWnd
, &rcTemp
);
89 g_pChildWnd
->nSplitPos
= tConfig
.TreeViewSize
;
90 ResizeWnd(rcTemp
.right
, rcTemp
.bottom
);
92 /* Apply program window settings */
93 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
94 bVisible
= SetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
);
98 /* In case we fail to restore the window, or open the key, show normal */
100 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
102 /* Restore key position */
103 if (QueryStringValue(HKEY_CURRENT_USER
, g_szGeneralRegKey
, L
"LastKey", szBuffer
, ARRAY_SIZE(szBuffer
)) == ERROR_SUCCESS
)
105 SelectNode(g_pChildWnd
->hTreeWnd
, szBuffer
);
112 /* Failed to open key, show normal */
113 ShowWindow(hFrameWnd
, SW_SHOWNORMAL
);
117 extern void SaveSettings(void)
121 if (RegCreateKeyW(HKEY_CURRENT_USER
, g_szGeneralRegKey
, &hKey
) == ERROR_SUCCESS
)
123 RegistryBinaryConfig tConfig
;
124 DWORD iBufferSize
= sizeof(tConfig
);
125 WCHAR szBuffer
[MAX_PATH
]; /* FIXME: a complete registry path can be longer than that */
126 LPCWSTR keyPath
, rootName
;
129 /* Save key position */
130 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, 0, &hRootKey
);
131 rootName
= get_root_key_name(hRootKey
);
133 /* Load "My Computer" string and complete it */
134 if (LoadStringW(hInst
, IDS_MY_COMPUTER
, szBuffer
, ARRAY_SIZE(szBuffer
)) &&
135 SUCCEEDED(StringCbCatW(szBuffer
, sizeof(szBuffer
), L
"\\")) &&
136 SUCCEEDED(StringCbCatW(szBuffer
, sizeof(szBuffer
), rootName
)) &&
137 SUCCEEDED(StringCbCatW(szBuffer
, sizeof(szBuffer
), L
"\\")))
141 hr
= StringCbCatW(szBuffer
, sizeof(szBuffer
), keyPath
);
143 RegSetValueExW(hKey
, L
"LastKey", 0, REG_SZ
, (LPBYTE
)szBuffer
, (DWORD
)wcslen(szBuffer
) * sizeof(WCHAR
));
145 DbgPrint("err: (%s:%d): Buffer not big enough for '%S + %S'\n", __FILE__
, __LINE__
, rootName
, keyPath
);
149 DbgPrint("err: (%s:%d): Buffer not big enough for '%S'\n", __FILE__
, __LINE__
, rootName
);
152 /* Get statusbar settings */
153 tConfig
.StatusBarVisible
= ((GetMenuState(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
) & MF_CHECKED
) ? 1 : 0);
155 /* Get splitter position */
156 tConfig
.TreeViewSize
= g_pChildWnd
->nSplitPos
;
158 /* Get list view column width*/
159 tConfig
.NameColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 0);
160 tConfig
.TypeColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 1);
161 tConfig
.DataColumnSize
= ListView_GetColumnWidth(g_pChildWnd
->hListWnd
, 2);
163 /* Get program window settings */
164 tConfig
.tPlacement
.length
= sizeof(WINDOWPLACEMENT
);
165 GetWindowPlacement(hFrameWnd
, &tConfig
.tPlacement
);
167 /* Save all the data */
168 RegSetValueExW(hKey
, L
"View", 0, REG_BINARY
, (LPBYTE
)&tConfig
, iBufferSize
);