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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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(2);
73 SetRect(&rt
, 0, 0, cx
, cy
);
75 if (hStatusBar
!= NULL
) {
76 GetWindowRect(hStatusBar
, &rs
);
77 cy
= rs
.bottom
- rs
.top
+ 8;
79 cx
= pChildWnd
->nSplitPos
+ SPLIT_WIDTH
/2;
80 DeferWindowPos(hdwp
, pChildWnd
->hAddressBarWnd
, 0, rt
.left
, rt
.top
, rt
.right
-rt
.left
, 23, SWP_NOZORDER
|SWP_NOACTIVATE
);
81 DeferWindowPos(hdwp
, pChildWnd
->hTreeWnd
, 0, rt
.left
, rt
.top
+ 25, pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2-rt
.left
, rt
.bottom
-rt
.top
-cy
, SWP_NOZORDER
|SWP_NOACTIVATE
);
82 DeferWindowPos(hdwp
, pChildWnd
->hListWnd
, 0, rt
.left
+cx
, rt
.top
+ 25, rt
.right
-cx
, rt
.bottom
-rt
.top
-cy
, SWP_NOZORDER
|SWP_NOACTIVATE
);
83 EndDeferWindowPos(hdwp
);
86 static void OnPaint(HWND hWnd
)
92 GetClientRect(hWnd
, &rt
);
93 hdc
= BeginPaint(hWnd
, &ps
);
94 FillRect(ps
.hdc
, &rt
, GetSysColorBrush(COLOR_BTNFACE
));
98 /*******************************************************************************
99 * finish_splitbar [internal]
101 * make the splitbar invisible and resize the windows
102 * (helper for ChildWndProc)
104 static void finish_splitbar(HWND hWnd
, int x
)
108 draw_splitbar(hWnd
, last_split
);
110 GetClientRect(hWnd
, &rt
);
111 g_pChildWnd
->nSplitPos
= x
;
112 ResizeWnd(g_pChildWnd
, rt
.right
, rt
.bottom
);
116 /*******************************************************************************
118 * FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
120 * PURPOSE: Processes WM_COMMAND messages for the main frame window.
124 static BOOL
_CmdWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
126 ChildWnd
* pChildWnd
= g_pChildWnd
;
127 HTREEITEM hSelection
;
130 WORD wID
= LOWORD(wParam
);
132 UNREFERENCED_PARAMETER(message
);
135 /* Parse the menu selections: */
136 case ID_REGISTRY_EXIT
:
139 case ID_VIEW_REFRESH
:
142 case ID_TREE_EXPANDBRANCH
:
143 (void)TreeView_Expand(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
), TVE_EXPAND
);
145 case ID_TREE_COLLAPSEBRANCH
:
146 (void)TreeView_Expand(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
), TVE_COLLAPSE
);
149 SetFocus(pChildWnd
->hTreeWnd
);
150 (void)TreeView_EditLabel(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
));
153 hSelection
= TreeView_GetSelection(pChildWnd
->hTreeWnd
);
154 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
156 if (keyPath
== 0 || *keyPath
== 0)
158 MessageBeep(MB_ICONHAND
);
160 if (DeleteKey(hWnd
, hRootKey
, keyPath
))
161 DeleteNode(g_pChildWnd
->hTreeWnd
, 0);
164 ExportRegistryFile(pChildWnd
->hTreeWnd
);
169 case ID_EDIT_COPYKEYNAME
:
170 hSelection
= TreeView_GetSelection(pChildWnd
->hTreeWnd
);
171 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, hSelection
, &hRootKey
);
172 CopyKeyName(hWnd
, hRootKey
, keyPath
);
174 case ID_EDIT_NEW_KEY
:
175 CreateNewKey(pChildWnd
->hTreeWnd
, TreeView_GetSelection(pChildWnd
->hTreeWnd
));
177 case ID_EDIT_NEW_STRINGVALUE
:
178 case ID_EDIT_NEW_BINARYVALUE
:
179 case ID_EDIT_NEW_DWORDVALUE
:
180 SendMessage(hFrameWnd
, WM_COMMAND
, wParam
, lParam
);
182 case ID_SWITCH_PANELS
:
183 pChildWnd
->nFocusPanel
= !pChildWnd
->nFocusPanel
;
184 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
187 if ((wID
>= ID_TREE_SUGGESTION_MIN
) && (wID
<= ID_TREE_SUGGESTION_MAX
))
190 while(wID
> ID_TREE_SUGGESTION_MIN
)
196 SelectNode(pChildWnd
->hTreeWnd
, s
);
204 /*******************************************************************************
209 #define MIN(a,b) ((a < b) ? (a) : (b))
211 static void SuggestKeys(HKEY hRootKey
, LPCTSTR pszKeyPath
, LPTSTR pszSuggestions
,
212 size_t iSuggestionsLength
)
215 TCHAR szLastFound
[256];
217 HKEY hOtherKey
, hSubKey
;
220 memset(pszSuggestions
, 0, iSuggestionsLength
* sizeof(*pszSuggestions
));
221 iSuggestionsLength
--;
223 /* Are we a root key in HKEY_CLASSES_ROOT? */
224 if ((hRootKey
== HKEY_CLASSES_ROOT
) && pszKeyPath
[0] && !_tcschr(pszKeyPath
, TEXT('\\')))
230 /* Check default key */
231 if (RegQueryStringValue(hRootKey
, pszKeyPath
, NULL
,
232 szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0])) == ERROR_SUCCESS
)
234 /* Sanity check this key; it cannot be empty, nor can it be a
236 if ((szBuffer
[0] != '\0') && _tcsicmp(szBuffer
, pszKeyPath
))
238 if (RegOpenKey(hRootKey
, szBuffer
, &hOtherKey
) == ERROR_SUCCESS
)
240 lstrcpyn(pszSuggestions
, TEXT("HKCR\\"), (int) iSuggestionsLength
);
241 i
= _tcslen(pszSuggestions
);
243 iSuggestionsLength
-= i
;
245 lstrcpyn(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
246 i
= MIN(_tcslen(pszSuggestions
) + 1, iSuggestionsLength
);
248 iSuggestionsLength
-= i
;
249 RegCloseKey(hOtherKey
);
252 _tcscpy(szLastFound
, szBuffer
);
253 pszKeyPath
= szLastFound
;
258 while(bFound
&& (iSuggestionsLength
> 0));
260 /* Check CLSID key */
261 if (RegOpenKey(hRootKey
, pszKeyPath
, &hSubKey
) == ERROR_SUCCESS
)
263 if (RegQueryStringValue(hSubKey
, TEXT("CLSID"), NULL
,
264 szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0])) == ERROR_SUCCESS
)
266 lstrcpyn(pszSuggestions
, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength
);
267 i
= _tcslen(pszSuggestions
);
269 iSuggestionsLength
-= i
;
271 lstrcpyn(pszSuggestions
, szBuffer
, (int) iSuggestionsLength
);
272 i
= MIN(_tcslen(pszSuggestions
) + 1, iSuggestionsLength
);
274 iSuggestionsLength
-= i
;
276 RegCloseKey(hSubKey
);
282 LRESULT CALLBACK
AddressBarProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
285 static TCHAR s_szNode
[256];
286 oldwndproc
= (WNDPROC
)(LONG_PTR
)GetWindowLongPtr(hwnd
, GWL_USERDATA
);
291 if (wParam
== VK_RETURN
)
293 GetWindowText(hwnd
, s_szNode
, sizeof(s_szNode
) / sizeof(s_szNode
[0]));
294 SelectNode(g_pChildWnd
->hTreeWnd
, s_szNode
);
300 return CallWindowProc(oldwndproc
, hwnd
, uMsg
, wParam
, lParam
);
303 /* fix coords to top-left when SHIFT-F10 is pressed */
304 void FixPointIfContext(POINTS
*pt
, HWND hWnd
)
306 if (pt
->x
== -1 && pt
->y
== -1) {
308 ClientToScreen(hWnd
, &p
);
314 /*******************************************************************************
316 * FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
318 * PURPOSE: Processes messages for the child windows.
320 * WM_COMMAND - process the application menu
321 * WM_PAINT - Paint the main window
322 * WM_DESTROY - post a quit message and return
325 LRESULT CALLBACK
ChildWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
328 ChildWnd
* pChildWnd
= g_pChildWnd
;
335 TCHAR buffer
[MAX_PATH
];
336 /* load "My Computer" string */
337 LoadString(hInst
, IDS_MY_COMPUTER
, buffer
, sizeof(buffer
)/sizeof(TCHAR
));
339 g_pChildWnd
= pChildWnd
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ChildWnd
));
341 if (!pChildWnd
) return 0;
342 _tcsncpy(pChildWnd
->szPath
, buffer
, MAX_PATH
);
343 pChildWnd
->nSplitPos
= 250;
344 pChildWnd
->hWnd
= hWnd
;
345 pChildWnd
->hAddressBarWnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, _T("Edit"), NULL
, WS_CHILD
| WS_VISIBLE
| WS_CHILDWINDOW
| WS_TABSTOP
,
346 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
347 hWnd
, (HMENU
)0, hInst
, 0);
348 pChildWnd
->hTreeWnd
= CreateTreeView(hWnd
, pChildWnd
->szPath
, (HMENU
) TREE_WINDOW
);
349 pChildWnd
->hListWnd
= CreateListView(hWnd
, (HMENU
) LIST_WINDOW
/*, pChildWnd->szPath*/);
350 SetFocus(pChildWnd
->hTreeWnd
);
352 /* set the address bar font */
353 if (pChildWnd
->hAddressBarWnd
)
355 hFont
= (HFONT
)GetStockObject(DEFAULT_GUI_FONT
);
356 SendMessage(pChildWnd
->hAddressBarWnd
,
362 /* Subclass the AddressBar */
363 oldproc
= (WNDPROC
)(LONG_PTR
)GetWindowLongPtr(pChildWnd
->hAddressBarWnd
, GWL_WNDPROC
);
364 SetWindowLongPtr(pChildWnd
->hAddressBarWnd
, GWL_USERDATA
, (DWORD_PTR
)oldproc
);
365 SetWindowLongPtr(pChildWnd
->hAddressBarWnd
, GWL_WNDPROC
, (DWORD_PTR
)AddressBarProc
);
369 if (!_CmdWndProc(hWnd
, message
, wParam
, lParam
)) {
377 if (LOWORD(lParam
) == HTCLIENT
) {
380 ScreenToClient(hWnd
, &pt
);
381 if (pt
.x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && pt
.x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
382 SetCursor(LoadCursor(0, IDC_SIZEWE
));
389 DestroyListView(pChildWnd
->hListWnd
);
391 HeapFree(GetProcessHeap(), 0, pChildWnd
);
395 case WM_LBUTTONDOWN
: {
397 int x
= (short)LOWORD(lParam
);
398 GetClientRect(hWnd
, &rt
);
399 if (x
>=pChildWnd
->nSplitPos
-SPLIT_WIDTH
/2 && x
<pChildWnd
->nSplitPos
+SPLIT_WIDTH
/2+1) {
400 last_split
= pChildWnd
->nSplitPos
;
401 draw_splitbar(hWnd
, last_split
);
409 if (GetCapture() == hWnd
) {
410 finish_splitbar(hWnd
, LOWORD(lParam
));
414 case WM_CAPTURECHANGED
:
415 if (GetCapture()==hWnd
&& last_split
>=0)
416 draw_splitbar(hWnd
, last_split
);
420 if (wParam
== VK_ESCAPE
)
421 if (GetCapture() == hWnd
) {
423 draw_splitbar(hWnd
, last_split
);
424 GetClientRect(hWnd
, &rt
);
425 ResizeWnd(pChildWnd
, rt
.right
, rt
.bottom
);
428 SetCursor(LoadCursor(0, IDC_ARROW
));
433 if (GetCapture() == hWnd
) {
437 int x
= LOWORD(lParam
);
440 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
441 SizingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
445 SizingBrush
= CreatePatternBrush(SizingPattern
);
448 GetClientRect(hWnd
, &rt
);
449 x
= (SHORT
) min(max(x
, SPLIT_MIN
), rt
.right
- SPLIT_MIN
);
452 rt
.left
= last_split
-SPLIT_WIDTH
/2;
453 rt
.right
= last_split
+SPLIT_WIDTH
/2+1;
455 OldObj
= SelectObject(hdc
, SizingBrush
);
456 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
458 rt
.left
= x
-SPLIT_WIDTH
/2;
459 rt
.right
= x
+SPLIT_WIDTH
/2+1;
460 PatBlt(hdc
, rt
.left
, rt
.top
, rt
.right
- rt
.left
, rt
.bottom
- rt
.top
, PATINVERT
);
461 SelectObject(hdc
, OldObj
);
462 ReleaseDC(hWnd
, hdc
);
468 if (pChildWnd
!= NULL
) {
469 SetFocus(pChildWnd
->nFocusPanel
? pChildWnd
->hListWnd
: pChildWnd
->hTreeWnd
);
477 if ((int)wParam
== TREE_WINDOW
) {
478 switch (((LPNMHDR
)lParam
)->code
) {
479 case TVN_ITEMEXPANDING
:
480 return !OnTreeExpanding(pChildWnd
->hTreeWnd
, (NMTREEVIEW
*)lParam
);
481 case TVN_SELCHANGED
: {
482 LPCTSTR keyPath
, rootName
;
486 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, ((NMTREEVIEW
*)lParam
)->itemNew
.hItem
, &hRootKey
);
488 RefreshListView(pChildWnd
->hListWnd
, hRootKey
, keyPath
);
489 rootName
= get_root_key_name(hRootKey
);
490 fullPath
= HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName
) + 1 + _tcslen(keyPath
) + 1) * sizeof(TCHAR
));
492 _stprintf(fullPath
, _T("%s\\%s"), rootName
, keyPath
);
493 SendMessage(hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)fullPath
);
494 SendMessage(pChildWnd
->hAddressBarWnd
, WM_SETTEXT
, 0, (LPARAM
)fullPath
);
495 HeapFree(GetProcessHeap(), 0, fullPath
);
499 TCHAR szBuffer
[MAX_PATH
];
500 _sntprintf(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), _T("My Computer\\%s\\%s"), rootName
, keyPath
);
502 if (RegCreateKey(HKEY_CURRENT_USER
,
504 &hKey
) == ERROR_SUCCESS
)
506 RegSetValueEx(hKey
, _T("LastKey"), 0, REG_SZ
, (LPBYTE
) szBuffer
, (DWORD
) _tcslen(szBuffer
) * sizeof(szBuffer
[0]));
515 pChildWnd
->nFocusPanel
= 0;
517 case TVN_BEGINLABELEDIT
:
519 LPNMTVDISPINFO ptvdi
;
520 /* cancel label edit for rootkeys */
521 ptvdi
= (LPNMTVDISPINFO
) lParam
;
522 if (!TreeView_GetParent(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
) ||
523 !TreeView_GetParent(pChildWnd
->hTreeWnd
, TreeView_GetParent(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
)))
527 case TVN_ENDLABELEDIT
:
532 LPNMTVDISPINFO ptvdi
;
534 TCHAR szBuffer
[MAX_PATH
];
536 ptvdi
= (LPNMTVDISPINFO
) lParam
;
537 if (ptvdi
->item
.pszText
)
539 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, TreeView_GetParent(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
), &hRootKey
);
540 _sntprintf(szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0]), _T("%s\\%s"), keyPath
, ptvdi
->item
.pszText
);
541 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
, &hRootKey
);
542 if (RegOpenKeyEx(hRootKey
, szBuffer
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
546 (void)TreeView_EditLabel(pChildWnd
->hTreeWnd
, ptvdi
->item
.hItem
);
550 if (RegRenameKey(hRootKey
, keyPath
, ptvdi
->item
.pszText
) != ERROR_SUCCESS
)
561 if ((int)wParam
== LIST_WINDOW
)
563 switch (((LPNMHDR
)lParam
)->code
) {
565 pChildWnd
->nFocusPanel
= 1;
568 if(!ListWndNotifyProc(pChildWnd
->hListWnd
, wParam
, lParam
, &Result
))
582 if((HWND
)wParam
== pChildWnd
->hListWnd
)
586 pt
.x
= LOWORD(lParam
);
587 pt
.y
= HIWORD(lParam
);
588 cnt
= ListView_GetSelectedCount(pChildWnd
->hListWnd
);
589 i
= ListView_GetNextItem(pChildWnd
->hListWnd
, -1, LVNI_FOCUSED
| LVNI_SELECTED
);
590 FixPointIfContext(&pt
, pChildWnd
->hListWnd
);
593 TrackPopupMenu(GetSubMenu(hPopupMenus
, PM_NEW
), TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
597 HMENU mnu
= GetSubMenu(hPopupMenus
, PM_MODIFYVALUE
);
598 SetMenuDefaultItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
599 IsDefault
= IsDefaultValue(pChildWnd
->hListWnd
, i
);
601 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| (IsDefault
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
603 EnableMenuItem(mnu
, ID_EDIT_RENAME
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
604 EnableMenuItem(mnu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
605 EnableMenuItem(mnu
, ID_EDIT_MODIFY_BIN
, MF_BYCOMMAND
| (cnt
== 1 ? MF_ENABLED
: MF_DISABLED
| MF_GRAYED
));
607 TrackPopupMenu(mnu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, hFrameWnd
, NULL
);
610 else if ((HWND
)wParam
== pChildWnd
->hTreeWnd
)
624 pt
.x
= LOWORD(lParam
);
625 pt
.y
= HIWORD(lParam
);
628 ScreenToClient(pChildWnd
->hTreeWnd
, &hti
.pt
);
629 (void)TreeView_HitTest(pChildWnd
->hTreeWnd
, &hti
);
631 if ((hti
.flags
& TVHT_ONITEM
) != 0 || (pt
.x
== -1 && pt
.y
== -1))
633 hContextMenu
= GetSubMenu(hPopupMenus
, PM_TREECONTEXT
);
634 (void)TreeView_SelectItem(pChildWnd
->hTreeWnd
, hti
.hItem
);
636 memset(&item
, 0, sizeof(item
));
637 item
.mask
= TVIF_STATE
| TVIF_CHILDREN
;
638 item
.hItem
= hti
.hItem
;
639 (void)TreeView_GetItem(pChildWnd
->hTreeWnd
, &item
);
641 /* Set the Expand/Collapse menu item appropriately */
642 LoadString(hInst
, (item
.state
& TVIS_EXPANDED
) ? IDS_COLLAPSE
: IDS_EXPAND
, buffer
, sizeof(buffer
) / sizeof(buffer
[0]));
643 memset(&mii
, 0, sizeof(mii
));
644 mii
.cbSize
= sizeof(mii
);
645 mii
.fMask
= MIIM_STRING
| MIIM_STATE
| MIIM_ID
;
646 mii
.fState
= (item
.cChildren
> 0) ? MFS_DEFAULT
: MFS_GRAYED
;
647 mii
.wID
= (item
.state
& TVIS_EXPANDED
) ? ID_TREE_COLLAPSEBRANCH
: ID_TREE_EXPANDBRANCH
;
648 mii
.dwTypeData
= (LPTSTR
) buffer
;
649 SetMenuItemInfo(hContextMenu
, 0, TRUE
, &mii
);
651 /* Remove any existing suggestions */
652 memset(&mii
, 0, sizeof(mii
));
653 mii
.cbSize
= sizeof(mii
);
655 GetMenuItemInfo(hContextMenu
, GetMenuItemCount(hContextMenu
) - 1, TRUE
, &mii
);
656 if ((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
))
660 iLastPos
= GetMenuItemCount(hContextMenu
) - 1;
661 GetMenuItemInfo(hContextMenu
, iLastPos
, TRUE
, &mii
);
662 RemoveMenu(hContextMenu
, iLastPos
, MF_BYPOSITION
);
664 while((mii
.wID
>= ID_TREE_SUGGESTION_MIN
) && (mii
.wID
<= ID_TREE_SUGGESTION_MAX
));
667 /* Come up with suggestions */
668 keyPath
= GetItemPath(pChildWnd
->hTreeWnd
, NULL
, &hRootKey
);
669 SuggestKeys(hRootKey
, keyPath
, Suggestions
, sizeof(Suggestions
) / sizeof(Suggestions
[0]));
672 AppendMenu(hContextMenu
, MF_SEPARATOR
, 0, NULL
);
674 LoadString(hInst
, IDS_GOTO_SUGGESTED_KEY
, resource
, sizeof(resource
) / sizeof(resource
[0]));
677 wID
= ID_TREE_SUGGESTION_MIN
;
678 while(*s
&& (wID
<= ID_TREE_SUGGESTION_MAX
))
680 _sntprintf(buffer
, sizeof(buffer
) / sizeof(buffer
[0]), resource
, s
);
682 memset(&mii
, 0, sizeof(mii
));
683 mii
.cbSize
= sizeof(mii
);
684 mii
.fMask
= MIIM_STRING
| MIIM_ID
;
686 mii
.dwTypeData
= buffer
;
687 InsertMenuItem(hContextMenu
, GetMenuItemCount(hContextMenu
), TRUE
, &mii
);
692 FixPointIfContext(&pt
, pChildWnd
->hTreeWnd
);
693 TrackPopupMenu(hContextMenu
, TPM_RIGHTBUTTON
, pt
.x
, pt
.y
, 0, pChildWnd
->hWnd
, NULL
);
700 if (wParam
!= SIZE_MINIMIZED
&& pChildWnd
!= NULL
) {
701 ResizeWnd(pChildWnd
, LOWORD(lParam
), HIWORD(lParam
));
705 return DefWindowProc(hWnd
, message
, wParam
, lParam
);