ReactOS  0.4.15-dev-1203-g0e5a4d5
treeview.c File Reference
#include "regedit.h"
Include dependency graph for treeview.c:

Go to the source code of this file.

Macros

#define NUM_ICONS   3
 

Functions

static BOOL get_item_path (HWND hwndTV, HTREEITEM hItem, HKEY *phKey, LPWSTR *pKeyPath, int *pPathLen, int *pMaxLen)
 
LPCWSTR GetItemPath (HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
 
BOOL DeleteNode (HWND hwndTV, HTREEITEM hItem)
 
static HTREEITEM AddEntryToTree (HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
 
BOOL RefreshTreeItem (HWND hwndTV, HTREEITEM hItem)
 
BOOL RefreshTreeView (HWND hwndTV)
 
HTREEITEM InsertNode (HWND hwndTV, HTREEITEM hItem, LPWSTR name)
 
HWND StartKeyRename (HWND hwndTV)
 
static BOOL InitTreeViewItems (HWND hwndTV, LPWSTR pHostName)
 
static BOOL InitTreeViewImageLists (HWND hwndTV)
 
BOOL OnTreeExpanding (HWND hwndTV, NMTREEVIEW *pnmtv)
 
BOOL CreateNewKey (HWND hwndTV, HTREEITEM hItem)
 
BOOL TreeWndNotifyProc (HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
 
HWND CreateTreeView (HWND hwndParent, LPWSTR pHostName, HMENU id)
 
void DestroyTreeView (HWND hwndTV)
 
BOOL SelectNode (HWND hwndTV, LPCWSTR keyPath)
 

Variables

static int Image_Open = 0
 
static int Image_Closed = 0
 
static int Image_Root = 0
 
static LPWSTR pathBuffer
 

Macro Definition Documentation

◆ NUM_ICONS

#define NUM_ICONS   3

Definition at line 33 of file treeview.c.

Function Documentation

◆ AddEntryToTree()

static HTREEITEM AddEntryToTree ( HWND  hwndTV,
HTREEITEM  hParent,
LPWSTR  label,
HKEY  hKey,
DWORD  dwChildren 
)
static

Definition at line 110 of file treeview.c.

111 {
112  TVITEMW tvi;
113  TVINSERTSTRUCTW tvins;
114 
115  if (hKey)
116  {
117  if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwChildren, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS)
118  {
119  dwChildren = 0;
120  }
121  }
122 
124  tvi.pszText = label;
125  tvi.cchTextMax = wcslen(tvi.pszText);
126  tvi.iImage = Image_Closed;
128  tvi.cChildren = dwChildren;
129  tvi.lParam = (LPARAM)hKey;
130  tvins.item = tvi;
131  tvins.hInsertAfter = (HTREEITEM)(hKey ? TVI_LAST : TVI_FIRST);
132  tvins.hParent = hParent;
133  return TreeView_InsertItem(hwndTV, &tvins);
134 }
int cchTextMax
Definition: commctrl.h:3317
HTREEITEM hParent
Definition: commctrl.h:3389
#define ERROR_SUCCESS
Definition: deptool.c:10
int iImage
Definition: commctrl.h:3318
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3260
LPARAM lParam
Definition: commctrl.h:3321
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3267
UINT mask
Definition: commctrl.h:3312
LPWSTR pszText
Definition: commctrl.h:3316
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3408
#define TVIF_CHILDREN
Definition: commctrl.h:3268
HTREEITEM hInsertAfter
Definition: commctrl.h:3390
static int Image_Closed
Definition: treeview.c:28
#define TVI_FIRST
Definition: commctrl.h:3365
LONG_PTR LPARAM
Definition: windef.h:208
static int Image_Open
Definition: treeview.c:27
#define TVI_LAST
Definition: commctrl.h:3366
int cChildren
Definition: commctrl.h:3320
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
uint8_t label[11]
Definition: fsck.fat.h:65
#define TVIF_TEXT
Definition: commctrl.h:3262
int iSelectedImage
Definition: commctrl.h:3319
#define TVIF_IMAGE
Definition: commctrl.h:3263
#define TVIF_PARAM
Definition: commctrl.h:3264
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by InitTreeViewItems(), InsertNode(), OnTreeExpanding(), and RefreshTreeItem().

◆ CreateNewKey()

BOOL CreateNewKey ( HWND  hwndTV,
HTREEITEM  hItem 
)

Definition at line 571 of file treeview.c.

572 {
573  WCHAR szNewKeyFormat[128];
574  WCHAR szNewKey[128];
575  LPCWSTR pszKeyPath;
576  int iIndex = 1;
577  LONG nResult;
578  HKEY hRootKey = NULL, hKey = NULL, hNewKey = NULL;
579  BOOL bSuccess = FALSE;
580  DWORD dwDisposition;
581  HTREEITEM hNewItem;
582 
583  pszKeyPath = GetItemPath(hwndTV, hItem, &hRootKey);
584  if (pszKeyPath[0] == L'\0')
585  hKey = hRootKey;
586  else if (RegOpenKeyW(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
587  goto done;
588 
589  if (LoadStringW(hInst, IDS_NEW_KEY, szNewKeyFormat, COUNT_OF(szNewKeyFormat)) <= 0)
590  goto done;
591 
592  /* Need to create a new key with a unique name */
593  do
594  {
595  wsprintf(szNewKey, szNewKeyFormat, iIndex++);
596  nResult = RegCreateKeyExW(hKey, szNewKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hNewKey, &dwDisposition);
597  if (hNewKey && dwDisposition == REG_OPENED_EXISTING_KEY)
598  {
599  RegCloseKey(hNewKey);
600  hNewKey = NULL;
601  }
602  else if (!hNewKey)
603  {
604  InfoMessageBox(hFrameWnd, MB_OK | MB_ICONERROR, NULL, L"Cannot create new key!\n\nError Code: %d", nResult);
605  goto done;
606  }
607  }
608  while(!hNewKey);
609 
610  /* Insert the new key */
611  hNewItem = InsertNode(hwndTV, hItem, szNewKey);
612  if (!hNewItem)
613  goto done;
614 
615  /* The new key's name is probably not appropriate yet */
616  (void)TreeView_EditLabel(hwndTV, hNewItem);
617 
618  bSuccess = TRUE;
619 
620 done:
621  if (hKey != hRootKey && hKey)
622  RegCloseKey(hKey);
623  if (hNewKey)
624  RegCloseKey(hNewKey);
625  return bSuccess;
626 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define TreeView_EditLabel(hwnd, hitem)
Definition: commctrl.h:3500
int InfoMessageBox(HWND hWnd, UINT uType, LPCWSTR lpTitle, LPCWSTR lpMessage,...)
Definition: error.c:51
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
static BOOLEAN bSuccess
Definition: drive.cpp:419
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
#define IDS_NEW_KEY
Definition: resource.h:192
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name)
Definition: treeview.c:331
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3296
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define COUNT_OF(a)
Definition: main.h:33
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define MB_ICONERROR
Definition: winuser.h:781
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:83
HWND hFrameWnd
Definition: main.c:30
HINSTANCE hInst
Definition: dxdiag.c:13
#define MB_OK
Definition: winuser.h:784
#define wsprintf
Definition: winuser.h:5840

Referenced by _CmdWndProc().

◆ CreateTreeView()

HWND CreateTreeView ( HWND  hwndParent,
LPWSTR  pHostName,
HMENU  id 
)

Definition at line 738 of file treeview.c.

739 {
740  RECT rcClient;
741  HWND hwndTV;
742 
743  /* Get the dimensions of the parent window's client area, and create the tree view control. */
744  GetClientRect(hwndParent, &rcClient);
747  0, 0, rcClient.right, rcClient.bottom,
748  hwndParent, id, hInst, NULL);
749  if (!hwndTV) return NULL;
750 
751  /* Initialize the image list, and add items to the control. */
752  if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName))
753  {
754  DestroyWindow(hwndTV);
755  return NULL;
756  }
757  return hwndTV;
758 }
static BOOL InitTreeViewItems(HWND hwndTV, LPWSTR pHostName)
Definition: treeview.c:391
#define TVS_LINESATROOT
Definition: commctrl.h:3245
#define WS_CHILD
Definition: pedump.c:617
LONG right
Definition: windef.h:308
BOOL WINAPI DestroyWindow(_In_ HWND)
#define TVS_HASBUTTONS
Definition: commctrl.h:3243
smooth NULL
Definition: ftsmooth.c:416
static HWND hwndParent
Definition: cryptui.c:300
#define WC_TREEVIEW
Definition: commctrl.h:3241
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define WS_TABSTOP
Definition: pedump.c:634
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
static BOOL InitTreeViewImageLists(HWND hwndTV)
Definition: treeview.c:438
HINSTANCE hInst
Definition: dxdiag.c:13
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define TVS_SHOWSELALWAYS
Definition: commctrl.h:3248
#define TVS_HASLINES
Definition: commctrl.h:3244
LONG bottom
Definition: windef.h:309
#define WS_VISIBLE
Definition: pedump.c:620
#define TVS_EDITLABELS
Definition: commctrl.h:3246

Referenced by ChildWndProc().

◆ DeleteNode()

BOOL DeleteNode ( HWND  hwndTV,
HTREEITEM  hItem 
)

Definition at line 102 of file treeview.c.

103 {
104  if (!hItem) hItem = TreeView_GetSelection(hwndTV);
105  if (!hItem) return FALSE;
106  return TreeView_DeleteItem(hwndTV, hItem);
107 }
#define FALSE
Definition: types.h:117
#define TreeView_DeleteItem(hwnd, hitem)
Definition: commctrl.h:3411
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3469

Referenced by _CmdWndProc(), and RtlpDeleteAvlTreeNode().

◆ DestroyTreeView()

void DestroyTreeView ( HWND  hwndTV)

Definition at line 760 of file treeview.c.

761 {
763 
765 
766  /* Destroy the image list associated with the tree view control */
769 }
static LPWSTR pathBuffer
Definition: treeview.c:31
HIMAGELIST himl
#define TreeView_GetImageList(hwnd, iImage)
Definition: commctrl.h:3437
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
#define GetProcessHeap()
Definition: compat.h:595
#define TVSIL_NORMAL
Definition: commctrl.h:3439
#define HeapFree(x, y, z)
Definition: compat.h:594

◆ get_item_path()

static BOOL get_item_path ( HWND  hwndTV,
HTREEITEM  hItem,
HKEY phKey,
LPWSTR pKeyPath,
int pPathLen,
int pMaxLen 
)
static

Definition at line 35 of file treeview.c.

36 {
37  TVITEMW item;
38  size_t maxLen, len;
39  LPWSTR newStr;
40 
41  item.mask = TVIF_PARAM;
42  item.hItem = hItem;
43  if (!TreeView_GetItem(hwndTV, &item)) return FALSE;
44 
45  if (item.lParam)
46  {
47  /* found root key with valid key value */
48  *phKey = (HKEY)item.lParam;
49  return TRUE;
50  }
51 
52  if(!get_item_path(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxLen)) return FALSE;
53  if (*pPathLen)
54  {
55  (*pKeyPath)[*pPathLen] = L'\\';
56  ++(*pPathLen);
57  }
58 
59  do
60  {
61  item.mask = TVIF_TEXT;
62  item.hItem = hItem;
63  item.pszText = *pKeyPath + *pPathLen;
64  maxLen = *pMaxLen - *pPathLen;
65  item.cchTextMax = (int) maxLen;
66  if (!TreeView_GetItem(hwndTV, &item)) return FALSE;
67  len = wcslen(item.pszText);
68  if (len < maxLen - 1)
69  {
70  *pPathLen += (int) len;
71  break;
72  }
73  newStr = HeapReAlloc(GetProcessHeap(), 0, *pKeyPath, *pMaxLen * 2);
74  if (!newStr) return FALSE;
75  *pKeyPath = newStr;
76  *pMaxLen *= 2;
77  }
78  while(TRUE);
79 
80  return TRUE;
81 }
#define TRUE
Definition: types.h:120
static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY *phKey, LPWSTR *pKeyPath, int *pPathLen, int *pMaxLen)
Definition: treeview.c:35
#define FALSE
Definition: types.h:117
HTREEITEM hItem
Definition: treelist.h:37
#define GetProcessHeap()
Definition: compat.h:595
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
#define TreeView_GetParent(hwnd, hitem)
Definition: commctrl.h:3465
static ATOM item
Definition: dde.c:856
#define TVIF_TEXT
Definition: commctrl.h:3262
#define HeapReAlloc
Definition: compat.h:593
HANDLE HKEY
Definition: registry.h:24
#define TVIF_PARAM
Definition: commctrl.h:3264
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3486
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by GetItemPath().

◆ GetItemPath()

LPCWSTR GetItemPath ( HWND  hwndTV,
HTREEITEM  hItem,
HKEY phRootKey 
)

Definition at line 83 of file treeview.c.

84 {
85  int pathLen = 0, maxLen;
86 
87  *phRootKey = NULL;
88  if (!pathBuffer) pathBuffer = HeapAlloc(GetProcessHeap(), 0, 1024);
89  if (!pathBuffer) return NULL;
90  *pathBuffer = 0;
91  maxLen = (int) HeapSize(GetProcessHeap(), 0, pathBuffer);
92  if (maxLen == -1) return NULL;
93  if (!hItem) hItem = TreeView_GetSelection(hwndTV);
94  if (!hItem) return NULL;
95  if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen))
96  {
97  return NULL;
98  }
99  return pathBuffer;
100 }
static LPWSTR pathBuffer
Definition: treeview.c:31
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)
static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY *phKey, LPWSTR *pKeyPath, int *pPathLen, int *pMaxLen)
Definition: treeview.c:35
smooth NULL
Definition: ftsmooth.c:416
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3469
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by _CmdWndProc(), ChildWndProc(), CreateNewKey(), ExportRegistryFile(), FindNext(), ImportRegistryFile(), ListWndNotifyProc(), LoadHive(), OnTreeExpanding(), RefreshTreeItem(), SaveSettings(), TreeWndNotifyProc(), UnloadHive(), UpdateAddress(), and UpdateStatusBar().

◆ InitTreeViewImageLists()

static BOOL InitTreeViewImageLists ( HWND  hwndTV)
static

Definition at line 438 of file treeview.c.

439 {
440  HIMAGELIST himl; /* handle to image list */
441  HICON hico; /* handle to icon */
442 
443  /* Create the image list. */
447  0,
448  NUM_ICONS)) == NULL)
449  {
450  return FALSE;
451  }
452 
453  /* Add the open file, closed file, and document bitmaps. */
456  IMAGE_ICON,
459  0);
460  if (hico)
461  {
463  DestroyIcon(hico);
464  }
465 
468  IMAGE_ICON,
471  0);
472  if (hico)
473  {
475  DestroyIcon(hico);
476  }
477 
480  IMAGE_ICON,
483  0);
484  if (hico)
485  {
487  DestroyIcon(hico);
488  }
489 
490  /* Fail if not all of the images were added. */
492  {
494  return FALSE;
495  }
496 
497  /* Associate the image list with the tree view control. */
499 
500  return TRUE;
501 }
INT WINAPI ImageList_GetImageCount(HIMAGELIST himl)
Definition: imagelist.c:2063
static HICON
Definition: imagelist.c:84
#define IMAGE_ICON
Definition: winuser.h:212
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define TRUE
Definition: types.h:120
#define SM_CYSMICON
Definition: winuser.h:1003
HIMAGELIST himl
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
#define ILC_COLOR32
Definition: commctrl.h:354
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:804
#define FALSE
Definition: types.h:117
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
static int Image_Closed
Definition: treeview.c:28
smooth NULL
Definition: ftsmooth.c:416
static int Image_Open
Definition: treeview.c:27
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3443
static int Image_Root
Definition: treeview.c:29
#define IDI_CLOSED_FILE
Definition: resource.h:44
int WINAPI GetSystemMetrics(_In_ int)
INT WINAPI ImageList_AddIcon(HIMAGELIST himl, HICON hIcon)
Definition: imagelist.c:540
HICON hico
#define SM_CXSMICON
Definition: winuser.h:1002
#define ILC_MASK
Definition: commctrl.h:347
HINSTANCE hInst
Definition: dxdiag.c:13
#define IDI_OPEN_FILE
Definition: resource.h:43
#define IDI_ROOT
Definition: resource.h:45
#define TVSIL_NORMAL
Definition: commctrl.h:3439
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define NUM_ICONS
Definition: treeview.c:33

Referenced by CreateTreeView().

◆ InitTreeViewItems()

static BOOL InitTreeViewItems ( HWND  hwndTV,
LPWSTR  pHostName 
)
static

Definition at line 391 of file treeview.c.

392 {
393  TVITEMW tvi;
394  TVINSERTSTRUCTW tvins;
396 
398  /* Set the text of the item. */
399  tvi.pszText = pHostName;
400  tvi.cchTextMax = wcslen(tvi.pszText);
401  /* Assume the item is not a parent item, so give it an image. */
402  tvi.iImage = Image_Root;
404  tvi.cChildren = 5;
405  /* Save the heading level in the item's application-defined data area. */
406  tvi.lParam = (LPARAM)NULL;
407  tvins.item = tvi;
409  tvins.hParent = TVI_ROOT;
410  /* Add the item to the tree view control. */
411  if (!(hRoot = TreeView_InsertItem(hwndTV, &tvins))) return FALSE;
412 
413  if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_CLASSES_ROOT", HKEY_CLASSES_ROOT, 1)) return FALSE;
414  if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_CURRENT_USER", HKEY_CURRENT_USER, 1)) return FALSE;
415  if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_LOCAL_MACHINE", HKEY_LOCAL_MACHINE, 1)) return FALSE;
416  if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_USERS", HKEY_USERS, 1)) return FALSE;
417  if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_CURRENT_CONFIG", HKEY_CURRENT_CONFIG, 1)) return FALSE;
418 
419  if (GetVersion() & 0x80000000)
420  {
421  /* Win9x specific key */
422  if (!AddEntryToTree(hwndTV, hRoot, L"HKEY_DYN_DATA", HKEY_DYN_DATA, 1)) return FALSE;
423  }
424 
425  /* expand and select host name */
428  return TRUE;
429 }
#define HKEY_USERS
Definition: winreg.h:13
int cchTextMax
Definition: commctrl.h:3317
HTREEITEM hParent
Definition: commctrl.h:3389
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TVGN_CARET
Definition: commctrl.h:3457
#define TRUE
Definition: types.h:120
int iImage
Definition: commctrl.h:3318
#define HKEY_CURRENT_USER
Definition: winreg.h:11
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3260
LPARAM lParam
Definition: commctrl.h:3321
#define HKEY_DYN_DATA
Definition: winreg.h:16
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3267
UINT mask
Definition: commctrl.h:3312
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
LPWSTR pszText
Definition: commctrl.h:3316
DWORD WINAPI GetVersion(VOID)
Definition: version.c:22
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
Definition: treeview.c:110
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3408
#define TVIF_CHILDREN
Definition: commctrl.h:3268
#define FALSE
Definition: types.h:117
HTREEITEM hInsertAfter
Definition: commctrl.h:3390
static HTREEITEM hRoot
Definition: treeview.c:381
#define TVI_FIRST
Definition: commctrl.h:3365
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
int cChildren
Definition: commctrl.h:3320
static int Image_Root
Definition: treeview.c:29
#define TVE_EXPAND
Definition: commctrl.h:3419
#define TVI_ROOT
Definition: commctrl.h:3364
static const WCHAR L[]
Definition: oid.c:1250
#define TVIF_TEXT
Definition: commctrl.h:3262
int iSelectedImage
Definition: commctrl.h:3319
#define TreeView_Select(hwnd, hitem, code)
Definition: commctrl.h:3475
#define TVIF_IMAGE
Definition: commctrl.h:3263
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define TVIF_PARAM
Definition: commctrl.h:3264
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3416
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by CreateTreeView().

◆ InsertNode()

HTREEITEM InsertNode ( HWND  hwndTV,
HTREEITEM  hItem,
LPWSTR  name 
)

Definition at line 331 of file treeview.c.

332 {
334  HTREEITEM hNewItem = 0;
335  TVITEMEXW item;
336 
337  /* Default to the current selection */
338  if (!hItem)
339  {
340  hItem = TreeView_GetSelection(hwndTV);
341  if (!hItem)
342  return FALSE;
343  }
344 
345  memset(&item, 0, sizeof(item));
346  item.hItem = hItem;
348  if (!TreeView_GetItem(hwndTV, &item))
349  return FALSE;
350 
351  if ((item.state & TVIS_EXPANDEDONCE) && (item.cChildren > 0))
352  {
353  hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0);
354  SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM) hItem);
355  }
356  else
357  {
358  item.mask = TVIF_CHILDREN | TVIF_HANDLE;
359  item.hItem = hItem;
360  item.cChildren = 1;
361  if (!TreeView_SetItem(hwndTV, &item))
362  return FALSE;
363  }
364 
366  if (!hNewItem)
367  {
368  for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem))
369  {
370  item.mask = TVIF_HANDLE | TVIF_TEXT;
371  item.hItem = hNewItem;
372  item.pszText = buf;
373  item.cchTextMax = COUNT_OF(buf);
374  if (!TreeView_GetItem(hwndTV, &item)) continue;
375  if (wcscmp(name, item.pszText) == 0) break;
376  }
377  }
378  if (hNewItem) (void)TreeView_SelectItem(hwndTV, hNewItem);
379 
380  return hNewItem;
381 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TVM_SORTCHILDREN
Definition: commctrl.h:3537
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3462
#define TVIS_EXPANDEDONCE
Definition: commctrl.h:3281
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3463
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
Definition: treeview.c:110
#define TVIF_CHILDREN
Definition: commctrl.h:3268
#define FALSE
Definition: types.h:117
HTREEITEM hItem
Definition: treelist.h:37
LONG_PTR LPARAM
Definition: windef.h:208
#define COUNT_OF(a)
Definition: main.h:33
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3469
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define TVE_EXPAND
Definition: commctrl.h:3419
#define TVIF_HANDLE
Definition: commctrl.h:3266
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static ATOM item
Definition: dde.c:856
#define TVIF_TEXT
Definition: commctrl.h:3262
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3477
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define TreeView_SetItem(hwnd, pitem)
Definition: commctrl.h:3493
Definition: name.c:38
#define TVIF_STATE
Definition: commctrl.h:3265
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3416
#define memset(x, y, z)
Definition: compat.h:39
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3486
#define MAX_NEW_KEY_LEN
Definition: main.h:41

Referenced by CreateNewKey().

◆ OnTreeExpanding()

BOOL OnTreeExpanding ( HWND  hwndTV,
NMTREEVIEW pnmtv 
)

Definition at line 503 of file treeview.c.

504 {
505  DWORD dwCount, dwIndex, dwMaxSubKeyLen;
506  HKEY hRoot, hNewKey, hKey;
507  LPCWSTR keyPath;
508  LPWSTR Name;
509  LONG errCode;
510  HCURSOR hcursorOld;
511 
512  static int expanding;
513  if (expanding) return FALSE;
514  if (pnmtv->itemNew.state & TVIS_EXPANDEDONCE )
515  {
516  return TRUE;
517  }
518  expanding = TRUE;
519  hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
520  SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
521 
522  keyPath = GetItemPath(hwndTV, pnmtv->itemNew.hItem, &hRoot);
523  if (!keyPath) goto done;
524 
525  if (*keyPath)
526  {
527  errCode = RegOpenKeyExW(hRoot, keyPath, 0, KEY_READ, &hNewKey);
528  if (errCode != ERROR_SUCCESS) goto done;
529  }
530  else
531  {
532  hNewKey = hRoot;
533  }
534 
535  errCode = RegQueryInfoKeyW(hNewKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0);
536  if (errCode != ERROR_SUCCESS) goto done;
537  dwMaxSubKeyLen++; /* account for the \0 terminator */
538  Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR));
539  if (!Name) goto done;
540 
541  for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
542  {
543  DWORD cName = dwMaxSubKeyLen, dwSubCount;
544 
545  errCode = RegEnumKeyExW(hNewKey, dwIndex, Name, &cName, 0, 0, 0, 0);
546  if (errCode != ERROR_SUCCESS) continue;
547  errCode = RegOpenKeyExW(hNewKey, Name, 0, KEY_QUERY_VALUE, &hKey);
548  if (errCode == ERROR_SUCCESS)
549  {
550  errCode = RegQueryInfoKeyW(hKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0);
551  RegCloseKey(hKey);
552  }
553  if (errCode != ERROR_SUCCESS) dwSubCount = 0;
554  AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount);
555  }
556 
557  SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM)pnmtv->itemNew.hItem);
558 
559  RegCloseKey(hNewKey);
561 
562 done:
563  SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0);
564  SetCursor(hcursorOld);
565  expanding = FALSE;
566 
567  return TRUE;
568 }
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TVM_SORTCHILDREN
Definition: commctrl.h:3537
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define WM_SETREDRAW
Definition: winuser.h:1598
#define TVIS_EXPANDEDONCE
Definition: commctrl.h:3281
HICON HCURSOR
Definition: windef.h:299
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
Definition: treeview.c:110
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
static HTREEITEM hRoot
Definition: treeview.c:381
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
#define IDC_WAIT
Definition: winuser.h:684
LONG_PTR LPARAM
Definition: windef.h:208
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
#define LoadCursor
Definition: winuser.h:5787
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:83
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:594

Referenced by TreeWndNotifyProc().

◆ RefreshTreeItem()

BOOL RefreshTreeItem ( HWND  hwndTV,
HTREEITEM  hItem 
)

Definition at line 136 of file treeview.c.

137 {
138  HKEY hRoot, hKey, hSubKey;
139  HTREEITEM childItem;
140  LPCWSTR KeyPath;
141  DWORD dwCount, dwIndex, dwMaxSubKeyLen;
142  LPWSTR Name = NULL;
143  TVITEMW tvItem;
144  LPWSTR pszNodes = NULL;
145  BOOL bSuccess = FALSE;
146  LPWSTR s;
147  BOOL bAddedAny;
148 
149  KeyPath = GetItemPath(hwndTV, hItem, &hRoot);
150 
151  if (*KeyPath)
152  {
153  if (RegOpenKeyExW(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
154  {
155  goto done;
156  }
157  }
158  else
159  {
160  hKey = hRoot;
161  }
162 
163  if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS)
164  {
165  goto done;
166  }
167 
168  /* Set the number of children again */
169  tvItem.mask = TVIF_CHILDREN;
170  tvItem.hItem = hItem;
171  tvItem.cChildren = dwCount;
172  if (!TreeView_SetItem(hwndTV, &tvItem))
173  {
174  goto done;
175  }
176 
177  /* We don't have to bother with the rest if it's not expanded. */
178  if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDED) == 0)
179  {
180  RegCloseKey(hKey);
181  bSuccess = TRUE;
182  goto done;
183  }
184 
185  dwMaxSubKeyLen++; /* account for the \0 terminator */
186  if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR))))
187  {
188  goto done;
189  }
190  tvItem.cchTextMax = dwMaxSubKeyLen;
191  /*if (!(tvItem.pszText = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR)))) {
192  goto done;
193  }*/
194 
195  /* Get all of the tree node siblings in one contiguous block of memory */
196  {
197  DWORD dwPhysicalSize = 0;
198  DWORD dwActualSize = 0;
199  DWORD dwNewPhysicalSize;
200  LPWSTR pszNewNodes;
201  DWORD dwStep = 10000;
202 
203  for (childItem = TreeView_GetChild(hwndTV, hItem); childItem;
204  childItem = TreeView_GetNextSibling(hwndTV, childItem))
205  {
206 
207  if (dwActualSize + dwMaxSubKeyLen + 1 > dwPhysicalSize)
208  {
209  dwNewPhysicalSize = dwActualSize + dwMaxSubKeyLen + 1 + dwStep;
210 
211  if (pszNodes)
212  pszNewNodes = (LPWSTR) HeapReAlloc(GetProcessHeap(), 0, pszNodes, dwNewPhysicalSize * sizeof(WCHAR));
213  else
214  pszNewNodes = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwNewPhysicalSize * sizeof(WCHAR));
215  if (!pszNewNodes)
216  goto done;
217 
218  dwPhysicalSize = dwNewPhysicalSize;
219  pszNodes = pszNewNodes;
220  }
221 
222  tvItem.mask = TVIF_TEXT;
223  tvItem.hItem = childItem;
224  tvItem.pszText = &pszNodes[dwActualSize];
225  tvItem.cchTextMax = dwPhysicalSize - dwActualSize;
226  if (!TreeView_GetItem(hwndTV, &tvItem))
227  goto done;
228 
229  dwActualSize += (DWORD) wcslen(&pszNodes[dwActualSize]) + 1;
230  }
231 
232  if (pszNodes)
233  pszNodes[dwActualSize] = L'\0';
234  }
235 
236  /* Now go through all the children in the tree, and check if any have to be removed. */
237  childItem = TreeView_GetChild(hwndTV, hItem);
238  while (childItem)
239  {
240  HTREEITEM nextItem = TreeView_GetNextSibling(hwndTV, childItem);
241  if (RefreshTreeItem(hwndTV, childItem) == FALSE)
242  {
243  (void)TreeView_DeleteItem(hwndTV, childItem);
244  }
245  childItem = nextItem;
246  }
247 
248  /* Now go through all the children in the registry, and check if any have to be added. */
249  bAddedAny = FALSE;
250  for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
251  {
252  DWORD cName = dwMaxSubKeyLen, dwSubCount;
253  BOOL found;
254 
255  found = FALSE;
256  if (RegEnumKeyExW(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS)
257  {
258  continue;
259  }
260 
261  /* Check if the node is already in there. */
262  if (pszNodes)
263  {
264  for (s = pszNodes; *s; s += wcslen(s) + 1)
265  {
266  if (!wcscmp(s, Name))
267  {
268  found = TRUE;
269  break;
270  }
271  }
272  }
273 
274  if (found == FALSE)
275  {
276  /* Find the number of children of the node. */
277  dwSubCount = 0;
278  if (RegOpenKeyExW(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
279  {
280  if (RegQueryInfoKeyW(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS)
281  {
282  dwSubCount = 0;
283  }
284  RegCloseKey(hSubKey);
285  }
286 
287  AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount);
288  bAddedAny = TRUE;
289  }
290  }
291  RegCloseKey(hKey);
292 
293  if (bAddedAny)
294  SendMessageW(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM) hItem);
295 
296  bSuccess = TRUE;
297 
298 done:
299  if (pszNodes)
300  HeapFree(GetProcessHeap(), 0, pszNodes);
301  if (Name)
303  return bSuccess;
304 }
int cchTextMax
Definition: commctrl.h:3317
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TVM_SORTCHILDREN
Definition: commctrl.h:3537
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3462
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3463
UINT mask
Definition: commctrl.h:3312
LPWSTR pszText
Definition: commctrl.h:3316
#define DWORD
Definition: nt_native.h:44
static BOOLEAN bSuccess
Definition: drive.cpp:419
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
Definition: treeview.c:110
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define TVIF_CHILDREN
Definition: commctrl.h:3268
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static HTREEITEM hRoot
Definition: treeview.c:381
HTREEITEM hItem
Definition: treelist.h:37
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
int cChildren
Definition: commctrl.h:3320
#define TreeView_DeleteItem(hwnd, hitem)
Definition: commctrl.h:3411
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define TreeView_GetItemState(hwndTV, hti, mask)
Definition: commctrl.h:3591
BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
Definition: treeview.c:136
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
static const WCHAR L[]
Definition: oid.c:1250
GLdouble s
Definition: gl.h:2039
#define TVIS_EXPANDED
Definition: commctrl.h:3280
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:83
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define TVIF_TEXT
Definition: commctrl.h:3262
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define HeapReAlloc
Definition: compat.h:593
HTREEITEM hItem
Definition: commctrl.h:3313
#define TreeView_SetItem(hwnd, pitem)
Definition: commctrl.h:3493
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:594
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3486

Referenced by RefreshTreeView().

◆ RefreshTreeView()

BOOL RefreshTreeView ( HWND  hwndTV)

Definition at line 306 of file treeview.c.

307 {
309  HTREEITEM hSelectedItem;
310  HCURSOR hcursorOld;
311 
312  hSelectedItem = TreeView_GetSelection(hwndTV);
313  hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
314  SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
315 
316  hItem = TreeView_GetChild(hwndTV, TreeView_GetRoot(hwndTV));
317  while (hItem)
318  {
319  RefreshTreeItem(hwndTV, hItem);
321  }
322 
323  SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0);
324  SetCursor(hcursorOld);
325 
326  /* We reselect the currently selected node, this will prompt a refresh of the listview. */
327  (void)TreeView_SelectItem(hwndTV, hSelectedItem);
328  return TRUE;
329 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TRUE
Definition: types.h:120
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3462
#define WM_SETREDRAW
Definition: winuser.h:1598
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3463
HICON HCURSOR
Definition: windef.h:299
#define FALSE
Definition: types.h:117
HTREEITEM hItem
Definition: treelist.h:37
smooth NULL
Definition: ftsmooth.c:416
#define IDC_WAIT
Definition: winuser.h:684
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3469
BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
Definition: treeview.c:136
#define LoadCursor
Definition: winuser.h:5787
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3471
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3477
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by _CmdWndProc(), ImportRegistryFile(), LoadHive(), and UnloadHive().

◆ SelectNode()

BOOL SelectNode ( HWND  hwndTV,
LPCWSTR  keyPath 
)

Definition at line 771 of file treeview.c.

772 {
774  HTREEITEM hChildItem;
775  WCHAR szPathPart[128];
776  WCHAR szBuffer[128];
777  LPCWSTR s;
778  TVITEMW tvi;
779 
780  /* Load "My Computer" string... */
781  LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, COUNT_OF(szBuffer));
782  wcscat(szBuffer, L"\\");
783 
784  /* ... and remove it from the key path */
785  if (!_wcsnicmp(keyPath, szBuffer, wcslen(szBuffer)))
786  keyPath += wcslen(szBuffer);
787 
788  /* Reinitialize szBuffer */
789  szBuffer[0] = L'\0';
790 
791  hRoot = TreeView_GetRoot(hwndTV);
792  hItem = hRoot;
793 
794  while(keyPath[0])
795  {
796  s = wcschr(keyPath, L'\\');
797  lstrcpynW(szPathPart, keyPath, s ? s - keyPath + 1 : wcslen(keyPath) + 1);
798 
799  /* Special case for root to expand root key abbreviations */
800  if (hItem == hRoot)
801  {
802  if (!_wcsicmp(szPathPart, L"HKCR"))
803  wcscpy(szPathPart, L"HKEY_CLASSES_ROOT");
804  else if (!_wcsicmp(szPathPart, L"HKCU"))
805  wcscpy(szPathPart, L"HKEY_CURRENT_USER");
806  else if (!_wcsicmp(szPathPart, L"HKLM"))
807  wcscpy(szPathPart, L"HKEY_LOCAL_MACHINE");
808  else if (!_wcsicmp(szPathPart, L"HKU"))
809  wcscpy(szPathPart, L"HKEY_USERS");
810  else if (!_wcsicmp(szPathPart, L"HKCC"))
811  wcscpy(szPathPart, L"HKEY_CURRENT_CONFIG");
812  else if (!_wcsicmp(szPathPart, L"HKDD"))
813  wcscpy(szPathPart, L"HKEY_DYN_DATA");
814  }
815 
816  for (hChildItem = TreeView_GetChild(hwndTV, hItem); hChildItem;
817  hChildItem = TreeView_GetNextSibling(hwndTV, hChildItem))
818  {
819  memset(&tvi, 0, sizeof(tvi));
820  tvi.hItem = hChildItem;
821  tvi.mask = TVIF_TEXT | TVIF_CHILDREN;
822  tvi.pszText = szBuffer;
823  tvi.cchTextMax = COUNT_OF(szBuffer);
824 
825  (void)TreeView_GetItem(hwndTV, &tvi);
826 
827  if (!_wcsicmp(szBuffer, szPathPart))
828  break;
829  }
830 
831  if (!hChildItem)
832  return FALSE;
833 
834  if (tvi.cChildren > 0)
835  {
836  if (!TreeView_Expand(hwndTV, hChildItem, TVE_EXPAND))
837  return FALSE;
838  }
839 
840  keyPath = s ? s + 1 : L"";
841  hItem = hChildItem;
842  }
843 
844  (void)TreeView_SelectItem(hwndTV, hItem);
846 
847  return TRUE;
848 }
int cchTextMax
Definition: commctrl.h:3317
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3462
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3463
UINT mask
Definition: commctrl.h:3312
LPWSTR pszText
Definition: commctrl.h:3316
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define lstrcpynW
Definition: compat.h:597
#define TVIF_CHILDREN
Definition: commctrl.h:3268
#define FALSE
Definition: types.h:117
static HTREEITEM hRoot
Definition: treeview.c:381
HTREEITEM hItem
Definition: treelist.h:37
int cChildren
Definition: commctrl.h:3320
#define COUNT_OF(a)
Definition: main.h:33
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDS_MY_COMPUTER
Definition: resource.h:132
#define TVE_EXPAND
Definition: commctrl.h:3419
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
GLdouble s
Definition: gl.h:2039
#define TreeView_EnsureVisible(hwnd, hitem)
Definition: commctrl.h:3541
HINSTANCE hInst
Definition: dxdiag.c:13
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3471
#define TVIF_TEXT
Definition: commctrl.h:3262
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3477
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
HTREEITEM hItem
Definition: commctrl.h:3313
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3416
#define memset(x, y, z)
Definition: compat.h:39
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3486
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by _CmdWndProc(), AddressBarProc(), ChooseFavorite(), FindNext(), and LoadSettings().

◆ StartKeyRename()

HWND StartKeyRename ( HWND  hwndTV)

Definition at line 383 of file treeview.c.

384 {
386 
387  if(!(hItem = TreeView_GetSelection(hwndTV))) return 0;
388  return TreeView_EditLabel(hwndTV, hItem);
389 }
#define TreeView_EditLabel(hwnd, hitem)
Definition: commctrl.h:3500
HTREEITEM hItem
Definition: treelist.h:37
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3469

◆ TreeWndNotifyProc()

BOOL TreeWndNotifyProc ( HWND  hWnd,
WPARAM  wParam,
LPARAM  lParam,
BOOL Result 
)

Definition at line 628 of file treeview.c.

629 {
631  *Result = TRUE;
632 
633  switch (((LPNMHDR)lParam)->code)
634  {
635  case TVN_ITEMEXPANDING:
637  return TRUE;
638  case TVN_SELCHANGED:
639  {
640  NMTREEVIEW* pnmtv = (NMTREEVIEW*)lParam;
641  /* Get the parent of the current item */
642  HTREEITEM hParentItem = TreeView_GetParent(g_pChildWnd->hTreeWnd, pnmtv->itemNew.hItem);
643 
644  UpdateAddress(pnmtv->itemNew.hItem, NULL, NULL);
645 
646  /* Disable the Permissions menu item for 'My Computer' */
648 
649  /*
650  * Disable Delete/Rename menu options for 'My Computer' (first item so doesn't have any parent)
651  * and HKEY_* keys (their parent is 'My Computer' and the previous remark applies).
652  */
653  if (!hParentItem || !TreeView_GetParent(g_pChildWnd->hTreeWnd, hParentItem))
654  {
659  }
660  else
661  {
666  }
667 
668  return TRUE;
669  }
670  case NM_SETFOCUS:
672  break;
673  case TVN_BEGINLABELEDIT:
674  {
676  /* cancel label edit for rootkeys */
677  if (!TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem) ||
679  {
680  *Result = TRUE;
681  }
682  else
683  {
684  *Result = FALSE;
685  }
686  return TRUE;
687  }
688  case TVN_ENDLABELEDIT:
689  {
690  LPCWSTR keyPath;
691  HKEY hRootKey;
692  HKEY hKey = NULL;
694  LONG nRenResult;
695  LONG lResult = TRUE;
696  WCHAR szBuffer[MAX_PATH];
697  WCHAR Caption[128];
698 
699  if (ptvdi->item.pszText)
700  {
701  keyPath = GetItemPath(g_pChildWnd->hTreeWnd, TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem), &hRootKey);
702  if (wcslen(keyPath))
703  _snwprintf(szBuffer, COUNT_OF(szBuffer), L"%s\\%s", keyPath, ptvdi->item.pszText);
704  else
705  _snwprintf(szBuffer, COUNT_OF(szBuffer), L"%s", ptvdi->item.pszText);
706  keyPath = GetItemPath(g_pChildWnd->hTreeWnd, ptvdi->item.hItem, &hRootKey);
707  if (RegOpenKeyExW(hRootKey, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
708  {
709  lResult = FALSE;
710  RegCloseKey(hKey);
711  TreeView_EditLabel(g_pChildWnd->hTreeWnd, ptvdi->item.hItem);
712  }
713  else
714  {
715  nRenResult = RenameKey(hRootKey, keyPath, ptvdi->item.pszText);
716  if (nRenResult != ERROR_SUCCESS)
717  {
718  LoadStringW(hInst, IDS_ERROR, Caption, COUNT_OF(Caption));
719  ErrorMessageBox(hWnd, Caption, nRenResult);
720  lResult = FALSE;
721  }
722  else
723  UpdateAddress(ptvdi->item.hItem, hRootKey, szBuffer);
724  }
725  *Result = lResult;
726  }
727  return TRUE;
728  }
729  }
730  return FALSE;
731 }
#define ID_TREE_RENAME
Definition: resource.h:155
BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW *pnmtv)
Definition: treeview.c:503
int ErrorMessageBox(HWND hWnd, LPCWSTR lpTitle, DWORD dwErrorCode,...)
Definition: error.c:24
ChildWnd * g_pChildWnd
Definition: childwnd.c:23
#define MF_BYCOMMAND
Definition: winuser.h:202
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define TreeView_EditLabel(hwnd, hitem)
Definition: commctrl.h:3500
HWND hTreeWnd
Definition: main.h:61
HWND hWnd
Definition: settings.c:17
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
LONG RenameKey(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpNewName)
Definition: edit.c:1489
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define TVN_ENDLABELEDIT
Definition: commctrl.h:3740
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
#define NMTREEVIEW
Definition: commctrl.h:3638
#define ID_EDIT_DELETE
Definition: resource.h:60
#define TVN_BEGINLABELEDIT
Definition: commctrl.h:3739
#define ID_EDIT_PERMISSIONS
Definition: resource.h:153
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define ID_EDIT_RENAME
Definition: resource.h:61
#define COUNT_OF(a)
Definition: main.h:33
__wchar_t WCHAR
Definition: xmlstorage.h:180
HMENU hPopupMenus
Definition: main.c:33
#define NM_SETFOCUS
Definition: commctrl.h:135
#define TVN_SELCHANGED
Definition: commctrl.h:3731
#define MF_ENABLED
Definition: winuser.h:128
#define MAX_PATH
Definition: compat.h:34
static const WCHAR L[]
Definition: oid.c:1250
#define TreeView_GetParent(hwnd, hitem)
Definition: commctrl.h:3465
Definition: inflate.c:139
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:83
#define TVN_ITEMEXPANDING
Definition: commctrl.h:3734
HINSTANCE hInst
Definition: dxdiag.c:13
HMENU hMenuFrame
Definition: main.c:32
#define LPNMTVDISPINFO
Definition: commctrl.h:3672
#define IDS_ERROR
Definition: resource.h:18
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define ID_TREE_DELETE
Definition: resource.h:154
#define MF_GRAYED
Definition: winuser.h:129
LPARAM lParam
Definition: combotst.c:139
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
int nFocusPanel
Definition: main.h:66
VOID UpdateAddress(HTREEITEM hItem, HKEY hRootKey, LPCWSTR pszPath)
Definition: childwnd.c:232

Referenced by ChildWndProc().

Variable Documentation

◆ Image_Closed

int Image_Closed = 0
static

Definition at line 28 of file treeview.c.

Referenced by AddEntryToTree(), and InitTreeViewImageLists().

◆ Image_Open

int Image_Open = 0
static

Definition at line 27 of file treeview.c.

Referenced by AddEntryToTree(), and InitTreeViewImageLists().

◆ Image_Root

int Image_Root = 0
static

Definition at line 29 of file treeview.c.

Referenced by InitTreeViewImageLists(), and InitTreeViewItems().

◆ pathBuffer

LPWSTR pathBuffer
static

Definition at line 31 of file treeview.c.

Referenced by DestroyTreeView(), GetItemPath(), test_listbox_dlgdir(), and test_listbox_LB_DIR().