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 TCHAR Suggestions
[256];
29 /*******************************************************************************
30 * Local module support methods
33 static LPCTSTR
get_root_key_name(HKEY hRootKey
)
35 if (hRootKey
== HKEY_CLASSES_ROOT
) return _T("HKEY_CLASSES_ROOT");
36 if (hRootKey
== HKEY_CURRENT_USER
) return _T("HKEY_CURRENT_USER");
37 if (hRootKey
== HKEY_LOCAL_MACHINE
) return _T("HKEY_LOCAL_MACHINE");
38 if (hRootKey
== HKEY_USERS
) return _T("HKEY_USERS");
39 if (hRootKey
== HKEY_CURRENT_CONFIG
) return _T("HKEY_CURRENT_CONFIG");
40 if (hRootKey
== HKEY_DYN_DATA
) return _T("HKEY_DYN_DATA");
41 return _T("UKNOWN HKEY, PLEASE REPORT");
44 static void draw_splitbar(HWND hWnd
, int x
)
48 HDC hdc
= GetDC(hWnd
);
52 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
53 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
57 SizingBrush
= CreatePatternBrush(SizingPattern
);
59 GetClientRect(hWnd
, &rt
);
60 rt
.left
= x
- SPLIT_WIDTH
/2;
61 rt
.right
= x
+ SPLIT_WIDTH
/2+1;
62 OldObj
= SelectObject(hdc
, SizingBrush
);
63 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
64 SelectObject(hdc
, OldObj
);
68 static void ResizeWnd(ChildWnd
* pChildWnd
, int cx
, int cy
)
70 HDWP hdwp
= BeginDeferWindowPos(3);
72 const int tHeight
= 18;
73 SetRect(&rt
, 0, 0, cx
, cy
);
75 if (hStatusBar
!= NULL
)
77 GetWindowRect(hStatusBar
, &rs
);
78 cy
= rs
.bottom
- rs
.top
;
80 GetWindowRect(pChildWnd
->hAddressBtnWnd
, &rb
);
81 cx
= pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
82 DeferWindowPos(hdwp
, pChildWnd
->hAddressBarWnd
, 0, rt
.left
, rt
.top
, rt
.right
-rt
.left
- tHeight
-2, tHeight
, SWP_NOZORDER
|SWP_NOACTIVATE
);
83 DeferWindowPos(hdwp
, pChildWnd
->hAddressBtnWnd
, 0, rt
.right
- tHeight
, rt
.top
, tHeight
, tHeight
, SWP_NOZORDER
|SWP_NOACTIVATE
);
84 DeferWindowPos(hdwp
, pChildWnd
->hTreeWnd
, 0, rt
.left
, rt
.top
+ tHeight
+2, pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2-rt
.left
, rt
.bottom
-rt
.top
-cy
, SWP_NOZORDER
|SWP_NOACTIVATE
);
85 DeferWindowPos(hdwp
, pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
+ tHeight
+2, rt
.right
-cx
, rt
.bottom
-rt
.top
-cy
, SWP_NOZORDER
|SWP_NOACTIVATE
);
86 EndDeferWindowPos(hdwp
);
89 static void OnPaint(HWND hWnd
)
94 GetClientRect(hWnd
, &rt
);
95 BeginPaint(hWnd
, &ps
);
96 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
100 /*******************************************************************************
101 * finish_splitbar [internal]
103 * make the splitbar invisible and resize the windows
104 * (helper for ChildWndProc)
106 static void finish_splitbar(HWND hWnd
, int x
)
110 draw_splitbar(hWnd
, last_split
);
112 GetClientRect(hWnd
, &rt
);
113 g_pChildWnd
->nSplitPos
= x
;
114 ResizeWnd(g_pChildWnd
, rt
.right
, rt
.bottom
);
118 /*******************************************************************************
120 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
122 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
126 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
128 ChildWnd
* pChildWnd
= g_pChildWnd
;
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(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
), TVE_EXPAND
);
148 case ID_TREE_COLLAPSEBRANCH
:
149 (void)TreeView_Expand(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
), TVE_COLLAPSE
);
152 SetFocus(pChildWnd
->hTreeWnd
);
153 (void)TreeView_EditLabel(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
));
156 hSelection
= TreeView_GetSelection(pChildWnd
->hTreeWnd
);
157 keyPath
= GetItemPath(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(pChildWnd
->hTreeWnd
);
172 case ID_EDIT_COPYKEYNAME
:
173 hSelection
= TreeView_GetSelection(pChildWnd
->hTreeWnd
);
174 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
175 CopyKeyName(hWnd
, hRootKey
, keyPath
);
177 case ID_EDIT_NEW_KEY
:
178 CreateNewKey(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
));
180 case ID_EDIT_NEW_STRINGVALUE
:
181 case ID_EDIT_NEW_BINARYVALUE
:
182 case ID_EDIT_NEW_DWORDVALUE
:
183 SendMessage(hFrameWnd
, WM_COMMAND
, wParam
, lParam
);
185 case ID_SWITCH_PANELS
:
186 pChildWnd
->nFocusPanel
= !pChildWnd
->nFocusPanel
;
187 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
190 if ((wID
>= ID_TREE_SUGGESTION_MIN
) && (wID
<= ID_TREE_SUGGESTION_MAX
))
193 while(wID
> ID_TREE_SUGGESTION_MIN
)
199 SelectNode(pChildWnd
->hTreeWnd
, s
);
207 /*******************************************************************************
212 #define MIN(a,b) ((a < b) ? (a) : (b))
214 static void SuggestKeys(HKEY hRootKey
, LPCTSTR pszKeyPath
, LPTSTR pszSuggestions
,
215 size_t iSuggestionsLength
)
218 TCHAR 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] && !_tcschr(pszKeyPath
, TEXT('\\')))
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] != '\0') && _tcsicmp(szBuffer
, pszKeyPath
))
241 if (RegOpenKey(hRootKey
, szBuffer
, &hOtherKey
) == ERROR_SUCCESS
)
243 lstrcpyn(pszSuggestions
, TEXT("HKCR\\"), (int) iSuggestionsLength
);
244 i
= _tcslen(pszSuggestions
);
246 iSuggestionsLength
-= i
;
248 lstrcpyn(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
249 i
= MIN(_tcslen(pszSuggestions
) + 1, iSuggestionsLength
);
251 iSuggestionsLength
-= i
;
252 RegCloseKey(hOtherKey
);
255 _tcscpy(szLastFound
, szBuffer
);
256 pszKeyPath
= szLastFound
;
261 while(bFound
&& (iSuggestionsLength
> 0));
263 /* Check CLSID key */
264 if (RegOpenKey(hRootKey
, pszKeyPath
, &hSubKey
) == ERROR_SUCCESS
)
266 if (QueryStringValue(hSubKey
, TEXT("CLSID"), NULL
, szBuffer
,
267 COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
269 lstrcpyn(pszSuggestions
, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength
);
270 i
= _tcslen(pszSuggestions
);
272 iSuggestionsLength
-= i
;
274 lstrcpyn(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
275 i
= MIN(_tcslen(pszSuggestions
) + 1, iSuggestionsLength
);
277 iSuggestionsLength
-= i
;
279 RegCloseKey(hSubKey
);
285 LRESULT CALLBACK
AddressBarProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
288 static TCHAR s_szNode
[256];
289 oldwndproc
= (WNDPROC
)(LONG_PTR
)GetWindowLongPtr(hwnd
, GWL_USERDATA
);
294 if (wParam
== VK_RETURN
)
296 GetWindowText(hwnd
, s_szNode
, sizeof(s_szNode
) / sizeof(s_szNode
[0]));
297 SelectNode(g_pChildWnd
->hTreeWnd
, s_szNode
);
303 return CallWindowProc(oldwndproc
, hwnd
, uMsg
, wParam
, lParam
);
306 /*******************************************************************************
308 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
310 * PURPOSE: Processes messages for the child windows.
312 * WM_COMMAND - process the application menu
313 * WM_PAINT - Paint the main window
314 * WM_DESTROY - post a quit message and return
317 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
320 ChildWnd
* pChildWnd
= g_pChildWnd
;
328 TCHAR buffer
[MAX_PATH
];
329 /* load "My Computer" string */
330 LoadString(hInst
, IDS_MY_COMPUTER
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
332 g_pChildWnd
= pChildWnd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ChildWnd
));
334 if (!pChildWnd
) return 0;
335 _tcsncpy(pChildWnd
->szPath
, buffer
, MAX_PATH
);
336 pChildWnd
->nSplitPos
= 250;
337 pChildWnd
->hWnd
= hWnd
;
338 pChildWnd
->hAddressBarWnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Edit"), NULL
, WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
,
339 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
340 hWnd
, (HMENU
)0, hInst
, 0);
341 pChildWnd
->hAddressBtnWnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Button"), _T("»"), WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
| BS_DEFPUSHBUTTON
,
342 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
343 hWnd
, (HMENU
)0, hInst
, 0);
344 pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, pChildWnd
->szPath
, (HMENU
) TREE_WINDOW
);
345 pChildWnd
->hListWnd
= CreateListView(hWnd
, (HMENU
) LIST_WINDOW
/*, pChildWnd->szPath*/);
346 SetFocus(pChildWnd
->hTreeWnd
);
348 /* set the address bar and button font */
349 if ((pChildWnd
->hAddressBarWnd
) && (pChildWnd
->hAddressBtnWnd
))
351 hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
352 SendMessage(pChildWnd
->hAddressBarWnd
,
356 SendMessage(pChildWnd
->hAddressBtnWnd
,
361 /* Subclass the AddressBar */
362 oldproc
= (WNDPROC
)(LONG_PTR
)GetWindowLongPtr(pChildWnd
->hAddressBarWnd
, GWL_WNDPROC
);
363 SetWindowLongPtr(pChildWnd
->hAddressBarWnd
, GWL_USERDATA
, (DWORD_PTR
)oldproc
);
364 SetWindowLongPtr(pChildWnd
->hAddressBarWnd
, GWL_WNDPROC
, (DWORD_PTR
)AddressBarProc
);
368 if(HIWORD(wParam
) == BN_CLICKED
)
370 PostMessage(pChildWnd
->hAddressBarWnd
, WM_KEYUP
, VK_RETURN
, 0);
372 else if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
381 if (LOWORD(lParam
) == HTCLIENT
)
385 ScreenToClient(hWnd
, &pt
);
386 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1)
388 SetCursor(LoadCursor(0, IDC_SIZEWE
));
395 DestroyListView(pChildWnd
->hListWnd
);
397 HeapFree(GetProcessHeap(), 0, pChildWnd
);
404 int x
= (short)LOWORD(lParam
);
405 GetClientRect(hWnd
, &rt
);
406 if (x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1)
408 last_split
= pChildWnd
->nSplitPos
;
409 draw_splitbar(hWnd
, last_split
);
417 if (GetCapture() == hWnd
)
419 finish_splitbar(hWnd
, LOWORD(lParam
));
423 case WM_CAPTURECHANGED
:
424 if (GetCapture()==hWnd
&& last_split
>=0)
425 draw_splitbar(hWnd
, last_split
);
429 if (wParam
== VK_ESCAPE
)
430 if (GetCapture() == hWnd
)
433 draw_splitbar(hWnd
, last_split
);
434 GetClientRect(hWnd
, &rt
);
435 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
438 SetCursor(LoadCursor(0, IDC_ARROW
));
443 if (GetCapture() == hWnd
)
448 int x
= LOWORD(lParam
);
451 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
452 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
456 SizingBrush
= CreatePatternBrush(SizingPattern
);
459 GetClientRect(hWnd
, &rt
);
460 x
= (SHORT
) min(max(x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
463 rt
.left
= last_split
-SPLIT_WIDTH
/2;
464 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
466 OldObj
= SelectObject(hdc
, SizingBrush
);
467 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
469 rt
.left
= x
-SPLIT_WIDTH
/2;
470 rt
.right
= x
+SPLIT_WIDTH
/2+1;
471 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
472 SelectObject(hdc
, OldObj
);
473 ReleaseDC(hWnd
, hdc
);
479 if (pChildWnd
!= NULL
)
481 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
489 if ((int)wParam
== TREE_WINDOW
)
491 switch (((LPNMHDR
)lParam
)->code
)
493 case TVN_ITEMEXPANDING
:
494 return !OnTreeExpanding(pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
497 LPCTSTR keyPath
, rootName
;
501 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, &hRootKey
);
504 RefreshListView(pChildWnd
->hListWnd
, hRootKey
, keyPath
);
505 rootName
= get_root_key_name(hRootKey
);
506 fullPath
= HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName
) + 1 + _tcslen(keyPath
) + 1) * sizeof(TCHAR
));
509 /* set (correct) the address bar text */
510 if(keyPath
[0] != '\0')
511 _stprintf(fullPath
, _T("%s\\%s"), rootName
, keyPath
);
513 fullPath
= _tcscpy(fullPath
, rootName
);
514 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
515 SendMessage(pChildWnd
->hAddressBarWnd
, WM_SETTEXT
, 0, (LPARAM
)fullPath
);
516 HeapFree(GetProcessHeap(), 0, fullPath
);
517 /* disable hive manipulation items temporarily (enable only if necessary) */
518 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_LOADHIVE
, MF_BYCOMMAND
| MF_GRAYED
);
519 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_UNLOADHIVE
, MF_BYCOMMAND
| MF_GRAYED
);
520 /* compare the strings to see if we should enable/disable the "Load Hive" menus accordingly */
521 if (!(_tcsicmp(rootName
, TEXT("HKEY_LOCAL_MACHINE")) &&
522 _tcsicmp(rootName
, TEXT("HKEY_USERS"))))
524 // enable the unload menu item if at the root
525 // otherwise enable the load menu item if there is no slash in keyPath (ie. immediate child selected)
526 if(keyPath
[0] == '\0')
527 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_LOADHIVE
, MF_BYCOMMAND
| MF_ENABLED
);
528 else if(!_tcschr(keyPath
, _T('\\')))
529 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_UNLOADHIVE
, MF_BYCOMMAND
| MF_ENABLED
);
534 TCHAR szBuffer
[MAX_PATH
];
535 _sntprintf(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), _T("My Computer\\%s\\%s"), rootName
, keyPath
);
537 if (RegCreateKey(HKEY_CURRENT_USER
,
539 &hKey
) == ERROR_SUCCESS
)
541 RegSetValueEx(hKey
, _T("LastKey"), 0, REG_SZ
, (LPBYTE
) szBuffer
, (DWORD
) _tcslen(szBuffer
) * sizeof(szBuffer
[0]));
550 pChildWnd
->nFocusPanel
= 0;
552 case TVN_BEGINLABELEDIT
:
554 LPNMTVDISPINFO ptvdi
;
555 /* cancel label edit for rootkeys */
556 ptvdi
= (LPNMTVDISPINFO
) lParam
;
557 if (!TreeView_GetParent(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
) ||
558 !TreeView_GetParent(pChildWnd
->hTreeWnd
, TreeView_GetParent(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
)))
562 case TVN_ENDLABELEDIT
:
567 LPNMTVDISPINFO ptvdi
;
569 TCHAR szBuffer
[MAX_PATH
];
571 ptvdi
= (LPNMTVDISPINFO
) lParam
;
572 if (ptvdi
->item
.pszText
)
574 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, TreeView_GetParent(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
), &hRootKey
);
575 _sntprintf(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), _T("%s\\%s"), keyPath
, ptvdi
->item
.pszText
);
576 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
, &hRootKey
);
577 if (RegOpenKeyEx(hRootKey
, szBuffer
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
581 (void)TreeView_EditLabel(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
);
585 if (RenameKey(hRootKey
, keyPath
, ptvdi
->item
.pszText
) != ERROR_SUCCESS
)
597 if ((int)wParam
== LIST_WINDOW
)
599 switch (((LPNMHDR
)lParam
)->code
)
602 pChildWnd
->nFocusPanel
= 1;
605 if(!ListWndNotifyProc(pChildWnd
->hListWnd
, wParam
, lParam
, &Result
))
619 if((HWND
)wParam
== pChildWnd
->hListWnd
)
623 pt
.x
= (short) LOWORD(lParam
);
624 pt
.y
= (short) HIWORD(lParam
);
625 cnt
= ListView_GetSelectedCount(pChildWnd
->hListWnd
);
626 i
= ListView_GetNextItem(pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
627 if (pt
.x
== -1 && pt
.y
== -1)
632 rc
.left
= LVIR_BOUNDS
;
633 SendMessage(pChildWnd
->hListWnd
, LVM_GETITEMRECT
, i
, (LPARAM
) &rc
);
639 ClientToScreen(pChildWnd
->hListWnd
, &pt
);
643 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
647 HMENU mnu
= GetSubMenu(hPopupMenus
, PM_MODIFYVALUE
);
648 SetMenuDefaultItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
649 IsDefault
= IsDefaultValue(pChildWnd
->hListWnd
, i
);
651 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| (IsDefault
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
653 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
654 EnableMenuItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
655 EnableMenuItem(mnu
, ID_EDIT_MODIFY_BIN
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
657 TrackPopupMenu(mnu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
660 else if ((HWND
)wParam
== pChildWnd
->hTreeWnd
)
674 pt
.x
= (short) LOWORD(lParam
);
675 pt
.y
= (short) HIWORD(lParam
);
677 if (pt
.x
== -1 && pt
.y
== -1)
680 hti
.hItem
= TreeView_GetSelection(pChildWnd
->hTreeWnd
);
681 if (hti
.hItem
!= NULL
)
683 TreeView_GetItemRect(pChildWnd
->hTreeWnd
, hti
.hItem
, &rc
, TRUE
);
686 ClientToScreen(pChildWnd
->hTreeWnd
, &pt
);
687 hti
.flags
= TVHT_ONITEM
;
696 ScreenToClient(pChildWnd
->hTreeWnd
, &hti
.pt
);
697 (void)TreeView_HitTest(pChildWnd
->hTreeWnd
, &hti
);
700 if (hti
.flags
& TVHT_ONITEM
)
702 hContextMenu
= GetSubMenu(hPopupMenus
, PM_TREECONTEXT
);
703 (void)TreeView_SelectItem(pChildWnd
->hTreeWnd
, hti
.hItem
);
705 memset(&item
, 0, sizeof(item
));
706 item
.mask
= TVIF_STATE
| TVIF_CHILDREN
;
707 item
.hItem
= hti
.hItem
;
708 (void)TreeView_GetItem(pChildWnd
->hTreeWnd
, &item
);
710 /* Set the Expand/Collapse menu item appropriately */
711 LoadString(hInst
, (item
.state
& TVIS_EXPANDED
) ? IDS_COLLAPSE
: IDS_EXPAND
, buffer
, sizeof(buffer
) / sizeof(buffer
[0]));
712 memset(&mii
, 0, sizeof(mii
));
713 mii
.cbSize
= sizeof(mii
);
714 mii
.fMask
= MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
715 mii
.fState
= (item
.cChildren
> 0) ? MFS_DEFAULT
: MFS_GRAYED
;
716 mii
.wID
= (item
.state
& TVIS_EXPANDED
) ? ID_TREE_COLLAPSEBRANCH
: ID_TREE_EXPANDBRANCH
;
717 mii
.dwTypeData
= (LPTSTR
) buffer
;
718 SetMenuItemInfo(hContextMenu
, 0, TRUE
, &mii
);
720 /* Remove any existing suggestions */
721 memset(&mii
, 0, sizeof(mii
));
722 mii
.cbSize
= sizeof(mii
);
724 GetMenuItemInfo(hContextMenu
, GetMenuItemCount(hContextMenu
) - 1, TRUE
, &mii
);
725 if ((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
))
729 iLastPos
= GetMenuItemCount(hContextMenu
) - 1;
730 GetMenuItemInfo(hContextMenu
, iLastPos
, TRUE
, &mii
);
731 RemoveMenu(hContextMenu
, iLastPos
, MF_BYPOSITION
);
733 while((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
));
736 /* Come up with suggestions */
737 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, NULL
, &hRootKey
);
738 SuggestKeys(hRootKey
, keyPath
, Suggestions
, sizeof(Suggestions
) / sizeof(Suggestions
[0]));
741 AppendMenu(hContextMenu
, MF_SEPARATOR
, 0, NULL
);
743 LoadString(hInst
, IDS_GOTO_SUGGESTED_KEY
, resource
, sizeof(resource
) / sizeof(resource
[0]));
746 wID
= ID_TREE_SUGGESTION_MIN
;
747 while(*s
&& (wID
<= ID_TREE_SUGGESTION_MAX
))
749 _sntprintf(buffer
, sizeof(buffer
) / sizeof(buffer
[0]), resource
, s
);
751 memset(&mii
, 0, sizeof(mii
));
752 mii
.cbSize
= sizeof(mii
);
753 mii
.fMask
= MIIM_STRING
| MIIM_ID
;
755 mii
.dwTypeData
= buffer
;
756 InsertMenuItem(hContextMenu
, GetMenuItemCount(hContextMenu
), TRUE
, &mii
);
761 TrackPopupMenu(hContextMenu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, pChildWnd
->hWnd
, NULL
);
768 if (wParam
!= SIZE_MINIMIZED
&& pChildWnd
!= NULL
)
770 ResizeWnd(pChildWnd
, LOWORD(lParam
), HIWORD(lParam
));
775 return DefWindowProc(hWnd
, message
, wParam
, lParam
);