4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 ChildWnd
* g_pChildWnd
;
24 static int last_split
;
25 HBITMAP SizingPattern
= 0;
26 HBRUSH SizingBrush
= 0;
27 static WCHAR Suggestions
[256];
29 extern LPCWSTR
get_root_key_name(HKEY hRootKey
)
31 if (hRootKey
== HKEY_CLASSES_ROOT
) return L
"HKEY_CLASSES_ROOT";
32 if (hRootKey
== HKEY_CURRENT_USER
) return L
"HKEY_CURRENT_USER";
33 if (hRootKey
== HKEY_LOCAL_MACHINE
) return L
"HKEY_LOCAL_MACHINE";
34 if (hRootKey
== HKEY_USERS
) return L
"HKEY_USERS";
35 if (hRootKey
== HKEY_CURRENT_CONFIG
) return L
"HKEY_CURRENT_CONFIG";
36 if (hRootKey
== HKEY_DYN_DATA
) return L
"HKEY_DYN_DATA";
38 return L
"UNKNOWN HKEY, PLEASE REPORT";
41 extern void ResizeWnd(int cx
, int cy
)
43 HDWP hdwp
= BeginDeferWindowPos(4);
45 const int tHeight
= 22;
46 SetRect(&rt
, 0, 0, cx
, cy
);
48 if (hStatusBar
!= NULL
)
50 GetWindowRect(hStatusBar
, &rs
);
51 cy
= rs
.bottom
- rs
.top
;
53 GetWindowRect(g_pChildWnd
->hAddressBtnWnd
, &rb
);
54 cx
= g_pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
55 if (hdwp
) hdwp
= DeferWindowPos(hdwp
, g_pChildWnd
->hAddressBarWnd
, 0, rt
.left
, rt
.top
, rt
.right
-rt
.left
- 2*tHeight
, tHeight
, SWP_NOZORDER
|SWP_NOACTIVATE
);
56 if (hdwp
) hdwp
= DeferWindowPos(hdwp
, g_pChildWnd
->hAddressBtnWnd
, 0, rt
.right
- 2*tHeight
, rt
.top
, 2*tHeight
, tHeight
, SWP_NOZORDER
|SWP_NOACTIVATE
);
57 if (hdwp
) hdwp
= 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
);
58 if (hdwp
) hdwp
= 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
);
59 if (hdwp
) EndDeferWindowPos(hdwp
);
62 /*******************************************************************************
63 * Local module support methods
66 static void draw_splitbar(HWND hWnd
, int x
)
70 HDC hdc
= GetDC(hWnd
);
74 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
75 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
79 SizingBrush
= CreatePatternBrush(SizingPattern
);
81 GetClientRect(hWnd
, &rt
);
82 rt
.left
= x
- SPLIT_WIDTH
/2;
83 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
84 OldObj
= SelectObject(hdc
, SizingBrush
);
85 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
86 SelectObject(hdc
, OldObj
);
90 static void OnPaint(HWND hWnd
)
95 GetClientRect(hWnd
, &rt
);
96 BeginPaint(hWnd
, &ps
);
97 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
101 /*******************************************************************************
102 * finish_splitbar [internal]
104 * make the splitbar invisible and resize the windows
105 * (helper for ChildWndProc)
107 static void finish_splitbar(HWND hWnd
, int x
)
111 draw_splitbar(hWnd
, last_split
);
113 GetClientRect(hWnd
, &rt
);
114 g_pChildWnd
->nSplitPos
= x
;
115 ResizeWnd(rt
.right
, rt
.bottom
);
119 /*******************************************************************************
121 * FUNCTION: ChildWnd_CmdWndProc(HWND, unsigned, WORD, LONG)
123 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
127 static BOOL
ChildWnd_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
129 HTREEITEM hSelection
;
132 WORD wID
= LOWORD(wParam
);
134 UNREFERENCED_PARAMETER(message
);
138 /* Parse the menu selections: */
139 case ID_REGISTRY_EXIT
:
142 case ID_VIEW_REFRESH
:
145 case ID_TREE_EXPANDBRANCH
:
146 (void)TreeView_Expand(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
), TVE_EXPAND
);
148 case ID_TREE_COLLAPSEBRANCH
:
149 (void)TreeView_Expand(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
), TVE_COLLAPSE
);
152 SetFocus(g_pChildWnd
->hTreeWnd
);
153 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
156 hSelection
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
157 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
159 if (keyPath
== 0 || *keyPath
== 0)
161 MessageBeep(MB_ICONHAND
);
163 else if (DeleteKey(hWnd
, hRootKey
, keyPath
))
164 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
167 ExportRegistryFile(g_pChildWnd
->hTreeWnd
);
172 case ID_EDIT_COPYKEYNAME
:
173 hSelection
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
174 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
175 CopyKeyName(hWnd
, hRootKey
, keyPath
);
177 case ID_EDIT_NEW_KEY
:
178 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
180 case ID_EDIT_NEW_STRINGVALUE
:
181 case ID_EDIT_NEW_BINARYVALUE
:
182 case ID_EDIT_NEW_DWORDVALUE
:
183 SendMessageW(hFrameWnd
, WM_COMMAND
, wParam
, lParam
);
185 case ID_SWITCH_PANELS
:
186 g_pChildWnd
->nFocusPanel
= !g_pChildWnd
->nFocusPanel
;
187 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
190 if ((wID
>= ID_TREE_SUGGESTION_MIN
) && (wID
<= ID_TREE_SUGGESTION_MAX
))
193 while(wID
> ID_TREE_SUGGESTION_MIN
)
199 SelectNode(g_pChildWnd
->hTreeWnd
, s
);
207 /*******************************************************************************
212 #define MIN(a,b) ((a < b) ? (a) : (b))
214 static void SuggestKeys(HKEY hRootKey
, LPCWSTR pszKeyPath
, LPWSTR pszSuggestions
,
215 size_t iSuggestionsLength
)
218 WCHAR szLastFound
[256];
220 HKEY hOtherKey
, hSubKey
;
223 memset(pszSuggestions
, 0, iSuggestionsLength
* sizeof(*pszSuggestions
));
224 iSuggestionsLength
--;
226 /* Are we a root key in HKEY_CLASSES_ROOT? */
227 if ((hRootKey
== HKEY_CLASSES_ROOT
) && pszKeyPath
[0] && !wcschr(pszKeyPath
, L
'\\'))
233 /* Check default key */
234 if (QueryStringValue(hRootKey
, pszKeyPath
, NULL
,
235 szBuffer
, COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
237 /* Sanity check this key; it cannot be empty, nor can it be a
239 if ((szBuffer
[0] != L
'\0') && _wcsicmp(szBuffer
, pszKeyPath
))
241 if (RegOpenKeyW(hRootKey
, szBuffer
, &hOtherKey
) == ERROR_SUCCESS
)
243 lstrcpynW(pszSuggestions
, L
"HKCR\\", (int) iSuggestionsLength
);
244 i
= wcslen(pszSuggestions
);
246 iSuggestionsLength
-= i
;
248 lstrcpynW(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
249 i
= MIN(wcslen(pszSuggestions
) + 1, iSuggestionsLength
);
251 iSuggestionsLength
-= i
;
252 RegCloseKey(hOtherKey
);
255 wcscpy(szLastFound
, szBuffer
);
256 pszKeyPath
= szLastFound
;
261 while(bFound
&& (iSuggestionsLength
> 0));
263 /* Check CLSID key */
264 if (RegOpenKeyW(hRootKey
, pszKeyPath
, &hSubKey
) == ERROR_SUCCESS
)
266 if (QueryStringValue(hSubKey
, L
"CLSID", NULL
, szBuffer
,
267 COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
269 lstrcpynW(pszSuggestions
, L
"HKCR\\CLSID\\", (int)iSuggestionsLength
);
270 i
= wcslen(pszSuggestions
);
272 iSuggestionsLength
-= i
;
274 lstrcpynW(pszSuggestions
, szBuffer
, (int)iSuggestionsLength
);
275 i
= MIN(wcslen(pszSuggestions
) + 1, iSuggestionsLength
);
277 iSuggestionsLength
-= i
;
279 RegCloseKey(hSubKey
);
285 LRESULT CALLBACK
AddressBarProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
288 static WCHAR s_szNode
[256];
289 oldwndproc
= (WNDPROC
)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
294 if (wParam
== VK_RETURN
)
296 GetWindowTextW(hwnd
, s_szNode
, COUNT_OF(s_szNode
));
297 SelectNode(g_pChildWnd
->hTreeWnd
, s_szNode
);
303 return CallWindowProcW(oldwndproc
, hwnd
, uMsg
, wParam
, lParam
);
307 UpdateAddress(HTREEITEM hItem
, HKEY hRootKey
, LPCWSTR pszPath
)
309 LPCWSTR keyPath
, rootName
;
312 /* Wipe the listview, the status bar and the address bar if the root key was selected */
313 if (TreeView_GetParent(g_pChildWnd
->hTreeWnd
, hItem
) == NULL
)
315 (void)ListView_DeleteAllItems(g_pChildWnd
->hListWnd
);
316 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)NULL
);
317 SendMessageW(g_pChildWnd
->hAddressBarWnd
, WM_SETTEXT
, 0, (LPARAM
)NULL
);
322 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, hItem
, &hRootKey
);
328 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, keyPath
);
329 rootName
= get_root_key_name(hRootKey
);
330 fullPath
= HeapAlloc(GetProcessHeap(), 0, (wcslen(rootName
) + 1 + wcslen(keyPath
) + 1) * sizeof(WCHAR
));
333 /* set (correct) the address bar text */
334 if (keyPath
[0] != L
'\0')
335 swprintf(fullPath
, L
"%s\\%s", rootName
, keyPath
);
337 fullPath
= wcscpy(fullPath
, rootName
);
338 SendMessageW(hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)fullPath
);
339 SendMessageW(g_pChildWnd
->hAddressBarWnd
, WM_SETTEXT
, 0, (LPARAM
)fullPath
);
340 HeapFree(GetProcessHeap(), 0, fullPath
);
341 /* disable hive manipulation items temporarily (enable only if necessary) */
342 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_LOADHIVE
, MF_BYCOMMAND
| MF_GRAYED
);
343 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_UNLOADHIVE
, MF_BYCOMMAND
| MF_GRAYED
);
344 /* compare the strings to see if we should enable/disable the "Load Hive" menus accordingly */
345 if (!(_wcsicmp(rootName
, L
"HKEY_LOCAL_MACHINE") &&
346 _wcsicmp(rootName
, L
"HKEY_USERS")))
349 * enable the unload menu item if at the root, otherwise
350 * enable the load menu item if there is no slash in
351 * keyPath (ie. immediate child selected)
353 if(keyPath
[0] == L
'\0')
354 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_LOADHIVE
, MF_BYCOMMAND
| MF_ENABLED
);
355 else if(!wcschr(keyPath
, L
'\\'))
356 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_UNLOADHIVE
, MF_BYCOMMAND
| MF_ENABLED
);
362 /*******************************************************************************
364 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
366 * PURPOSE: Processes messages for the child windows.
368 * WM_COMMAND - process the application menu
369 * WM_PAINT - Paint the main window
370 * WM_DESTROY - post a quit message and return
373 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
383 WCHAR buffer
[MAX_PATH
];
385 /* Load "My Computer" string */
386 LoadStringW(hInst
, IDS_MY_COMPUTER
, buffer
, COUNT_OF(buffer
));
388 g_pChildWnd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ChildWnd
));
389 if (!g_pChildWnd
) return 0;
391 wcsncpy(g_pChildWnd
->szPath
, buffer
, MAX_PATH
);
392 g_pChildWnd
->nSplitPos
= 250;
393 g_pChildWnd
->hWnd
= hWnd
;
394 g_pChildWnd
->hAddressBarWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, L
"Edit", NULL
, WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
,
395 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
396 hWnd
, (HMENU
)0, hInst
, 0);
397 g_pChildWnd
->hAddressBtnWnd
= CreateWindowExW(0, L
"Button", L
"\x00BB", WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
| BS_TEXT
| BS_CENTER
| BS_VCENTER
| BS_FLAT
| BS_DEFPUSHBUTTON
,
398 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
399 hWnd
, (HMENU
)0, hInst
, 0);
400 g_pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, g_pChildWnd
->szPath
, (HMENU
) TREE_WINDOW
);
401 g_pChildWnd
->hListWnd
= CreateListView(hWnd
, (HMENU
) LIST_WINDOW
/*, g_pChildWnd->szPath*/);
402 SetFocus(g_pChildWnd
->hTreeWnd
);
404 /* set the address bar and button font */
405 if ((g_pChildWnd
->hAddressBarWnd
) && (g_pChildWnd
->hAddressBtnWnd
))
407 hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
408 SendMessageW(g_pChildWnd
->hAddressBarWnd
,
412 SendMessageW(g_pChildWnd
->hAddressBtnWnd
,
417 /* Subclass the AddressBar */
418 oldproc
= (WNDPROC
)GetWindowLongPtr(g_pChildWnd
->hAddressBarWnd
, GWLP_WNDPROC
);
419 SetWindowLongPtr(g_pChildWnd
->hAddressBarWnd
, GWLP_USERDATA
, (DWORD_PTR
)oldproc
);
420 SetWindowLongPtr(g_pChildWnd
->hAddressBarWnd
, GWLP_WNDPROC
, (DWORD_PTR
)AddressBarProc
);
424 if(HIWORD(wParam
) == BN_CLICKED
)
426 PostMessageW(g_pChildWnd
->hAddressBarWnd
, WM_KEYUP
, VK_RETURN
, 0);
429 if (!ChildWnd_CmdWndProc(hWnd
, message
, wParam
, lParam
))
438 if (LOWORD(lParam
) == HTCLIENT
)
442 ScreenToClient(hWnd
, &pt
);
443 if (pt
.x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1)
445 SetCursor(LoadCursorW(0, IDC_SIZEWE
));
451 DestroyListView(g_pChildWnd
->hListWnd
);
452 DestroyTreeView(g_pChildWnd
->hTreeWnd
);
454 HeapFree(GetProcessHeap(), 0, g_pChildWnd
);
461 int x
= (short)LOWORD(lParam
);
462 GetClientRect(hWnd
, &rt
);
463 if (x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1)
465 last_split
= g_pChildWnd
->nSplitPos
;
466 draw_splitbar(hWnd
, last_split
);
474 if (GetCapture() == hWnd
)
476 finish_splitbar(hWnd
, LOWORD(lParam
));
480 case WM_CAPTURECHANGED
:
481 if (GetCapture()==hWnd
&& last_split
>=0)
482 draw_splitbar(hWnd
, last_split
);
486 if (wParam
== VK_ESCAPE
)
487 if (GetCapture() == hWnd
)
490 draw_splitbar(hWnd
, last_split
);
491 GetClientRect(hWnd
, &rt
);
492 ResizeWnd(rt
.right
, rt
.bottom
);
495 SetCursor(LoadCursorW(0, IDC_ARROW
));
500 if (GetCapture() == hWnd
)
505 int x
= LOWORD(lParam
);
508 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
509 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
513 SizingBrush
= CreatePatternBrush(SizingPattern
);
516 GetClientRect(hWnd
, &rt
);
517 x
= (SHORT
) min(max(x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
520 rt
.left
= last_split
-SPLIT_WIDTH
/2;
521 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
523 OldObj
= SelectObject(hdc
, SizingBrush
);
524 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
526 rt
.left
= x
-SPLIT_WIDTH
/2;
527 rt
.right
= x
+SPLIT_WIDTH
/2+1;
528 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
529 SelectObject(hdc
, OldObj
);
530 ReleaseDC(hWnd
, hdc
);
536 if (g_pChildWnd
!= NULL
)
538 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
546 if ((int)wParam
== TREE_WINDOW
&& g_pChildWnd
!= NULL
)
548 switch (((LPNMHDR
)lParam
)->code
)
550 case TVN_ITEMEXPANDING
:
551 return !OnTreeExpanding(g_pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
554 NMTREEVIEW
* pnmtv
= (NMTREEVIEW
*)lParam
;
555 /* Get the parent of the current item */
556 HTREEITEM hParentItem
= TreeView_GetParent(g_pChildWnd
->hTreeWnd
, pnmtv
->itemNew
.hItem
);
558 UpdateAddress(pnmtv
->itemNew
.hItem
, NULL
, NULL
);
561 * Disable Delete/Rename menu options for 'My Computer' (first item so doesn't have any parent)
562 * and HKEY_* keys (their parent is 'My Computer' and the previous remark applies).
564 if (!hParentItem
|| !TreeView_GetParent(g_pChildWnd
->hTreeWnd
, hParentItem
))
566 EnableMenuItem(hMenuFrame
, ID_EDIT_DELETE
, MF_BYCOMMAND
| MF_GRAYED
);
567 EnableMenuItem(hMenuFrame
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_GRAYED
);
568 EnableMenuItem(hPopupMenus
, ID_TREE_DELETE
, MF_BYCOMMAND
| MF_GRAYED
);
569 EnableMenuItem(hPopupMenus
, ID_TREE_RENAME
, MF_BYCOMMAND
| MF_GRAYED
);
573 EnableMenuItem(hMenuFrame
, ID_EDIT_DELETE
, MF_BYCOMMAND
| MF_ENABLED
);
574 EnableMenuItem(hMenuFrame
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_ENABLED
);
575 EnableMenuItem(hPopupMenus
, ID_TREE_DELETE
, MF_BYCOMMAND
| MF_ENABLED
);
576 EnableMenuItem(hPopupMenus
, ID_TREE_RENAME
, MF_BYCOMMAND
| MF_ENABLED
);
582 g_pChildWnd
->nFocusPanel
= 0;
584 case TVN_BEGINLABELEDIT
:
586 LPNMTVDISPINFO ptvdi
;
587 /* cancel label edit for rootkeys */
588 ptvdi
= (LPNMTVDISPINFO
) lParam
;
589 if (!TreeView_GetParent(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
) ||
590 !TreeView_GetParent(g_pChildWnd
->hTreeWnd
, TreeView_GetParent(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
)))
594 case TVN_ENDLABELEDIT
:
599 LPNMTVDISPINFO ptvdi
;
601 WCHAR szBuffer
[MAX_PATH
];
603 ptvdi
= (LPNMTVDISPINFO
) lParam
;
604 if (ptvdi
->item
.pszText
)
606 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, TreeView_GetParent(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
), &hRootKey
);
607 _snwprintf(szBuffer
, COUNT_OF(szBuffer
), L
"%s\\%s", keyPath
, ptvdi
->item
.pszText
);
608 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
, &hRootKey
);
609 if (RegOpenKeyExW(hRootKey
, szBuffer
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
613 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
);
617 if (RenameKey(hRootKey
, keyPath
, ptvdi
->item
.pszText
) != ERROR_SUCCESS
)
620 UpdateAddress(ptvdi
->item
.hItem
, hRootKey
, szBuffer
);
631 if ((int)wParam
== LIST_WINDOW
&& g_pChildWnd
!= NULL
)
633 switch (((LPNMHDR
)lParam
)->code
)
636 g_pChildWnd
->nFocusPanel
= 1;
639 if(!ListWndNotifyProc(g_pChildWnd
->hListWnd
, wParam
, lParam
, &Result
))
653 if((HWND
)wParam
== g_pChildWnd
->hListWnd
)
657 pt
.x
= (short) LOWORD(lParam
);
658 pt
.y
= (short) HIWORD(lParam
);
659 cnt
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
660 i
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
661 if (pt
.x
== -1 && pt
.y
== -1)
666 rc
.left
= LVIR_BOUNDS
;
667 SendMessageW(g_pChildWnd
->hListWnd
, LVM_GETITEMRECT
, i
, (LPARAM
) &rc
);
673 ClientToScreen(g_pChildWnd
->hListWnd
, &pt
);
677 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
681 HMENU mnu
= GetSubMenu(hPopupMenus
, PM_MODIFYVALUE
);
682 SetMenuDefaultItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
683 IsDefault
= IsDefaultValue(g_pChildWnd
->hListWnd
, i
);
685 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| (IsDefault
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
687 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
688 EnableMenuItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
689 EnableMenuItem(mnu
, ID_EDIT_MODIFY_BIN
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
691 TrackPopupMenu(mnu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
694 else if ((HWND
)wParam
== g_pChildWnd
->hTreeWnd
)
708 pt
.x
= (short) LOWORD(lParam
);
709 pt
.y
= (short) HIWORD(lParam
);
711 if (pt
.x
== -1 && pt
.y
== -1)
714 hti
.hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
715 if (hti
.hItem
!= NULL
)
717 TreeView_GetItemRect(g_pChildWnd
->hTreeWnd
, hti
.hItem
, &rc
, TRUE
);
720 ClientToScreen(g_pChildWnd
->hTreeWnd
, &pt
);
721 hti
.flags
= TVHT_ONITEM
;
730 ScreenToClient(g_pChildWnd
->hTreeWnd
, &hti
.pt
);
731 (void)TreeView_HitTest(g_pChildWnd
->hTreeWnd
, &hti
);
734 if (hti
.flags
& TVHT_ONITEM
)
736 hContextMenu
= GetSubMenu(hPopupMenus
, PM_TREECONTEXT
);
737 (void)TreeView_SelectItem(g_pChildWnd
->hTreeWnd
, hti
.hItem
);
739 memset(&item
, 0, sizeof(item
));
740 item
.mask
= TVIF_STATE
| TVIF_CHILDREN
;
741 item
.hItem
= hti
.hItem
;
742 (void)TreeView_GetItem(g_pChildWnd
->hTreeWnd
, &item
);
744 /* Set the Expand/Collapse menu item appropriately */
745 LoadStringW(hInst
, (item
.state
& TVIS_EXPANDED
) ? IDS_COLLAPSE
: IDS_EXPAND
, buffer
, COUNT_OF(buffer
));
746 memset(&mii
, 0, sizeof(mii
));
747 mii
.cbSize
= sizeof(mii
);
748 mii
.fMask
= MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
749 mii
.fState
= (item
.cChildren
> 0) ? MFS_DEFAULT
: MFS_GRAYED
;
750 mii
.wID
= (item
.state
& TVIS_EXPANDED
) ? ID_TREE_COLLAPSEBRANCH
: ID_TREE_EXPANDBRANCH
;
751 mii
.dwTypeData
= (LPWSTR
) buffer
;
752 SetMenuItemInfo(hContextMenu
, 0, TRUE
, &mii
);
754 /* Remove any existing suggestions */
755 memset(&mii
, 0, sizeof(mii
));
756 mii
.cbSize
= sizeof(mii
);
758 GetMenuItemInfo(hContextMenu
, GetMenuItemCount(hContextMenu
) - 1, TRUE
, &mii
);
759 if ((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
))
763 iLastPos
= GetMenuItemCount(hContextMenu
) - 1;
764 GetMenuItemInfo(hContextMenu
, iLastPos
, TRUE
, &mii
);
765 RemoveMenu(hContextMenu
, iLastPos
, MF_BYPOSITION
);
767 while((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
));
770 /* Come up with suggestions */
771 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, NULL
, &hRootKey
);
772 SuggestKeys(hRootKey
, keyPath
, Suggestions
, COUNT_OF(Suggestions
));
775 AppendMenu(hContextMenu
, MF_SEPARATOR
, 0, NULL
);
777 LoadStringW(hInst
, IDS_GOTO_SUGGESTED_KEY
, resource
, COUNT_OF(resource
));
780 wID
= ID_TREE_SUGGESTION_MIN
;
781 while(*s
&& (wID
<= ID_TREE_SUGGESTION_MAX
))
783 _snwprintf(buffer
, COUNT_OF(buffer
), resource
, s
);
785 memset(&mii
, 0, sizeof(mii
));
786 mii
.cbSize
= sizeof(mii
);
787 mii
.fMask
= MIIM_STRING
| MIIM_ID
;
789 mii
.dwTypeData
= buffer
;
790 InsertMenuItem(hContextMenu
, GetMenuItemCount(hContextMenu
), TRUE
, &mii
);
795 TrackPopupMenu(hContextMenu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, g_pChildWnd
->hWnd
, NULL
);
802 if (wParam
!= SIZE_MINIMIZED
&& g_pChildWnd
!= NULL
)
804 ResizeWnd(LOWORD(lParam
), HIWORD(lParam
));
809 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);