[REGEDIT] Improve arrow button visual (#2133)
[reactos.git] / base / applications / regedit / childwnd.c
index 168861a..d02fb2d 100644 (file)
@@ -18,7 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <regedit.h>
+#include "regedit.h"
 
 ChildWnd* g_pChildWnd;
 static int last_split;
@@ -35,14 +35,17 @@ extern LPCWSTR get_root_key_name(HKEY hRootKey)
     if (hRootKey == HKEY_CURRENT_CONFIG) return L"HKEY_CURRENT_CONFIG";
     if (hRootKey == HKEY_DYN_DATA) return L"HKEY_DYN_DATA";
 
-    return L"UKNOWN HKEY, PLEASE REPORT";
+    return L"UNKNOWN HKEY, PLEASE REPORT";
 }
 
 extern void ResizeWnd(int cx, int cy)
 {
-    HDWP hdwp = BeginDeferWindowPos(3);
+    HDWP hdwp = BeginDeferWindowPos(4);
     RECT rt, rs, rb;
-    const int tHeight = 18;
+    const int nButtonWidth = 44;
+    const int nButtonHeight = 22;
+    int cyEdge = GetSystemMetrics(SM_CYEDGE);
+    const UINT uFlags = SWP_NOZORDER | SWP_NOACTIVATE;
     SetRect(&rt, 0, 0, cx, cy);
     cy = 0;
     if (hStatusBar != NULL)
@@ -51,12 +54,33 @@ extern void ResizeWnd(int cx, int cy)
         cy = rs.bottom - rs.top;
     }
     GetWindowRect(g_pChildWnd->hAddressBtnWnd, &rb);
-    cx = g_pChildWnd->nSplitPos + SPLIT_WIDTH/2;
-    DeferWindowPos(hdwp, g_pChildWnd->hAddressBarWnd, 0, rt.left, rt.top, rt.right-rt.left - tHeight-2, tHeight, SWP_NOZORDER|SWP_NOACTIVATE);
-    DeferWindowPos(hdwp, g_pChildWnd->hAddressBtnWnd, 0, rt.right - tHeight, rt.top, tHeight, tHeight, SWP_NOZORDER|SWP_NOACTIVATE);
-    DeferWindowPos(hdwp, g_pChildWnd->hTreeWnd, 0, rt.left, rt.top + tHeight+2, g_pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE);
-    DeferWindowPos(hdwp, g_pChildWnd->hListWnd, 0, rt.left+cx, rt.top + tHeight+2, rt.right-cx, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE);
-    EndDeferWindowPos(hdwp);
+    cx = g_pChildWnd->nSplitPos + SPLIT_WIDTH / 2;
+    if (hdwp)
+        hdwp = DeferWindowPos(hdwp, g_pChildWnd->hAddressBarWnd, NULL,
+                              rt.left, rt.top,
+                              rt.right - rt.left - nButtonWidth, nButtonHeight,
+                              uFlags);
+    if (hdwp)
+        hdwp = DeferWindowPos(hdwp, g_pChildWnd->hAddressBtnWnd, NULL,
+                              rt.right - nButtonWidth, rt.top,
+                              nButtonWidth, nButtonHeight,
+                              uFlags);
+    if (hdwp)
+        hdwp = DeferWindowPos(hdwp, g_pChildWnd->hTreeWnd, NULL,
+                              rt.left,
+                              rt.top + nButtonHeight + cyEdge,
+                              g_pChildWnd->nSplitPos - SPLIT_WIDTH/2 - rt.left,
+                              rt.bottom - rt.top - cy - 2 * cyEdge,
+                              uFlags);
+    if (hdwp)
+        hdwp = DeferWindowPos(hdwp, g_pChildWnd->hListWnd, NULL,
+                              rt.left + cx,
+                              rt.top + nButtonHeight + cyEdge,
+                              rt.right - cx,
+                              rt.bottom - rt.top - cy - 2 * cyEdge,
+                              uFlags);
+    if (hdwp)
+        EndDeferWindowPos(hdwp);
 }
 
 /*******************************************************************************
@@ -87,17 +111,6 @@ static void draw_splitbar(HWND hWnd, int x)
     ReleaseDC(hWnd, hdc);
 }
 
-static void OnPaint(HWND hWnd)
-{
-    PAINTSTRUCT ps;
-    RECT rt;
-
-    GetClientRect(hWnd, &rt);
-    BeginPaint(hWnd, &ps);
-    FillRect(ps.hdc, &rt, GetSysColorBrush(COLOR_BTNFACE));
-    EndPaint(hWnd, &ps);
-}
-
 /*******************************************************************************
  * finish_splitbar [internal]
  *
@@ -118,13 +131,13 @@ static void finish_splitbar(HWND hWnd, int x)
 
 /*******************************************************************************
  *
- *  FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
+ *  FUNCTION: ChildWnd_CmdWndProc(HWND, unsigned, WORD, LONG)
  *
  *  PURPOSE:  Processes WM_COMMAND messages for the main frame window.
  *
  */
 
-static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+static BOOL ChildWnd_CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     HTREEITEM hSelection;
     HKEY hRootKey;
@@ -143,14 +156,14 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
         /* TODO */
         break;
     case ID_TREE_EXPANDBRANCH:
-        (void)TreeView_Expand(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd), TVE_EXPAND);
+        TreeView_Expand(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd), TVE_EXPAND);
         break;
     case ID_TREE_COLLAPSEBRANCH:
-        (void)TreeView_Expand(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd), TVE_COLLAPSE);
+        TreeView_Expand(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd), TVE_COLLAPSE);
         break;
     case ID_TREE_RENAME:
         SetFocus(g_pChildWnd->hTreeWnd);
-        (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd));
+        TreeView_EditLabel(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd));
         break;
     case ID_TREE_DELETE:
         hSelection = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
@@ -236,16 +249,16 @@ static void SuggestKeys(HKEY hRootKey, LPCWSTR pszKeyPath, LPWSTR pszSuggestions
             {
                 /* Sanity check this key; it cannot be empty, nor can it be a
                  * loop back */
-                if ((szBuffer[0] != L'\0') && wcsicmp(szBuffer, pszKeyPath))
+                if ((szBuffer[0] != L'\0') && _wcsicmp(szBuffer, pszKeyPath))
                 {
                     if (RegOpenKeyW(hRootKey, szBuffer, &hOtherKey) == ERROR_SUCCESS)
                     {
-                        wcsncpy(pszSuggestions, L"HKCR\\", (int) iSuggestionsLength);
+                        lstrcpynW(pszSuggestions, L"HKCR\\", (int) iSuggestionsLength);
                         i = wcslen(pszSuggestions);
                         pszSuggestions += i;
                         iSuggestionsLength -= i;
 
-                        wcsncpy(pszSuggestions, szBuffer, (int) iSuggestionsLength);
+                        lstrcpynW(pszSuggestions, szBuffer, (int) iSuggestionsLength);
                         i = MIN(wcslen(pszSuggestions) + 1, iSuggestionsLength);
                         pszSuggestions += i;
                         iSuggestionsLength -= i;
@@ -266,12 +279,12 @@ static void SuggestKeys(HKEY hRootKey, LPCWSTR pszKeyPath, LPWSTR pszSuggestions
             if (QueryStringValue(hSubKey, L"CLSID", NULL, szBuffer,
                                  COUNT_OF(szBuffer)) == ERROR_SUCCESS)
             {
-                wcsncpy(pszSuggestions, L"HKCR\\CLSID\\", (int)iSuggestionsLength);
+                lstrcpynW(pszSuggestions, L"HKCR\\CLSID\\", (int)iSuggestionsLength);
                 i = wcslen(pszSuggestions);
                 pszSuggestions += i;
                 iSuggestionsLength -= i;
 
-                wcsncpy(pszSuggestions, szBuffer, (int)iSuggestionsLength);
+                lstrcpynW(pszSuggestions, szBuffer, (int)iSuggestionsLength);
                 i = MIN(wcslen(pszSuggestions) + 1, iSuggestionsLength);
                 pszSuggestions += i;
                 iSuggestionsLength -= i;
@@ -286,7 +299,7 @@ LRESULT CALLBACK AddressBarProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
 {
     WNDPROC oldwndproc;
     static WCHAR s_szNode[256];
-    oldwndproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(hwnd, GWL_USERDATA);
+    oldwndproc = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
 
     switch (uMsg)
     {
@@ -300,7 +313,63 @@ LRESULT CALLBACK AddressBarProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
     default:
         break;
     }
-    return CallWindowProc(oldwndproc, hwnd, uMsg, wParam, lParam);
+    return CallWindowProcW(oldwndproc, hwnd, uMsg, wParam, lParam);
+}
+
+static VOID
+UpdateAddress(HTREEITEM hItem, HKEY hRootKey, LPCWSTR pszPath)
+{
+    LPCWSTR keyPath, rootName;
+    LPWSTR fullPath;
+
+    /* Wipe the listview, the status bar and the address bar if the root key was selected */
+    if (TreeView_GetParent(g_pChildWnd->hTreeWnd, hItem) == NULL)
+    {
+        ListView_DeleteAllItems(g_pChildWnd->hListWnd);
+        SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)NULL);
+        SendMessageW(g_pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)NULL);
+        return;
+    }
+
+    if (pszPath == NULL)
+        keyPath = GetItemPath(g_pChildWnd->hTreeWnd, hItem, &hRootKey);
+    else
+        keyPath = pszPath;
+
+    if (keyPath)
+    {
+        RefreshListView(g_pChildWnd->hListWnd, hRootKey, keyPath);
+        rootName = get_root_key_name(hRootKey);
+        fullPath = HeapAlloc(GetProcessHeap(), 0, (wcslen(rootName) + 1 + wcslen(keyPath) + 1) * sizeof(WCHAR));
+        if (fullPath)
+        {
+            /* set (correct) the address bar text */
+            if (keyPath[0] != L'\0')
+                swprintf(fullPath, L"%s\\%s", rootName, keyPath);
+            else
+                fullPath = wcscpy(fullPath, rootName);
+            SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath);
+            SendMessageW(g_pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)fullPath);
+            HeapFree(GetProcessHeap(), 0, fullPath);
+            /* disable hive manipulation items temporarily (enable only if necessary) */
+            EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_LOADHIVE, MF_BYCOMMAND | MF_GRAYED);
+            EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_GRAYED);
+            /* compare the strings to see if we should enable/disable the "Load Hive" menus accordingly */
+            if (!(_wcsicmp(rootName, L"HKEY_LOCAL_MACHINE") &&
+                  _wcsicmp(rootName, L"HKEY_USERS")))
+            {
+                /*
+                 * enable the unload menu item if at the root, otherwise
+                 * enable the load menu item if there is no slash in
+                 * keyPath (ie. immediate child selected)
+                 */
+                if(keyPath[0] == L'\0')
+                    EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_LOADHIVE, MF_BYCOMMAND | MF_ENABLED);
+                else if(!wcschr(keyPath, L'\\'))
+                    EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_ENABLED);
+            }
+        }
+    }
 }
 
 /*******************************************************************************
@@ -310,13 +379,13 @@ LRESULT CALLBACK AddressBarProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
  *  PURPOSE:  Processes messages for the child windows.
  *
  *  WM_COMMAND  - process the application menu
- *  WM_PAINT    - Paint the main window
  *  WM_DESTROY  - post a quit message and return
  *
  */
 LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     BOOL Result;
+    RECT rc;
 
     switch (message)
     {
@@ -325,6 +394,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
         WNDPROC oldproc;
         HFONT hFont;
         WCHAR buffer[MAX_PATH];
+        DWORD style;
 
         /* Load "My Computer" string */
         LoadStringW(hInst, IDS_MY_COMPUTER, buffer, COUNT_OF(buffer));
@@ -333,16 +403,26 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
         if (!g_pChildWnd) return 0;
 
         wcsncpy(g_pChildWnd->szPath, buffer, MAX_PATH);
-        g_pChildWnd->nSplitPos = 250;
+        g_pChildWnd->nSplitPos = 190;
         g_pChildWnd->hWnd = hWnd;
-        g_pChildWnd->hAddressBarWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", NULL, WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP,
+
+        style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
+        g_pChildWnd->hAddressBarWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", NULL, style,
                                                       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                                       hWnd, (HMENU)0, hInst, 0);
-        g_pChildWnd->hAddressBtnWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Button", L"ยป", WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP | BS_DEFPUSHBUTTON,
+
+        style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_ICON | BS_CENTER |
+                BS_VCENTER | BS_FLAT | BS_DEFPUSHBUTTON;
+        g_pChildWnd->hAddressBtnWnd = CreateWindowExW(0, L"Button", L"\x00BB", style,
                                                       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                                       hWnd, (HMENU)0, hInst, 0);
+        g_pChildWnd->hArrowIcon = (HICON)LoadImageW(hInst, MAKEINTRESOURCEW(IDI_ARROW),
+                                                    IMAGE_ICON, 12, 12, 0);
+        SendMessageW(g_pChildWnd->hAddressBtnWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_pChildWnd->hArrowIcon);
+
+        GetClientRect(hWnd, &rc);
         g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, (HMENU) TREE_WINDOW);
-        g_pChildWnd->hListWnd = CreateListView(hWnd, (HMENU) LIST_WINDOW/*, g_pChildWnd->szPath*/);
+        g_pChildWnd->hListWnd = CreateListView(hWnd, (HMENU) LIST_WINDOW, rc.right - g_pChildWnd->nSplitPos);
         SetFocus(g_pChildWnd->hTreeWnd);
 
         /* set the address bar and button font */
@@ -359,9 +439,9 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
                          0);
         }
         /* Subclass the AddressBar */
-        oldproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWL_WNDPROC);
-        SetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWL_USERDATA, (DWORD_PTR)oldproc);
-        SetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWL_WNDPROC, (DWORD_PTR)AddressBarProc);
+        oldproc = (WNDPROC)GetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWLP_WNDPROC);
+        SetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWLP_USERDATA, (DWORD_PTR)oldproc);
+        SetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWLP_WNDPROC, (DWORD_PTR)AddressBarProc);
         break;
     }
     case WM_COMMAND:
@@ -370,14 +450,11 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
             PostMessageW(g_pChildWnd->hAddressBarWnd, WM_KEYUP, VK_RETURN, 0);
         }
 
-        if (!_CmdWndProc(hWnd, message, wParam, lParam))
+        if (!ChildWnd_CmdWndProc(hWnd, message, wParam, lParam))
         {
             goto def;
         }
         break;
-    case WM_PAINT:
-        OnPaint(hWnd);
-        return 0;
     case WM_SETCURSOR:
         if (LOWORD(lParam) == HTCLIENT)
         {
@@ -392,9 +469,10 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
         }
         goto def;
     case WM_DESTROY:
-        DestroyTreeView();
         DestroyListView(g_pChildWnd->hListWnd);
+        DestroyTreeView(g_pChildWnd->hTreeWnd);
         DestroyMainMenu();
+        DestroyIcon(g_pChildWnd->hArrowIcon);
         HeapFree(GetProcessHeap(), 0, g_pChildWnd);
         g_pChildWnd = NULL;
         PostQuitMessage(0);
@@ -495,44 +573,33 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
                 return !OnTreeExpanding(g_pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
             case TVN_SELCHANGED:
             {
-                LPCWSTR keyPath, rootName;
-                LPWSTR fullPath;
-                HKEY hRootKey;
+                NMTREEVIEW* pnmtv = (NMTREEVIEW*)lParam;
+                /* Get the parent of the current item */
+                HTREEITEM hParentItem = TreeView_GetParent(g_pChildWnd->hTreeWnd, pnmtv->itemNew.hItem);
 
-                keyPath = GetItemPath(g_pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey);
-                if (keyPath)
+                UpdateAddress(pnmtv->itemNew.hItem, NULL, NULL);
+
+                /*
+                 * 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))
                 {
-                    RefreshListView(g_pChildWnd->hListWnd, hRootKey, keyPath);
-                    rootName = get_root_key_name(hRootKey);
-                    fullPath = HeapAlloc(GetProcessHeap(), 0, (wcslen(rootName) + 1 + wcslen(keyPath) + 1) * sizeof(WCHAR));
-                    if (fullPath)
-                    {
-                        /* set (correct) the address bar text */
-                        if(keyPath[0] != L'\0')
-                            swprintf(fullPath, L"%s\\%s", rootName, keyPath);
-                        else
-                            fullPath = wcscpy(fullPath, rootName);
-                        SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath);
-                        SendMessageW(g_pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)fullPath);
-                        HeapFree(GetProcessHeap(), 0, fullPath);
-                        /* disable hive manipulation items temporarily (enable only if necessary) */
-                        EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_LOADHIVE, MF_BYCOMMAND | MF_GRAYED);
-                        EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_GRAYED);
-                        /* compare the strings to see if we should enable/disable the "Load Hive" menus accordingly */
-                        if (!(wcsicmp(rootName, L"HKEY_LOCAL_MACHINE") &&
-                                wcsicmp(rootName, L"HKEY_USERS")))
-                        {
-                            // enable the unload menu item if at the root
-                            // otherwise enable the load menu item if there is no slash in keyPath (ie. immediate child selected)
-                            if(keyPath[0] == L'\0')
-                                EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_LOADHIVE, MF_BYCOMMAND | MF_ENABLED);
-                            else if(!wcschr(keyPath, L'\\'))
-                                EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_ENABLED);
-                        }
-                    }
+                    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);
+                    EnableMenuItem(hPopupMenus, ID_TREE_RENAME, MF_BYCOMMAND | MF_GRAYED); 
+                }
+                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);
                 }
+
+                break;
             }
-            break;
             case NM_SETFOCUS:
                 g_pChildWnd->nFocusPanel = 0;
                 break;
@@ -565,12 +632,14 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
                     {
                         lResult = FALSE;
                         RegCloseKey(hKey);
-                        (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, ptvdi->item.hItem);
+                        TreeView_EditLabel(g_pChildWnd->hTreeWnd, ptvdi->item.hItem);
                     }
                     else
                     {
                         if (RenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS)
                             lResult = FALSE;
+                        else
+                            UpdateAddress(ptvdi->item.hItem, hRootKey, szBuffer);
                     }
                     return lResult;
                 }
@@ -648,8 +717,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
         {
             TVHITTESTINFO hti;
             HMENU hContextMenu;
-            TVITEM item;
-            MENUITEMINFO mii;
+            TVITEMW item;
+            MENUITEMINFOW mii;
             WCHAR resource[256];
             WCHAR buffer[256];
             LPWSTR s;
@@ -681,18 +750,18 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
                 hti.pt.x = pt.x;
                 hti.pt.y = pt.y;
                 ScreenToClient(g_pChildWnd->hTreeWnd, &hti.pt);
-                (void)TreeView_HitTest(g_pChildWnd->hTreeWnd, &hti);
+                TreeView_HitTest(g_pChildWnd->hTreeWnd, &hti);
             }
 
             if (hti.flags & TVHT_ONITEM)
             {
                 hContextMenu = GetSubMenu(hPopupMenus, PM_TREECONTEXT);
-                (void)TreeView_SelectItem(g_pChildWnd->hTreeWnd, hti.hItem);
+                TreeView_SelectItem(g_pChildWnd->hTreeWnd, hti.hItem);
 
                 memset(&item, 0, sizeof(item));
                 item.mask = TVIF_STATE | TVIF_CHILDREN;
                 item.hItem = hti.hItem;
-                (void)TreeView_GetItem(g_pChildWnd->hTreeWnd, &item);
+                TreeView_GetItem(g_pChildWnd->hTreeWnd, &item);
 
                 /* Set the Expand/Collapse menu item appropriately */
                 LoadStringW(hInst, (item.state & TVIS_EXPANDED) ? IDS_COLLAPSE : IDS_EXPAND, buffer, COUNT_OF(buffer));