2012-03-28 08:23:15 +00:00
|
|
|
|
/*
|
2012-10-01 23:16:43 +00:00
|
|
|
|
* Regedit settings
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2012 Edijs Kolesnikovics <terminedijs@yahoo.com>
|
|
|
|
|
* Copyright (C) 2012 Gr<EFBFBD>gori Mac<EFBFBD>rio Harbs <mysoft64bits at gmail dot com>
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
|
#include "regedit.h"
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
|
const WCHAR g_szGeneralRegKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit";
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
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)
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
WINDOWPLACEMENT tPlacement;
|
|
|
|
|
int TreeViewSize;
|
|
|
|
|
int NameColumnSize;
|
|
|
|
|
int TypeColumnSize;
|
|
|
|
|
int DataColumnSize;
|
|
|
|
|
BOOL StatusBarVisible;
|
2012-03-28 08:23:15 +00:00
|
|
|
|
} RegistryBinaryConfig;
|
|
|
|
|
|
|
|
|
|
extern void LoadSettings(void)
|
|
|
|
|
{
|
|
|
|
|
HKEY hKey = NULL;
|
2012-10-03 22:42:34 +00:00
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
|
if (RegOpenKeyW(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS)
|
2012-03-28 08:23:15 +00:00
|
|
|
|
{
|
|
|
|
|
RegistryBinaryConfig tConfig;
|
|
|
|
|
DWORD iBufferSize = sizeof(tConfig);
|
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
|
if (RegQueryValueExW(hKey, L"View", NULL, NULL, (LPBYTE)&tConfig, &iBufferSize) == ERROR_SUCCESS)
|
2012-03-28 08:23:15 +00:00
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
|
if (iBufferSize == sizeof(tConfig))
|
2012-03-28 08:23:15 +00:00
|
|
|
|
{
|
|
|
|
|
RECT rcTemp;
|
|
|
|
|
|
|
|
|
|
/* Update status bar settings */
|
2012-10-03 22:42:34 +00:00
|
|
|
|
CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND | (tConfig.StatusBarVisible ? MF_CHECKED : MF_UNCHECKED));
|
2012-03-28 08:23:15 +00:00
|
|
|
|
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 */
|
2012-10-03 22:42:34 +00:00
|
|
|
|
if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, L"LastKey", szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS)
|
2012-03-28 08:23:15 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
|
if (RegCreateKeyW(HKEY_CURRENT_USER, g_szGeneralRegKey, &hKey) == ERROR_SUCCESS)
|
2012-03-28 08:23:15 +00:00
|
|
|
|
{
|
2012-12-31 17:10:15 +00:00
|
|
|
|
RegistryBinaryConfig tConfig;
|
|
|
|
|
DWORD iBufferSize = sizeof(tConfig);
|
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
|
LPCWSTR keyPath, rootName;
|
|
|
|
|
HKEY hRootKey;
|
|
|
|
|
|
|
|
|
|
/* Save key position */
|
|
|
|
|
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
|
|
|
|
|
if (keyPath)
|
2012-03-28 08:23:15 +00:00
|
|
|
|
{
|
2012-12-31 17:10:15 +00:00
|
|
|
|
rootName = get_root_key_name(hRootKey);
|
2012-10-05 20:08:16 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
/* Load "My Computer" string and complete it */
|
|
|
|
|
LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, COUNT_OF(szBuffer));
|
|
|
|
|
wcscat(szBuffer, L"\\"); wcscat(szBuffer, rootName);
|
|
|
|
|
wcscat(szBuffer, L"\\"); wcscat(szBuffer, keyPath);
|
2012-10-05 20:08:16 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
RegSetValueExW(hKey, L"LastKey", 0, REG_SZ, (LPBYTE)szBuffer, (DWORD)wcslen(szBuffer) * sizeof(WCHAR));
|
|
|
|
|
}
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
/* Get statusbar settings */
|
|
|
|
|
tConfig.StatusBarVisible = ((GetMenuState(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND) & MF_CHECKED) ? 1 : 0);
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
/* Get splitter position */
|
|
|
|
|
tConfig.TreeViewSize = g_pChildWnd->nSplitPos;
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
/* 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);
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
/* Get program window settings */
|
|
|
|
|
tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
|
2013-06-29 19:05:15 +00:00
|
|
|
|
GetWindowPlacement(hFrameWnd, &tConfig.tPlacement);
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
/* Save all the data */
|
|
|
|
|
RegSetValueExW(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize);
|
2012-03-28 08:23:15 +00:00
|
|
|
|
|
2012-12-31 17:10:15 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2012-03-28 08:23:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-03 22:42:34 +00:00
|
|
|
|
/* EOF */
|