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(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(g_pChildWnd
->hAddressBtnWnd
, &rb
);
81 cx
= g_pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
82 DeferWindowPos(hdwp
, g_pChildWnd
->hAddressBarWnd
, 0, rt
.left
, rt
.top
, rt
.right
-rt
.left
- tHeight
-2, tHeight
, SWP_NOZORDER
|SWP_NOACTIVATE
);
83 DeferWindowPos(hdwp
, g_pChildWnd
->hAddressBtnWnd
, 0, rt
.right
- tHeight
, rt
.top
, tHeight
, tHeight
, SWP_NOZORDER
|SWP_NOACTIVATE
);
84 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
);
85 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
);
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(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 HTREEITEM hSelection
;
131 WORD wID
= LOWORD(wParam
);
133 UNREFERENCED_PARAMETER(message
);
137 /* Parse the menu selections: */
138 case ID_REGISTRY_EXIT
:
141 case ID_VIEW_REFRESH
:
144 case ID_TREE_EXPANDBRANCH
:
145 (void)TreeView_Expand(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
), TVE_EXPAND
);
147 case ID_TREE_COLLAPSEBRANCH
:
148 (void)TreeView_Expand(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
), TVE_COLLAPSE
);
151 SetFocus(g_pChildWnd
->hTreeWnd
);
152 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
155 hSelection
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
156 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
158 if (keyPath
== 0 || *keyPath
== 0)
160 MessageBeep(MB_ICONHAND
);
162 else if (DeleteKey(hWnd
, hRootKey
, keyPath
))
163 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
166 ExportRegistryFile(g_pChildWnd
->hTreeWnd
);
171 case ID_EDIT_COPYKEYNAME
:
172 hSelection
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
173 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
174 CopyKeyName(hWnd
, hRootKey
, keyPath
);
176 case ID_EDIT_NEW_KEY
:
177 CreateNewKey(g_pChildWnd
->hTreeWnd
, TreeView_GetSelection(g_pChildWnd
->hTreeWnd
));
179 case ID_EDIT_NEW_STRINGVALUE
:
180 case ID_EDIT_NEW_BINARYVALUE
:
181 case ID_EDIT_NEW_DWORDVALUE
:
182 SendMessage(hFrameWnd
, WM_COMMAND
, wParam
, lParam
);
184 case ID_SWITCH_PANELS
:
185 g_pChildWnd
->nFocusPanel
= !g_pChildWnd
->nFocusPanel
;
186 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
189 if ((wID
>= ID_TREE_SUGGESTION_MIN
) && (wID
<= ID_TREE_SUGGESTION_MAX
))
192 while(wID
> ID_TREE_SUGGESTION_MIN
)
198 SelectNode(g_pChildWnd
->hTreeWnd
, s
);
206 /*******************************************************************************
211 #define MIN(a,b) ((a < b) ? (a) : (b))
213 static void SuggestKeys(HKEY hRootKey
, LPCTSTR pszKeyPath
, LPTSTR pszSuggestions
,
214 size_t iSuggestionsLength
)
217 TCHAR szLastFound
[256];
219 HKEY hOtherKey
, hSubKey
;
222 memset(pszSuggestions
, 0, iSuggestionsLength
* sizeof(*pszSuggestions
));
223 iSuggestionsLength
--;
225 /* Are we a root key in HKEY_CLASSES_ROOT? */
226 if ((hRootKey
== HKEY_CLASSES_ROOT
) && pszKeyPath
[0] && !_tcschr(pszKeyPath
, TEXT('\\')))
232 /* Check default key */
233 if (QueryStringValue(hRootKey
, pszKeyPath
, NULL
,
234 szBuffer
, COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
236 /* Sanity check this key; it cannot be empty, nor can it be a
238 if ((szBuffer
[0] != '\0') && _tcsicmp(szBuffer
, pszKeyPath
))
240 if (RegOpenKey(hRootKey
, szBuffer
, &hOtherKey
) == ERROR_SUCCESS
)
242 lstrcpyn(pszSuggestions
, TEXT("HKCR\\"), (int) iSuggestionsLength
);
243 i
= _tcslen(pszSuggestions
);
245 iSuggestionsLength
-= i
;
247 lstrcpyn(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
248 i
= MIN(_tcslen(pszSuggestions
) + 1, iSuggestionsLength
);
250 iSuggestionsLength
-= i
;
251 RegCloseKey(hOtherKey
);
254 _tcscpy(szLastFound
, szBuffer
);
255 pszKeyPath
= szLastFound
;
260 while(bFound
&& (iSuggestionsLength
> 0));
262 /* Check CLSID key */
263 if (RegOpenKey(hRootKey
, pszKeyPath
, &hSubKey
) == ERROR_SUCCESS
)
265 if (QueryStringValue(hSubKey
, TEXT("CLSID"), NULL
, szBuffer
,
266 COUNT_OF(szBuffer
)) == ERROR_SUCCESS
)
268 lstrcpyn(pszSuggestions
, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength
);
269 i
= _tcslen(pszSuggestions
);
271 iSuggestionsLength
-= i
;
273 lstrcpyn(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
274 i
= MIN(_tcslen(pszSuggestions
) + 1, iSuggestionsLength
);
276 iSuggestionsLength
-= i
;
278 RegCloseKey(hSubKey
);
284 LRESULT CALLBACK
AddressBarProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
287 static TCHAR s_szNode
[256];
288 oldwndproc
= (WNDPROC
)(LONG_PTR
)GetWindowLongPtr(hwnd
, GWL_USERDATA
);
293 if (wParam
== VK_RETURN
)
295 GetWindowText(hwnd
, s_szNode
, sizeof(s_szNode
) / sizeof(s_szNode
[0]));
296 SelectNode(g_pChildWnd
->hTreeWnd
, s_szNode
);
302 return CallWindowProc(oldwndproc
, hwnd
, uMsg
, wParam
, lParam
);
305 /*******************************************************************************
307 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
309 * PURPOSE: Processes messages for the child windows.
311 * WM_COMMAND - process the application menu
312 * WM_PAINT - Paint the main window
313 * WM_DESTROY - post a quit message and return
316 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
326 TCHAR buffer
[MAX_PATH
];
327 /* load "My Computer" string */
328 LoadString(hInst
, IDS_MY_COMPUTER
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
330 g_pChildWnd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ChildWnd
));
331 if (!g_pChildWnd
) return 0;
333 _tcsncpy(g_pChildWnd
->szPath
, buffer
, MAX_PATH
);
334 g_pChildWnd
->nSplitPos
= 250;
335 g_pChildWnd
->hWnd
= hWnd
;
336 g_pChildWnd
->hAddressBarWnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Edit"), NULL
, WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
,
337 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
338 hWnd
, (HMENU
)0, hInst
, 0);
339 g_pChildWnd
->hAddressBtnWnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Button"), _T("»"), WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
| BS_DEFPUSHBUTTON
,
340 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
341 hWnd
, (HMENU
)0, hInst
, 0);
342 g_pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, g_pChildWnd
->szPath
, (HMENU
) TREE_WINDOW
);
343 g_pChildWnd
->hListWnd
= CreateListView(hWnd
, (HMENU
) LIST_WINDOW
/*, g_pChildWnd->szPath*/);
344 SetFocus(g_pChildWnd
->hTreeWnd
);
346 /* set the address bar and button font */
347 if ((g_pChildWnd
->hAddressBarWnd
) && (g_pChildWnd
->hAddressBtnWnd
))
349 hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
350 SendMessage(g_pChildWnd
->hAddressBarWnd
,
354 SendMessage(g_pChildWnd
->hAddressBtnWnd
,
359 /* Subclass the AddressBar */
360 oldproc
= (WNDPROC
)(LONG_PTR
)GetWindowLongPtr(g_pChildWnd
->hAddressBarWnd
, GWL_WNDPROC
);
361 SetWindowLongPtr(g_pChildWnd
->hAddressBarWnd
, GWL_USERDATA
, (DWORD_PTR
)oldproc
);
362 SetWindowLongPtr(g_pChildWnd
->hAddressBarWnd
, GWL_WNDPROC
, (DWORD_PTR
)AddressBarProc
);
366 if(HIWORD(wParam
) == BN_CLICKED
)
368 PostMessage(g_pChildWnd
->hAddressBarWnd
, WM_KEYUP
, VK_RETURN
, 0);
370 else if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
))
379 if (LOWORD(lParam
) == HTCLIENT
)
383 ScreenToClient(hWnd
, &pt
);
384 if (pt
.x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1)
386 SetCursor(LoadCursor(0, IDC_SIZEWE
));
393 DestroyListView(g_pChildWnd
->hListWnd
);
395 HeapFree(GetProcessHeap(), 0, g_pChildWnd
);
402 int x
= (short)LOWORD(lParam
);
403 GetClientRect(hWnd
, &rt
);
404 if (x
>=g_pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<g_pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1)
406 last_split
= g_pChildWnd
->nSplitPos
;
407 draw_splitbar(hWnd
, last_split
);
415 if (GetCapture() == hWnd
)
417 finish_splitbar(hWnd
, LOWORD(lParam
));
421 case WM_CAPTURECHANGED
:
422 if (GetCapture()==hWnd
&& last_split
>=0)
423 draw_splitbar(hWnd
, last_split
);
427 if (wParam
== VK_ESCAPE
)
428 if (GetCapture() == hWnd
)
431 draw_splitbar(hWnd
, last_split
);
432 GetClientRect(hWnd
, &rt
);
433 ResizeWnd(rt
.right
, rt
.bottom
);
436 SetCursor(LoadCursor(0, IDC_ARROW
));
441 if (GetCapture() == hWnd
)
446 int x
= LOWORD(lParam
);
449 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
450 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
454 SizingBrush
= CreatePatternBrush(SizingPattern
);
457 GetClientRect(hWnd
, &rt
);
458 x
= (SHORT
) min(max(x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
461 rt
.left
= last_split
-SPLIT_WIDTH
/2;
462 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
464 OldObj
= SelectObject(hdc
, SizingBrush
);
465 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
467 rt
.left
= x
-SPLIT_WIDTH
/2;
468 rt
.right
= x
+SPLIT_WIDTH
/2+1;
469 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
470 SelectObject(hdc
, OldObj
);
471 ReleaseDC(hWnd
, hdc
);
477 if (g_pChildWnd
!= NULL
)
479 SetFocus(g_pChildWnd
->nFocusPanel
? g_pChildWnd
->hListWnd
: g_pChildWnd
->hTreeWnd
);
487 if ((int)wParam
== TREE_WINDOW
&& g_pChildWnd
!= NULL
)
489 switch (((LPNMHDR
)lParam
)->code
)
491 case TVN_ITEMEXPANDING
:
492 return !OnTreeExpanding(g_pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
495 LPCTSTR keyPath
, rootName
;
499 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, &hRootKey
);
502 RefreshListView(g_pChildWnd
->hListWnd
, hRootKey
, keyPath
);
503 rootName
= get_root_key_name(hRootKey
);
504 fullPath
= HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName
) + 1 + _tcslen(keyPath
) + 1) * sizeof(TCHAR
));
507 /* set (correct) the address bar text */
508 if(keyPath
[0] != '\0')
509 _stprintf(fullPath
, _T("%s\\%s"), rootName
, keyPath
);
511 fullPath
= _tcscpy(fullPath
, rootName
);
512 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
513 SendMessage(g_pChildWnd
->hAddressBarWnd
, WM_SETTEXT
, 0, (LPARAM
)fullPath
);
514 HeapFree(GetProcessHeap(), 0, fullPath
);
515 /* disable hive manipulation items temporarily (enable only if necessary) */
516 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_LOADHIVE
, MF_BYCOMMAND
| MF_GRAYED
);
517 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_UNLOADHIVE
, MF_BYCOMMAND
| MF_GRAYED
);
518 /* compare the strings to see if we should enable/disable the "Load Hive" menus accordingly */
519 if (!(_tcsicmp(rootName
, TEXT("HKEY_LOCAL_MACHINE")) &&
520 _tcsicmp(rootName
, TEXT("HKEY_USERS"))))
522 // enable the unload menu item if at the root
523 // otherwise enable the load menu item if there is no slash in keyPath (ie. immediate child selected)
524 if(keyPath
[0] == '\0')
525 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_LOADHIVE
, MF_BYCOMMAND
| MF_ENABLED
);
526 else if(!_tcschr(keyPath
, _T('\\')))
527 EnableMenuItem(GetSubMenu(hMenuFrame
,0), ID_REGISTRY_UNLOADHIVE
, MF_BYCOMMAND
| MF_ENABLED
);
532 TCHAR szBuffer
[MAX_PATH
];
533 _sntprintf(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), _T("My Computer\\%s\\%s"), rootName
, keyPath
);
535 if (RegCreateKey(HKEY_CURRENT_USER
,
537 &hKey
) == ERROR_SUCCESS
)
539 RegSetValueEx(hKey
, _T("LastKey"), 0, REG_SZ
, (LPBYTE
) szBuffer
, (DWORD
) _tcslen(szBuffer
) * sizeof(szBuffer
[0]));
548 g_pChildWnd
->nFocusPanel
= 0;
550 case TVN_BEGINLABELEDIT
:
552 LPNMTVDISPINFO ptvdi
;
553 /* cancel label edit for rootkeys */
554 ptvdi
= (LPNMTVDISPINFO
) lParam
;
555 if (!TreeView_GetParent(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
) ||
556 !TreeView_GetParent(g_pChildWnd
->hTreeWnd
, TreeView_GetParent(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
)))
560 case TVN_ENDLABELEDIT
:
565 LPNMTVDISPINFO ptvdi
;
567 TCHAR szBuffer
[MAX_PATH
];
569 ptvdi
= (LPNMTVDISPINFO
) lParam
;
570 if (ptvdi
->item
.pszText
)
572 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, TreeView_GetParent(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
), &hRootKey
);
573 _sntprintf(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), _T("%s\\%s"), keyPath
, ptvdi
->item
.pszText
);
574 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
, &hRootKey
);
575 if (RegOpenKeyEx(hRootKey
, szBuffer
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
579 (void)TreeView_EditLabel(g_pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
);
583 if (RenameKey(hRootKey
, keyPath
, ptvdi
->item
.pszText
) != ERROR_SUCCESS
)
595 if ((int)wParam
== LIST_WINDOW
&& g_pChildWnd
!= NULL
)
597 switch (((LPNMHDR
)lParam
)->code
)
600 g_pChildWnd
->nFocusPanel
= 1;
603 if(!ListWndNotifyProc(g_pChildWnd
->hListWnd
, wParam
, lParam
, &Result
))
617 if((HWND
)wParam
== g_pChildWnd
->hListWnd
)
621 pt
.x
= (short) LOWORD(lParam
);
622 pt
.y
= (short) HIWORD(lParam
);
623 cnt
= ListView_GetSelectedCount(g_pChildWnd
->hListWnd
);
624 i
= ListView_GetNextItem(g_pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
625 if (pt
.x
== -1 && pt
.y
== -1)
630 rc
.left
= LVIR_BOUNDS
;
631 SendMessage(g_pChildWnd
->hListWnd
, LVM_GETITEMRECT
, i
, (LPARAM
) &rc
);
637 ClientToScreen(g_pChildWnd
->hListWnd
, &pt
);
641 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
645 HMENU mnu
= GetSubMenu(hPopupMenus
, PM_MODIFYVALUE
);
646 SetMenuDefaultItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
647 IsDefault
= IsDefaultValue(g_pChildWnd
->hListWnd
, i
);
649 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| (IsDefault
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
651 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
652 EnableMenuItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
653 EnableMenuItem(mnu
, ID_EDIT_MODIFY_BIN
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
655 TrackPopupMenu(mnu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
658 else if ((HWND
)wParam
== g_pChildWnd
->hTreeWnd
)
672 pt
.x
= (short) LOWORD(lParam
);
673 pt
.y
= (short) HIWORD(lParam
);
675 if (pt
.x
== -1 && pt
.y
== -1)
678 hti
.hItem
= TreeView_GetSelection(g_pChildWnd
->hTreeWnd
);
679 if (hti
.hItem
!= NULL
)
681 TreeView_GetItemRect(g_pChildWnd
->hTreeWnd
, hti
.hItem
, &rc
, TRUE
);
684 ClientToScreen(g_pChildWnd
->hTreeWnd
, &pt
);
685 hti
.flags
= TVHT_ONITEM
;
694 ScreenToClient(g_pChildWnd
->hTreeWnd
, &hti
.pt
);
695 (void)TreeView_HitTest(g_pChildWnd
->hTreeWnd
, &hti
);
698 if (hti
.flags
& TVHT_ONITEM
)
700 hContextMenu
= GetSubMenu(hPopupMenus
, PM_TREECONTEXT
);
701 (void)TreeView_SelectItem(g_pChildWnd
->hTreeWnd
, hti
.hItem
);
703 memset(&item
, 0, sizeof(item
));
704 item
.mask
= TVIF_STATE
| TVIF_CHILDREN
;
705 item
.hItem
= hti
.hItem
;
706 (void)TreeView_GetItem(g_pChildWnd
->hTreeWnd
, &item
);
708 /* Set the Expand/Collapse menu item appropriately */
709 LoadString(hInst
, (item
.state
& TVIS_EXPANDED
) ? IDS_COLLAPSE
: IDS_EXPAND
, buffer
, sizeof(buffer
) / sizeof(buffer
[0]));
710 memset(&mii
, 0, sizeof(mii
));
711 mii
.cbSize
= sizeof(mii
);
712 mii
.fMask
= MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
713 mii
.fState
= (item
.cChildren
> 0) ? MFS_DEFAULT
: MFS_GRAYED
;
714 mii
.wID
= (item
.state
& TVIS_EXPANDED
) ? ID_TREE_COLLAPSEBRANCH
: ID_TREE_EXPANDBRANCH
;
715 mii
.dwTypeData
= (LPTSTR
) buffer
;
716 SetMenuItemInfo(hContextMenu
, 0, TRUE
, &mii
);
718 /* Remove any existing suggestions */
719 memset(&mii
, 0, sizeof(mii
));
720 mii
.cbSize
= sizeof(mii
);
722 GetMenuItemInfo(hContextMenu
, GetMenuItemCount(hContextMenu
) - 1, TRUE
, &mii
);
723 if ((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
))
727 iLastPos
= GetMenuItemCount(hContextMenu
) - 1;
728 GetMenuItemInfo(hContextMenu
, iLastPos
, TRUE
, &mii
);
729 RemoveMenu(hContextMenu
, iLastPos
, MF_BYPOSITION
);
731 while((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
));
734 /* Come up with suggestions */
735 keyPath
= GetItemPath(g_pChildWnd
->hTreeWnd
, NULL
, &hRootKey
);
736 SuggestKeys(hRootKey
, keyPath
, Suggestions
, sizeof(Suggestions
) / sizeof(Suggestions
[0]));
739 AppendMenu(hContextMenu
, MF_SEPARATOR
, 0, NULL
);
741 LoadString(hInst
, IDS_GOTO_SUGGESTED_KEY
, resource
, sizeof(resource
) / sizeof(resource
[0]));
744 wID
= ID_TREE_SUGGESTION_MIN
;
745 while(*s
&& (wID
<= ID_TREE_SUGGESTION_MAX
))
747 _sntprintf(buffer
, sizeof(buffer
) / sizeof(buffer
[0]), resource
, s
);
749 memset(&mii
, 0, sizeof(mii
));
750 mii
.cbSize
= sizeof(mii
);
751 mii
.fMask
= MIIM_STRING
| MIIM_ID
;
753 mii
.dwTypeData
= buffer
;
754 InsertMenuItem(hContextMenu
, GetMenuItemCount(hContextMenu
), TRUE
, &mii
);
759 TrackPopupMenu(hContextMenu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, g_pChildWnd
->hWnd
, NULL
);
766 if (wParam
!= SIZE_MINIMIZED
&& g_pChildWnd
!= NULL
)
768 ResizeWnd(LOWORD(lParam
), HIWORD(lParam
));
773 return DefWindowProc(hWnd
, message
, wParam
, lParam
);