2002-07-14 17:59:36 +00:00
|
|
|
/*
|
2003-08-22 05:55:14 +00:00
|
|
|
* Regedit treeview
|
2002-07-14 17:59:36 +00:00
|
|
|
*
|
2003-08-22 05:55:14 +00:00
|
|
|
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
2002-07-14 17:59:36 +00:00
|
|
|
*
|
2002-11-12 15:25:15 +00:00
|
|
|
* 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.
|
2002-07-14 17:59:36 +00:00
|
|
|
*
|
2002-11-12 15:25:15 +00:00
|
|
|
* 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.
|
2002-07-14 17:59:36 +00:00
|
|
|
*
|
2002-11-12 15:25:15 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-10-27 10:34:16 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-07-14 17:59:36 +00:00
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "regedit.h"
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Global variables and constants */
|
|
|
|
/* Image_Open, Image_Closed, and Image_Root - integer variables for indexes of the images. */
|
2004-01-01 15:12:11 +00:00
|
|
|
/* CX_ICON and CY_ICON - width and height of an icon. */
|
|
|
|
/* NUM_ICON - number of icons to add to the image list. */
|
2008-08-09 16:40:43 +00:00
|
|
|
static int Image_Open = 0;
|
|
|
|
static int Image_Closed = 0;
|
|
|
|
static int Image_Root = 0;
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
static LPWSTR pathBuffer;
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
#define NUM_ICONS 3
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2022-11-02 22:38:05 +00:00
|
|
|
/* External resources in shell32.dll */
|
|
|
|
#define IDI_SHELL_FOLDER 4
|
|
|
|
#define IDI_SHELL_FOLDER_OPEN 5
|
|
|
|
#define IDI_SHELL_MY_COMPUTER 16
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPWSTR* pKeyPath, int* pPathLen, int* pMaxLen)
|
2002-07-18 18:16:42 +00:00
|
|
|
{
|
2013-01-01 19:38:47 +00:00
|
|
|
TVITEMW item;
|
2006-08-22 20:06:30 +00:00
|
|
|
size_t maxLen, len;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPWSTR newStr;
|
2004-01-01 15:12:11 +00:00
|
|
|
|
2002-07-18 18:16:42 +00:00
|
|
|
item.mask = TVIF_PARAM;
|
2004-01-01 15:12:11 +00:00
|
|
|
item.hItem = hItem;
|
|
|
|
if (!TreeView_GetItem(hwndTV, &item)) return FALSE;
|
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
if (item.lParam)
|
|
|
|
{
|
|
|
|
/* found root key with valid key value */
|
|
|
|
*phKey = (HKEY)item.lParam;
|
|
|
|
return TRUE;
|
2004-01-01 15:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!get_item_path(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxLen)) return FALSE;
|
2010-12-07 21:49:25 +00:00
|
|
|
if (*pPathLen)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
(*pKeyPath)[*pPathLen] = L'\\';
|
2004-01-01 15:12:11 +00:00
|
|
|
++(*pPathLen);
|
2002-07-18 18:16:42 +00:00
|
|
|
}
|
2004-01-01 15:12:11 +00:00
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
do
|
|
|
|
{
|
2004-01-01 15:12:11 +00:00
|
|
|
item.mask = TVIF_TEXT;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.pszText = *pKeyPath + *pPathLen;
|
2006-08-22 20:06:30 +00:00
|
|
|
maxLen = *pMaxLen - *pPathLen;
|
|
|
|
item.cchTextMax = (int) maxLen;
|
2004-01-01 15:12:11 +00:00
|
|
|
if (!TreeView_GetItem(hwndTV, &item)) return FALSE;
|
2012-10-03 22:42:34 +00:00
|
|
|
len = wcslen(item.pszText);
|
2010-12-07 21:49:25 +00:00
|
|
|
if (len < maxLen - 1)
|
|
|
|
{
|
2006-08-22 20:06:30 +00:00
|
|
|
*pPathLen += (int) len;
|
2004-01-01 15:12:11 +00:00
|
|
|
break;
|
2010-12-07 21:49:25 +00:00
|
|
|
}
|
|
|
|
newStr = HeapReAlloc(GetProcessHeap(), 0, *pKeyPath, *pMaxLen * 2);
|
|
|
|
if (!newStr) return FALSE;
|
|
|
|
*pKeyPath = newStr;
|
|
|
|
*pMaxLen *= 2;
|
|
|
|
}
|
|
|
|
while(TRUE);
|
2004-01-01 15:12:11 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
|
2004-01-01 15:12:11 +00:00
|
|
|
{
|
|
|
|
int pathLen = 0, maxLen;
|
|
|
|
|
|
|
|
*phRootKey = NULL;
|
2023-05-18 10:16:49 +00:00
|
|
|
|
|
|
|
if (!pathBuffer)
|
|
|
|
{
|
|
|
|
pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024);
|
|
|
|
}
|
|
|
|
if (!pathBuffer)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pathBuffer = UNICODE_NULL;
|
|
|
|
|
2006-08-22 20:06:30 +00:00
|
|
|
maxLen = (int) HeapSize(GetProcessHeap(), 0, pathBuffer);
|
2023-05-18 10:16:49 +00:00
|
|
|
|
|
|
|
if (!hItem)
|
|
|
|
{
|
|
|
|
hItem = TreeView_GetSelection(hwndTV);
|
|
|
|
}
|
|
|
|
if (maxLen == -1 || !hItem || !get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen))
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-01-01 15:12:11 +00:00
|
|
|
return pathBuffer;
|
2002-07-18 18:16:42 +00:00
|
|
|
}
|
|
|
|
|
2005-11-26 20:22:45 +00:00
|
|
|
BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem)
|
|
|
|
{
|
|
|
|
if (!hItem) hItem = TreeView_GetSelection(hwndTV);
|
|
|
|
if (!hItem) return FALSE;
|
|
|
|
return TreeView_DeleteItem(hwndTV, hItem);
|
|
|
|
}
|
|
|
|
|
2005-09-26 03:18:53 +00:00
|
|
|
/* Add an entry to the tree. Only give hKey for root nodes (HKEY_ constants) */
|
2012-10-03 22:42:34 +00:00
|
|
|
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
|
2003-08-22 05:55:14 +00:00
|
|
|
{
|
2013-01-01 19:38:47 +00:00
|
|
|
TVITEMW tvi;
|
|
|
|
TVINSERTSTRUCTW tvins;
|
2003-08-22 05:55:14 +00:00
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
if (hKey)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwChildren, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
dwChildren = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
|
|
|
|
tvi.pszText = label;
|
2012-10-03 22:42:34 +00:00
|
|
|
tvi.cchTextMax = wcslen(tvi.pszText);
|
2003-08-22 05:55:14 +00:00
|
|
|
tvi.iImage = Image_Closed;
|
|
|
|
tvi.iSelectedImage = Image_Open;
|
|
|
|
tvi.cChildren = dwChildren;
|
2002-07-18 18:16:42 +00:00
|
|
|
tvi.lParam = (LPARAM)hKey;
|
- Get autochk, calc, cmd, devmgr, expand, format, gettype, hostname, lsass, msconfig, msiexec, notepad, reactos, regedit, regsvr32, reporterror, rundll32, sc, services, servman, setup, sm, sndvol32 compiling on MSVC.
- PCHify some things.
- Reduce NDK usage.
svn path=/trunk/; revision=20703
2006-01-08 10:05:37 +00:00
|
|
|
tvins.item = tvi;
|
2005-09-29 00:50:40 +00:00
|
|
|
tvins.hInsertAfter = (HTREEITEM)(hKey ? TVI_LAST : TVI_FIRST);
|
2003-08-22 05:55:14 +00:00
|
|
|
tvins.hParent = hParent;
|
2004-01-01 15:12:11 +00:00
|
|
|
return TreeView_InsertItem(hwndTV, &tvins);
|
2002-07-14 17:59:36 +00:00
|
|
|
}
|
2002-07-15 20:00:02 +00:00
|
|
|
|
2005-11-22 01:30:30 +00:00
|
|
|
BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
|
2005-09-26 03:18:53 +00:00
|
|
|
{
|
|
|
|
HKEY hRoot, hKey, hSubKey;
|
|
|
|
HTREEITEM childItem;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPCWSTR KeyPath;
|
2005-09-26 03:18:53 +00:00
|
|
|
DWORD dwCount, dwIndex, dwMaxSubKeyLen;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPWSTR Name = NULL;
|
2013-01-01 19:38:47 +00:00
|
|
|
TVITEMW tvItem;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPWSTR pszNodes = NULL;
|
2005-09-27 13:47:46 +00:00
|
|
|
BOOL bSuccess = FALSE;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPWSTR s;
|
2005-09-29 00:50:40 +00:00
|
|
|
BOOL bAddedAny;
|
2005-09-27 13:47:46 +00:00
|
|
|
|
2005-09-26 03:18:53 +00:00
|
|
|
KeyPath = GetItemPath(hwndTV, hItem, &hRoot);
|
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
if (*KeyPath)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
if (RegOpenKeyExW(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
goto done;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
2010-12-07 21:49:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
hKey = hRoot;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
goto done;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the number of children again */
|
|
|
|
tvItem.mask = TVIF_CHILDREN;
|
|
|
|
tvItem.hItem = hItem;
|
|
|
|
tvItem.cChildren = dwCount;
|
2010-12-07 21:49:25 +00:00
|
|
|
if (!TreeView_SetItem(hwndTV, &tvItem))
|
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
goto done;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't have to bother with the rest if it's not expanded. */
|
2010-12-07 21:49:25 +00:00
|
|
|
if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDED) == 0)
|
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
RegCloseKey(hKey);
|
2005-09-27 13:47:46 +00:00
|
|
|
bSuccess = TRUE;
|
|
|
|
goto done;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dwMaxSubKeyLen++; /* account for the \0 terminator */
|
2012-10-03 22:42:34 +00:00
|
|
|
if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR))))
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
goto done;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
tvItem.cchTextMax = dwMaxSubKeyLen;
|
2012-10-03 22:42:34 +00:00
|
|
|
/*if (!(tvItem.pszText = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR)))) {
|
2005-09-27 13:47:46 +00:00
|
|
|
goto done;
|
2005-10-17 15:17:54 +00:00
|
|
|
}*/
|
2005-09-27 13:47:46 +00:00
|
|
|
|
|
|
|
/* Get all of the tree node siblings in one contiguous block of memory */
|
|
|
|
{
|
|
|
|
DWORD dwPhysicalSize = 0;
|
|
|
|
DWORD dwActualSize = 0;
|
|
|
|
DWORD dwNewPhysicalSize;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPWSTR pszNewNodes;
|
2005-09-27 13:47:46 +00:00
|
|
|
DWORD dwStep = 10000;
|
|
|
|
|
|
|
|
for (childItem = TreeView_GetChild(hwndTV, hItem); childItem;
|
2010-12-07 21:49:25 +00:00
|
|
|
childItem = TreeView_GetNextSibling(hwndTV, childItem))
|
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
|
|
|
|
if (dwActualSize + dwMaxSubKeyLen + 1 > dwPhysicalSize)
|
|
|
|
{
|
|
|
|
dwNewPhysicalSize = dwActualSize + dwMaxSubKeyLen + 1 + dwStep;
|
|
|
|
|
|
|
|
if (pszNodes)
|
2012-10-03 22:42:34 +00:00
|
|
|
pszNewNodes = (LPWSTR) HeapReAlloc(GetProcessHeap(), 0, pszNodes, dwNewPhysicalSize * sizeof(WCHAR));
|
2005-09-27 13:47:46 +00:00
|
|
|
else
|
2012-10-03 22:42:34 +00:00
|
|
|
pszNewNodes = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwNewPhysicalSize * sizeof(WCHAR));
|
2005-09-27 13:47:46 +00:00
|
|
|
if (!pszNewNodes)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
dwPhysicalSize = dwNewPhysicalSize;
|
|
|
|
pszNodes = pszNewNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
tvItem.mask = TVIF_TEXT;
|
|
|
|
tvItem.hItem = childItem;
|
|
|
|
tvItem.pszText = &pszNodes[dwActualSize];
|
|
|
|
tvItem.cchTextMax = dwPhysicalSize - dwActualSize;
|
|
|
|
if (!TreeView_GetItem(hwndTV, &tvItem))
|
|
|
|
goto done;
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
dwActualSize += (DWORD) wcslen(&pszNodes[dwActualSize]) + 1;
|
2005-09-27 13:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pszNodes)
|
2012-10-03 22:42:34 +00:00
|
|
|
pszNodes[dwActualSize] = L'\0';
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
|
2007-09-30 13:31:44 +00:00
|
|
|
/* Now go through all the children in the tree, and check if any have to be removed. */
|
|
|
|
childItem = TreeView_GetChild(hwndTV, hItem);
|
2010-12-07 21:49:25 +00:00
|
|
|
while (childItem)
|
|
|
|
{
|
2007-09-30 13:31:44 +00:00
|
|
|
HTREEITEM nextItem = TreeView_GetNextSibling(hwndTV, childItem);
|
2010-12-07 21:49:25 +00:00
|
|
|
if (RefreshTreeItem(hwndTV, childItem) == FALSE)
|
|
|
|
{
|
2007-09-30 13:31:44 +00:00
|
|
|
(void)TreeView_DeleteItem(hwndTV, childItem);
|
|
|
|
}
|
|
|
|
childItem = nextItem;
|
|
|
|
}
|
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
/* Now go through all the children in the registry, and check if any have to be added. */
|
2005-09-29 00:50:40 +00:00
|
|
|
bAddedAny = FALSE;
|
2010-12-07 21:49:25 +00:00
|
|
|
for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
|
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
DWORD cName = dwMaxSubKeyLen, dwSubCount;
|
|
|
|
BOOL found;
|
|
|
|
|
|
|
|
found = FALSE;
|
2012-10-03 22:42:34 +00:00
|
|
|
if (RegEnumKeyExW(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the node is already in there. */
|
2010-12-07 21:49:25 +00:00
|
|
|
if (pszNodes)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
for (s = pszNodes; *s; s += wcslen(s) + 1)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
if (!wcscmp(s, Name))
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
if (found == FALSE)
|
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
/* Find the number of children of the node. */
|
|
|
|
dwSubCount = 0;
|
2012-10-03 22:42:34 +00:00
|
|
|
if (RegOpenKeyExW(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
if (RegQueryInfoKeyW(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2005-09-27 13:47:46 +00:00
|
|
|
dwSubCount = 0;
|
|
|
|
}
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
}
|
|
|
|
|
2005-09-26 03:18:53 +00:00
|
|
|
AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount);
|
2005-09-29 00:50:40 +00:00
|
|
|
bAddedAny = TRUE;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
2005-09-29 00:50:40 +00:00
|
|
|
if (bAddedAny)
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM) hItem);
|
2005-09-29 00:50:40 +00:00
|
|
|
|
2005-09-27 13:47:46 +00:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (pszNodes)
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszNodes);
|
|
|
|
if (Name)
|
|
|
|
HeapFree(GetProcessHeap(), 0, Name);
|
|
|
|
return bSuccess;
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL RefreshTreeView(HWND hwndTV)
|
|
|
|
{
|
|
|
|
HTREEITEM hItem;
|
|
|
|
HTREEITEM hSelectedItem;
|
|
|
|
HCURSOR hcursorOld;
|
|
|
|
|
|
|
|
hSelectedItem = TreeView_GetSelection(hwndTV);
|
|
|
|
hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
|
2005-09-26 03:18:53 +00:00
|
|
|
|
|
|
|
hItem = TreeView_GetChild(hwndTV, TreeView_GetRoot(hwndTV));
|
2010-12-07 21:49:25 +00:00
|
|
|
while (hItem)
|
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
RefreshTreeItem(hwndTV, hItem);
|
|
|
|
hItem = TreeView_GetNextSibling(hwndTV, hItem);
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0);
|
2005-09-26 03:18:53 +00:00
|
|
|
SetCursor(hcursorOld);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-09-26 03:18:53 +00:00
|
|
|
/* We reselect the currently selected node, this will prompt a refresh of the listview. */
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)TreeView_SelectItem(hwndTV, hSelectedItem);
|
2005-09-26 03:18:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name)
|
2005-09-26 03:18:53 +00:00
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
WCHAR buf[MAX_NEW_KEY_LEN];
|
2005-09-26 03:18:53 +00:00
|
|
|
HTREEITEM hNewItem = 0;
|
2013-01-01 19:38:47 +00:00
|
|
|
TVITEMEXW item;
|
2005-09-26 03:18:53 +00:00
|
|
|
|
2005-11-22 01:30:30 +00:00
|
|
|
/* Default to the current selection */
|
|
|
|
if (!hItem)
|
|
|
|
{
|
|
|
|
hItem = TreeView_GetSelection(hwndTV);
|
|
|
|
if (!hItem)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&item, 0, sizeof(item));
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_STATE;
|
|
|
|
if (!TreeView_GetItem(hwndTV, &item))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-05-18 10:16:49 +00:00
|
|
|
if (item.state & TVIS_EXPANDEDONCE)
|
2005-11-22 01:30:30 +00:00
|
|
|
{
|
|
|
|
hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0);
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM) hItem);
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
2010-12-07 21:49:25 +00:00
|
|
|
else
|
2005-11-22 01:30:30 +00:00
|
|
|
{
|
|
|
|
item.mask = TVIF_CHILDREN | TVIF_HANDLE;
|
|
|
|
item.hItem = hItem;
|
|
|
|
item.cChildren = 1;
|
|
|
|
if (!TreeView_SetItem(hwndTV, &item))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)TreeView_Expand(hwndTV, hItem, TVE_EXPAND);
|
2005-11-22 01:30:30 +00:00
|
|
|
if (!hNewItem)
|
|
|
|
{
|
|
|
|
for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem))
|
|
|
|
{
|
|
|
|
item.mask = TVIF_HANDLE | TVIF_TEXT;
|
|
|
|
item.hItem = hNewItem;
|
|
|
|
item.pszText = buf;
|
2022-11-02 18:02:14 +00:00
|
|
|
item.cchTextMax = ARRAY_SIZE(buf);
|
2005-11-22 01:30:30 +00:00
|
|
|
if (!TreeView_GetItem(hwndTV, &item)) continue;
|
2012-10-03 22:42:34 +00:00
|
|
|
if (wcscmp(name, item.pszText) == 0) break;
|
2007-10-19 23:21:45 +00:00
|
|
|
}
|
2005-09-26 03:18:53 +00:00
|
|
|
}
|
2006-03-04 17:27:40 +00:00
|
|
|
if (hNewItem) (void)TreeView_SelectItem(hwndTV, hNewItem);
|
2005-09-26 03:18:53 +00:00
|
|
|
|
|
|
|
return hNewItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND StartKeyRename(HWND hwndTV)
|
|
|
|
{
|
|
|
|
HTREEITEM hItem;
|
|
|
|
|
|
|
|
if(!(hItem = TreeView_GetSelection(hwndTV))) return 0;
|
|
|
|
return TreeView_EditLabel(hwndTV, hItem);
|
|
|
|
}
|
2002-07-15 20:00:02 +00:00
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
static BOOL InitTreeViewItems(HWND hwndTV, LPWSTR pHostName)
|
2003-08-22 05:55:14 +00:00
|
|
|
{
|
2013-01-01 19:38:47 +00:00
|
|
|
TVITEMW tvi;
|
|
|
|
TVINSERTSTRUCTW tvins;
|
2003-08-22 05:55:14 +00:00
|
|
|
HTREEITEM hRoot;
|
|
|
|
|
|
|
|
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
|
|
|
|
/* Set the text of the item. */
|
|
|
|
tvi.pszText = pHostName;
|
2012-10-03 22:42:34 +00:00
|
|
|
tvi.cchTextMax = wcslen(tvi.pszText);
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Assume the item is not a parent item, so give it an image. */
|
|
|
|
tvi.iImage = Image_Root;
|
|
|
|
tvi.iSelectedImage = Image_Root;
|
|
|
|
tvi.cChildren = 5;
|
|
|
|
/* Save the heading level in the item's application-defined data area. */
|
2002-07-18 18:16:42 +00:00
|
|
|
tvi.lParam = (LPARAM)NULL;
|
- Get autochk, calc, cmd, devmgr, expand, format, gettype, hostname, lsass, msconfig, msiexec, notepad, reactos, regedit, regsvr32, reporterror, rundll32, sc, services, servman, setup, sm, sndvol32 compiling on MSVC.
- PCHify some things.
- Reduce NDK usage.
svn path=/trunk/; revision=20703
2006-01-08 10:05:37 +00:00
|
|
|
tvins.item = tvi;
|
2003-08-22 05:55:14 +00:00
|
|
|
tvins.hInsertAfter = (HTREEITEM)TVI_FIRST;
|
|
|
|
tvins.hParent = TVI_ROOT;
|
|
|
|
/* Add the item to the tree view control. */
|
2004-01-01 15:12:11 +00:00
|
|
|
if (!(hRoot = TreeView_InsertItem(hwndTV, &tvins))) return FALSE;
|
2002-07-16 22:18:29 +00:00
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_CLASSES_ROOT", HKEY_CLASSES_ROOT, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_CURRENT_USER", HKEY_CURRENT_USER, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_LOCAL_MACHINE", HKEY_LOCAL_MACHINE, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_USERS", HKEY_USERS, 1)) return FALSE;
|
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_CURRENT_CONFIG", HKEY_CURRENT_CONFIG, 1)) return FALSE;
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
if (GetVersion() & 0x80000000)
|
2005-09-26 03:18:53 +00:00
|
|
|
{
|
|
|
|
/* Win9x specific key */
|
2012-10-03 22:42:34 +00:00
|
|
|
if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_DYN_DATA", HKEY_DYN_DATA, 1)) return FALSE;
|
2010-12-07 21:49:25 +00:00
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2004-01-03 15:59:46 +00:00
|
|
|
/* expand and select host name */
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)TreeView_Expand(hwndTV, hRoot, TVE_EXPAND);
|
|
|
|
(void)TreeView_Select(hwndTV, hRoot, TVGN_CARET);
|
2003-08-22 05:55:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-07-15 20:00:02 +00:00
|
|
|
|
2004-01-01 15:12:11 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/*
|
|
|
|
* InitTreeViewImageLists - creates an image list, adds three bitmaps
|
|
|
|
* to it, and associates the image list with a tree view control.
|
|
|
|
* Returns TRUE if successful, or FALSE otherwise.
|
|
|
|
* hwndTV - handle to the tree view control.
|
|
|
|
*/
|
|
|
|
static BOOL InitTreeViewImageLists(HWND hwndTV)
|
|
|
|
{
|
|
|
|
HIMAGELIST himl; /* handle to image list */
|
2004-01-01 15:12:11 +00:00
|
|
|
HICON hico; /* handle to icon */
|
2022-11-02 18:02:14 +00:00
|
|
|
INT cx = GetSystemMetrics(SM_CXSMICON);
|
|
|
|
INT cy = GetSystemMetrics(SM_CYSMICON);
|
2022-11-02 22:38:05 +00:00
|
|
|
HMODULE hShell32 = GetModuleHandleW(L"shell32.dll");
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Create the image list. */
|
2022-11-02 20:17:40 +00:00
|
|
|
if ((himl = ImageList_Create(cx, cy, ILC_MASK | ILC_COLOR32, 0, NUM_ICONS)) == NULL)
|
2003-08-22 05:55:14 +00:00
|
|
|
return FALSE;
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Add the open file, closed file, and document bitmaps. */
|
2022-11-02 22:38:05 +00:00
|
|
|
hico = LoadImageW(hShell32,
|
|
|
|
MAKEINTRESOURCEW(IDI_SHELL_FOLDER_OPEN),
|
2012-10-03 22:42:34 +00:00
|
|
|
IMAGE_ICON,
|
2022-11-02 22:38:05 +00:00
|
|
|
cx,
|
|
|
|
cy,
|
|
|
|
LR_DEFAULTCOLOR);
|
2008-08-09 16:40:43 +00:00
|
|
|
if (hico)
|
|
|
|
{
|
2010-12-07 21:49:25 +00:00
|
|
|
Image_Open = ImageList_AddIcon(himl, hico);
|
|
|
|
DestroyIcon(hico);
|
2008-08-09 16:40:43 +00:00
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2022-11-02 22:38:05 +00:00
|
|
|
hico = LoadImageW(hShell32,
|
|
|
|
MAKEINTRESOURCEW(IDI_SHELL_FOLDER),
|
2012-10-03 22:42:34 +00:00
|
|
|
IMAGE_ICON,
|
2022-11-02 22:38:05 +00:00
|
|
|
cx,
|
|
|
|
cy,
|
|
|
|
LR_DEFAULTCOLOR);
|
2008-08-09 16:40:43 +00:00
|
|
|
if (hico)
|
|
|
|
{
|
2010-12-07 21:49:25 +00:00
|
|
|
Image_Closed = ImageList_AddIcon(himl, hico);
|
|
|
|
DestroyIcon(hico);
|
2008-08-09 16:40:43 +00:00
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2022-11-02 22:38:05 +00:00
|
|
|
hico = LoadImageW(hShell32,
|
|
|
|
MAKEINTRESOURCEW(IDI_SHELL_MY_COMPUTER),
|
2012-10-03 22:42:34 +00:00
|
|
|
IMAGE_ICON,
|
2022-11-02 22:38:05 +00:00
|
|
|
cx,
|
|
|
|
cy,
|
|
|
|
LR_DEFAULTCOLOR);
|
2008-08-09 16:40:43 +00:00
|
|
|
if (hico)
|
|
|
|
{
|
2010-12-07 21:49:25 +00:00
|
|
|
Image_Root = ImageList_AddIcon(himl, hico);
|
|
|
|
DestroyIcon(hico);
|
2008-08-09 16:40:43 +00:00
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Fail if not all of the images were added. */
|
2004-01-01 15:12:11 +00:00
|
|
|
if (ImageList_GetImageCount(himl) < NUM_ICONS)
|
|
|
|
{
|
2008-08-09 16:40:43 +00:00
|
|
|
ImageList_Destroy(himl);
|
|
|
|
return FALSE;
|
2004-01-01 15:12:11 +00:00
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Associate the image list with the tree view control. */
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2002-07-18 18:16:42 +00:00
|
|
|
BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
|
2003-08-22 05:55:14 +00:00
|
|
|
{
|
2004-01-01 15:12:11 +00:00
|
|
|
DWORD dwCount, dwIndex, dwMaxSubKeyLen;
|
|
|
|
HKEY hRoot, hNewKey, hKey;
|
2012-10-03 22:42:34 +00:00
|
|
|
LPCWSTR keyPath;
|
|
|
|
LPWSTR Name;
|
2004-01-01 15:12:11 +00:00
|
|
|
LONG errCode;
|
2004-07-01 23:56:04 +00:00
|
|
|
HCURSOR hcursorOld;
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2002-07-18 18:16:42 +00:00
|
|
|
static int expanding;
|
2002-07-14 17:59:36 +00:00
|
|
|
if (expanding) return FALSE;
|
2010-12-07 21:49:25 +00:00
|
|
|
if (pnmtv->itemNew.state & TVIS_EXPANDEDONCE )
|
|
|
|
{
|
2002-07-18 18:16:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
expanding = TRUE;
|
2004-07-01 23:56:04 +00:00
|
|
|
hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
|
2002-07-18 18:16:42 +00:00
|
|
|
|
2004-01-01 15:12:11 +00:00
|
|
|
keyPath = GetItemPath(hwndTV, pnmtv->itemNew.hItem, &hRoot);
|
|
|
|
if (!keyPath) goto done;
|
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
if (*keyPath)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
errCode = RegOpenKeyExW(hRoot, keyPath, 0, KEY_READ, &hNewKey);
|
2004-01-01 15:12:11 +00:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
2010-12-07 21:49:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hNewKey = hRoot;
|
2002-07-18 18:16:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
errCode = RegQueryInfoKeyW(hNewKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0);
|
2004-01-01 15:12:11 +00:00
|
|
|
if (errCode != ERROR_SUCCESS) goto done;
|
|
|
|
dwMaxSubKeyLen++; /* account for the \0 terminator */
|
2012-10-03 22:42:34 +00:00
|
|
|
Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR));
|
2004-01-01 15:12:11 +00:00
|
|
|
if (!Name) goto done;
|
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
|
|
|
|
{
|
2005-09-26 03:18:53 +00:00
|
|
|
DWORD cName = dwMaxSubKeyLen, dwSubCount;
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
errCode = RegEnumKeyExW(hNewKey, dwIndex, Name, &cName, 0, 0, 0, 0);
|
2005-09-26 03:18:53 +00:00
|
|
|
if (errCode != ERROR_SUCCESS) continue;
|
2012-10-03 22:42:34 +00:00
|
|
|
errCode = RegOpenKeyExW(hNewKey, Name, 0, KEY_QUERY_VALUE, &hKey);
|
2010-12-07 21:49:25 +00:00
|
|
|
if (errCode == ERROR_SUCCESS)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
errCode = RegQueryInfoKeyW(hKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0);
|
2005-09-26 03:18:53 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
if (errCode != ERROR_SUCCESS) dwSubCount = 0;
|
|
|
|
AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount);
|
2002-07-15 20:00:02 +00:00
|
|
|
}
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM)pnmtv->itemNew.hItem);
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2004-01-01 15:12:11 +00:00
|
|
|
RegCloseKey(hNewKey);
|
|
|
|
HeapFree(GetProcessHeap(), 0, Name);
|
|
|
|
|
|
|
|
done:
|
2012-10-03 22:42:34 +00:00
|
|
|
SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0);
|
2004-07-01 23:56:04 +00:00
|
|
|
SetCursor(hcursorOld);
|
2002-07-14 17:59:36 +00:00
|
|
|
expanding = FALSE;
|
2004-01-01 15:12:11 +00:00
|
|
|
|
2002-07-14 17:59:36 +00:00
|
|
|
return TRUE;
|
2003-08-22 05:55:14 +00:00
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
|
2004-01-01 15:12:11 +00:00
|
|
|
|
2005-09-22 20:54:20 +00:00
|
|
|
BOOL CreateNewKey(HWND hwndTV, HTREEITEM hItem)
|
|
|
|
{
|
2012-10-03 22:42:34 +00:00
|
|
|
WCHAR szNewKeyFormat[128];
|
|
|
|
WCHAR szNewKey[128];
|
|
|
|
LPCWSTR pszKeyPath;
|
2005-09-22 20:54:20 +00:00
|
|
|
int iIndex = 1;
|
2010-07-28 19:13:24 +00:00
|
|
|
LONG nResult;
|
|
|
|
HKEY hRootKey = NULL, hKey = NULL, hNewKey = NULL;
|
2005-09-22 20:54:20 +00:00
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
DWORD dwDisposition;
|
|
|
|
HTREEITEM hNewItem;
|
|
|
|
|
2010-07-28 19:13:24 +00:00
|
|
|
pszKeyPath = GetItemPath(hwndTV, hItem, &hRootKey);
|
2012-10-03 22:42:34 +00:00
|
|
|
if (pszKeyPath[0] == L'\0')
|
2010-07-28 19:13:24 +00:00
|
|
|
hKey = hRootKey;
|
2012-10-03 22:42:34 +00:00
|
|
|
else if (RegOpenKeyW(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
|
2005-09-22 20:54:20 +00:00
|
|
|
goto done;
|
|
|
|
|
2022-11-02 18:02:14 +00:00
|
|
|
if (LoadStringW(hInst, IDS_NEW_KEY, szNewKeyFormat, ARRAY_SIZE(szNewKeyFormat)) <= 0)
|
2005-09-22 20:54:20 +00:00
|
|
|
goto done;
|
|
|
|
|
2005-11-22 01:30:30 +00:00
|
|
|
/* Need to create a new key with a unique name */
|
2005-09-22 20:54:20 +00:00
|
|
|
do
|
|
|
|
{
|
2010-07-28 19:13:24 +00:00
|
|
|
wsprintf(szNewKey, szNewKeyFormat, iIndex++);
|
2013-01-01 16:06:02 +00:00
|
|
|
nResult = RegCreateKeyExW(hKey, szNewKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hNewKey, &dwDisposition);
|
2010-07-28 19:13:24 +00:00
|
|
|
if (hNewKey && dwDisposition == REG_OPENED_EXISTING_KEY)
|
2005-09-22 20:54:20 +00:00
|
|
|
{
|
|
|
|
RegCloseKey(hNewKey);
|
|
|
|
hNewKey = NULL;
|
|
|
|
}
|
2010-07-28 19:13:24 +00:00
|
|
|
else if (!hNewKey)
|
|
|
|
{
|
2012-10-05 20:08:16 +00:00
|
|
|
InfoMessageBox(hFrameWnd, MB_OK | MB_ICONERROR, NULL, L"Cannot create new key!\n\nError Code: %d", nResult);
|
2010-07-28 19:13:24 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2005-09-22 20:54:20 +00:00
|
|
|
}
|
|
|
|
while(!hNewKey);
|
|
|
|
|
2005-11-22 01:30:30 +00:00
|
|
|
/* Insert the new key */
|
|
|
|
hNewItem = InsertNode(hwndTV, hItem, szNewKey);
|
2005-09-22 20:54:20 +00:00
|
|
|
if (!hNewItem)
|
|
|
|
goto done;
|
2005-11-22 01:30:30 +00:00
|
|
|
|
|
|
|
/* The new key's name is probably not appropriate yet */
|
2006-03-04 17:27:40 +00:00
|
|
|
(void)TreeView_EditLabel(hwndTV, hNewItem);
|
2005-09-22 20:54:20 +00:00
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
done:
|
2010-07-28 19:13:24 +00:00
|
|
|
if (hKey != hRootKey && hKey)
|
2005-09-22 20:54:20 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
if (hNewKey)
|
|
|
|
RegCloseKey(hNewKey);
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2020-05-16 12:23:20 +00:00
|
|
|
BOOL TreeWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
|
2021-09-13 01:33:14 +00:00
|
|
|
{
|
2020-05-16 12:23:20 +00:00
|
|
|
UNREFERENCED_PARAMETER(wParam);
|
|
|
|
*Result = TRUE;
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2020-05-16 12:23:20 +00:00
|
|
|
switch (((LPNMHDR)lParam)->code)
|
|
|
|
{
|
|
|
|
case TVN_ITEMEXPANDING:
|
|
|
|
*Result = !OnTreeExpanding(g_pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
|
|
|
|
return TRUE;
|
2021-09-13 01:33:14 +00:00
|
|
|
case TVN_SELCHANGED:
|
2020-05-16 12:23:20 +00:00
|
|
|
{
|
|
|
|
NMTREEVIEW* pnmtv = (NMTREEVIEW*)lParam;
|
|
|
|
/* Get the parent of the current item */
|
|
|
|
HTREEITEM hParentItem = TreeView_GetParent(g_pChildWnd->hTreeWnd, pnmtv->itemNew.hItem);
|
|
|
|
|
2023-04-01 13:21:59 +00:00
|
|
|
UpdateAddress(pnmtv->itemNew.hItem, NULL, NULL, TRUE);
|
2020-05-16 12:23:20 +00:00
|
|
|
|
2023-05-18 10:16:49 +00:00
|
|
|
/* Disable the Permissions and new key menu items for 'My Computer' */
|
2020-05-16 12:23:20 +00:00
|
|
|
EnableMenuItem(hMenuFrame, ID_EDIT_PERMISSIONS, MF_BYCOMMAND | (hParentItem ? MF_ENABLED : MF_GRAYED));
|
2023-05-18 10:16:49 +00:00
|
|
|
EnableMenuItem(hMenuFrame, ID_EDIT_NEW_KEY, MF_BYCOMMAND | (hParentItem ? MF_ENABLED : MF_GRAYED));
|
2020-05-16 12:23:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable Delete/Rename menu options for 'My Computer' (first item so doesn't have any parent)
|
|
|
|
* and HKEY_* keys (their parent is 'My Computer' and the previous remark applies).
|
|
|
|
*/
|
|
|
|
if (!hParentItem || !TreeView_GetParent(g_pChildWnd->hTreeWnd, hParentItem))
|
|
|
|
{
|
|
|
|
EnableMenuItem(hMenuFrame , ID_EDIT_DELETE, MF_BYCOMMAND | MF_GRAYED);
|
|
|
|
EnableMenuItem(hMenuFrame , ID_EDIT_RENAME, MF_BYCOMMAND | MF_GRAYED);
|
|
|
|
EnableMenuItem(hPopupMenus, ID_TREE_DELETE, MF_BYCOMMAND | MF_GRAYED);
|
2021-09-13 01:33:14 +00:00
|
|
|
EnableMenuItem(hPopupMenus, ID_TREE_RENAME, MF_BYCOMMAND | MF_GRAYED);
|
2020-05-16 12:23:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableMenuItem(hMenuFrame , ID_EDIT_DELETE, MF_BYCOMMAND | MF_ENABLED);
|
|
|
|
EnableMenuItem(hMenuFrame , ID_EDIT_RENAME, MF_BYCOMMAND | MF_ENABLED);
|
|
|
|
EnableMenuItem(hPopupMenus, ID_TREE_DELETE, MF_BYCOMMAND | MF_ENABLED);
|
|
|
|
EnableMenuItem(hPopupMenus, ID_TREE_RENAME, MF_BYCOMMAND | MF_ENABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case NM_SETFOCUS:
|
|
|
|
g_pChildWnd->nFocusPanel = 0;
|
|
|
|
break;
|
|
|
|
case TVN_BEGINLABELEDIT:
|
|
|
|
{
|
2023-05-01 14:50:01 +00:00
|
|
|
LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
|
2020-05-16 12:23:20 +00:00
|
|
|
/* cancel label edit for rootkeys */
|
|
|
|
if (!TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem) ||
|
|
|
|
!TreeView_GetParent(g_pChildWnd->hTreeWnd, TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem)))
|
|
|
|
{
|
|
|
|
*Result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*Result = FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case TVN_ENDLABELEDIT:
|
2021-09-13 01:33:14 +00:00
|
|
|
{
|
2020-05-16 12:23:20 +00:00
|
|
|
LPCWSTR keyPath;
|
|
|
|
HKEY hRootKey;
|
|
|
|
HKEY hKey = NULL;
|
2023-05-01 14:50:01 +00:00
|
|
|
LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
|
2020-05-16 12:23:20 +00:00
|
|
|
LONG nRenResult;
|
|
|
|
LONG lResult = TRUE;
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
WCHAR Caption[128];
|
|
|
|
|
|
|
|
if (ptvdi->item.pszText)
|
|
|
|
{
|
|
|
|
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem), &hRootKey);
|
|
|
|
if (wcslen(keyPath))
|
2022-11-02 18:02:14 +00:00
|
|
|
_snwprintf(szBuffer, ARRAY_SIZE(szBuffer), L"%s\\%s", keyPath, ptvdi->item.pszText);
|
2020-05-16 12:23:20 +00:00
|
|
|
else
|
2022-11-02 18:02:14 +00:00
|
|
|
_snwprintf(szBuffer, ARRAY_SIZE(szBuffer), L"%s", ptvdi->item.pszText);
|
2020-05-16 12:23:20 +00:00
|
|
|
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, ptvdi->item.hItem, &hRootKey);
|
|
|
|
if (RegOpenKeyExW(hRootKey, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
lResult = FALSE;
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
TreeView_EditLabel(g_pChildWnd->hTreeWnd, ptvdi->item.hItem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nRenResult = RenameKey(hRootKey, keyPath, ptvdi->item.pszText);
|
|
|
|
if (nRenResult != ERROR_SUCCESS)
|
|
|
|
{
|
2022-11-02 18:02:14 +00:00
|
|
|
LoadStringW(hInst, IDS_ERROR, Caption, ARRAY_SIZE(Caption));
|
2020-05-16 12:23:20 +00:00
|
|
|
ErrorMessageBox(hWnd, Caption, nRenResult);
|
|
|
|
lResult = FALSE;
|
|
|
|
}
|
|
|
|
else
|
2023-04-01 13:21:59 +00:00
|
|
|
UpdateAddress(ptvdi->item.hItem, hRootKey, szBuffer, FALSE);
|
2020-05-16 12:23:20 +00:00
|
|
|
}
|
|
|
|
*Result = lResult;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-22 20:54:20 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/*
|
|
|
|
* CreateTreeView - creates a tree view control.
|
|
|
|
* Returns the handle to the new control if successful, or NULL otherwise.
|
|
|
|
* hwndParent - handle to the control's parent window.
|
|
|
|
*/
|
2012-10-03 22:42:34 +00:00
|
|
|
HWND CreateTreeView(HWND hwndParent, LPWSTR pHostName, HMENU id)
|
2003-08-22 05:55:14 +00:00
|
|
|
{
|
2002-07-16 22:18:29 +00:00
|
|
|
RECT rcClient;
|
|
|
|
HWND hwndTV;
|
2003-08-22 05:55:14 +00:00
|
|
|
|
|
|
|
/* Get the dimensions of the parent window's client area, and create the tree view control. */
|
|
|
|
GetClientRect(hwndParent, &rcClient);
|
2012-10-03 22:42:34 +00:00
|
|
|
hwndTV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL,
|
2012-12-20 02:13:53 +00:00
|
|
|
WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_EDITLABELS | TVS_SHOWSELALWAYS,
|
2004-01-01 15:12:11 +00:00
|
|
|
0, 0, rcClient.right, rcClient.bottom,
|
2005-11-29 01:48:25 +00:00
|
|
|
hwndParent, id, hInst, NULL);
|
2020-05-16 12:23:20 +00:00
|
|
|
if (!hwndTV) return NULL;
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2003-08-22 05:55:14 +00:00
|
|
|
/* Initialize the image list, and add items to the control. */
|
2010-12-07 21:49:25 +00:00
|
|
|
if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName))
|
|
|
|
{
|
2003-08-22 05:55:14 +00:00
|
|
|
DestroyWindow(hwndTV);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-07-14 17:59:36 +00:00
|
|
|
return hwndTV;
|
2003-08-22 05:55:14 +00:00
|
|
|
}
|
2005-10-03 12:39:50 +00:00
|
|
|
|
2013-06-29 19:22:00 +00:00
|
|
|
void DestroyTreeView(HWND hwndTV)
|
2010-12-07 21:49:25 +00:00
|
|
|
{
|
2013-06-29 19:22:00 +00:00
|
|
|
HIMAGELIST himl;
|
|
|
|
|
|
|
|
if (pathBuffer) HeapFree(GetProcessHeap(), 0, pathBuffer);
|
|
|
|
|
|
|
|
/* Destroy the image list associated with the tree view control */
|
|
|
|
himl = TreeView_GetImageList(hwndTV, TVSIL_NORMAL);
|
|
|
|
if (himl) ImageList_Destroy(himl);
|
2005-10-28 00:14:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
BOOL SelectNode(HWND hwndTV, LPCWSTR keyPath)
|
2005-10-03 12:39:50 +00:00
|
|
|
{
|
2010-12-07 21:49:25 +00:00
|
|
|
HTREEITEM hRoot, hItem;
|
|
|
|
HTREEITEM hChildItem;
|
2012-10-03 22:42:34 +00:00
|
|
|
WCHAR szPathPart[128];
|
|
|
|
WCHAR szBuffer[128];
|
|
|
|
LPCWSTR s;
|
2013-01-01 19:38:47 +00:00
|
|
|
TVITEMW tvi;
|
2005-10-03 12:39:50 +00:00
|
|
|
|
2012-10-05 20:08:16 +00:00
|
|
|
/* Load "My Computer" string... */
|
2022-11-02 18:02:14 +00:00
|
|
|
LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, ARRAY_SIZE(szBuffer));
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCatW(szBuffer, sizeof(szBuffer), L"\\");
|
2012-10-05 20:08:16 +00:00
|
|
|
|
|
|
|
/* ... and remove it from the key path */
|
|
|
|
if (!_wcsnicmp(keyPath, szBuffer, wcslen(szBuffer)))
|
|
|
|
keyPath += wcslen(szBuffer);
|
|
|
|
|
|
|
|
/* Reinitialize szBuffer */
|
|
|
|
szBuffer[0] = L'\0';
|
2005-11-23 00:09:17 +00:00
|
|
|
|
2010-12-07 21:49:25 +00:00
|
|
|
hRoot = TreeView_GetRoot(hwndTV);
|
|
|
|
hItem = hRoot;
|
|
|
|
|
|
|
|
while(keyPath[0])
|
|
|
|
{
|
2023-01-20 01:34:46 +00:00
|
|
|
size_t copyLength;
|
2012-10-03 22:42:34 +00:00
|
|
|
s = wcschr(keyPath, L'\\');
|
2023-01-20 01:34:46 +00:00
|
|
|
if (s != NULL)
|
|
|
|
{
|
|
|
|
copyLength = (s - keyPath) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
copyLength = sizeof(szPathPart);
|
|
|
|
}
|
|
|
|
StringCbCopyNW(szPathPart, sizeof(szPathPart), keyPath, copyLength);
|
2010-12-07 21:49:25 +00:00
|
|
|
|
|
|
|
/* Special case for root to expand root key abbreviations */
|
|
|
|
if (hItem == hRoot)
|
|
|
|
{
|
2013-01-01 19:38:47 +00:00
|
|
|
if (!_wcsicmp(szPathPart, L"HKCR"))
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCopyW(szPathPart, sizeof(szPathPart), L"HKEY_CLASSES_ROOT");
|
2013-01-01 19:38:47 +00:00
|
|
|
else if (!_wcsicmp(szPathPart, L"HKCU"))
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCopyW(szPathPart, sizeof(szPathPart), L"HKEY_CURRENT_USER");
|
2013-01-01 19:38:47 +00:00
|
|
|
else if (!_wcsicmp(szPathPart, L"HKLM"))
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCopyW(szPathPart, sizeof(szPathPart), L"HKEY_LOCAL_MACHINE");
|
2013-01-01 19:38:47 +00:00
|
|
|
else if (!_wcsicmp(szPathPart, L"HKU"))
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCopyW(szPathPart, sizeof(szPathPart), L"HKEY_USERS");
|
2013-01-01 19:38:47 +00:00
|
|
|
else if (!_wcsicmp(szPathPart, L"HKCC"))
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCopyW(szPathPart, sizeof(szPathPart), L"HKEY_CURRENT_CONFIG");
|
2013-01-01 19:38:47 +00:00
|
|
|
else if (!_wcsicmp(szPathPart, L"HKDD"))
|
2023-01-20 01:34:46 +00:00
|
|
|
StringCbCopyW(szPathPart, sizeof(szPathPart), L"HKEY_DYN_DATA");
|
2010-12-07 21:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (hChildItem = TreeView_GetChild(hwndTV, hItem); hChildItem;
|
|
|
|
hChildItem = TreeView_GetNextSibling(hwndTV, hChildItem))
|
|
|
|
{
|
|
|
|
memset(&tvi, 0, sizeof(tvi));
|
|
|
|
tvi.hItem = hChildItem;
|
|
|
|
tvi.mask = TVIF_TEXT | TVIF_CHILDREN;
|
|
|
|
tvi.pszText = szBuffer;
|
2022-11-02 18:02:14 +00:00
|
|
|
tvi.cchTextMax = ARRAY_SIZE(szBuffer);
|
2010-12-07 21:49:25 +00:00
|
|
|
|
|
|
|
(void)TreeView_GetItem(hwndTV, &tvi);
|
|
|
|
|
2013-01-01 19:38:47 +00:00
|
|
|
if (!_wcsicmp(szBuffer, szPathPart))
|
2010-12-07 21:49:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hChildItem)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (tvi.cChildren > 0)
|
|
|
|
{
|
|
|
|
if (!TreeView_Expand(hwndTV, hChildItem, TVE_EXPAND))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
keyPath = s ? s + 1 : L"";
|
2010-12-07 21:49:25 +00:00
|
|
|
hItem = hChildItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)TreeView_SelectItem(hwndTV, hItem);
|
|
|
|
(void)TreeView_EnsureVisible(hwndTV, hItem);
|
|
|
|
|
|
|
|
return TRUE;
|
2005-10-03 12:39:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:42:34 +00:00
|
|
|
/* EOF */
|