BOOL RefreshTreeView(HWND hwndTV) { HTREEITEM hItem; HTREEITEM hSelectedItem; HCURSOR hcursorOld; HTREEITEM hRoot; WINE_TRACE("\n"); hSelectedItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CARET, 0); hcursorOld = SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_WAIT)); SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0); hRoot = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_ROOT, 0); hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hRoot); while (hItem) { RefreshTreeItem(hwndTV, hItem); hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem); } SendMessageW(hwndTV, WM_SETREDRAW, TRUE, 0); InvalidateRect(hwndTV, NULL, FALSE); SetCursor(hcursorOld); /* We reselect the currently selected node, this will prompt a refresh of the listview. */ SendMessageW(hwndTV, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hSelectedItem); return TRUE; }
void CTreePropSheetBase::RefreshPageTree(HTREEITEM hItem /* = TVI_ROOT */, const bool bRedraw /* = true */) { // If TVI_ROOT, get the first item. if (hItem == TVI_ROOT) { hItem = m_pwndPageTree->GetNextItem(NULL, TVGN_ROOT); } while( hItem ) { RefreshTreeItem( hItem ); if( m_pwndPageTree->ItemHasChildren( hItem ) ) { RefreshPageTree( m_pwndPageTree->GetNextItem(hItem, TVGN_CHILD), false ); } hItem = m_pwndPageTree->GetNextItem(hItem, TVGN_NEXT); } if( bRedraw ) { m_pwndPageTree->Invalidate( TRUE ); } }
static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem) { HKEY hRoot, hKey, hSubKey; HTREEITEM childItem; LPWSTR KeyPath; DWORD dwCount, dwIndex, dwMaxSubKeyLen; LPWSTR Name; TVITEMW tvItem; hRoot = NULL; KeyPath = GetItemPath(hwndTV, hItem, &hRoot); if (!KeyPath || !hRoot) return FALSE; if (*KeyPath) { if (RegOpenKeyExW(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { WINE_TRACE("RegOpenKeyEx failed, %s was probably removed.\n", wine_dbgstr_w(KeyPath)); return FALSE; } } else { hKey = hRoot; } HeapFree(GetProcessHeap(), 0, KeyPath); if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { return FALSE; } /* Set the number of children again */ tvItem.mask = TVIF_CHILDREN; tvItem.hItem = hItem; tvItem.cChildren = dwCount; if (!TreeView_SetItemW(hwndTV, &tvItem)) { return FALSE; } /* We don't have to bother with the rest if it's not expanded. */ if (SendMessageW(hwndTV, TVM_GETITEMSTATE, (WPARAM)hItem, TVIS_EXPANDED) == 0) { RegCloseKey(hKey); return TRUE; } dwMaxSubKeyLen++; /* account for the \0 terminator */ if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR)))) { return FALSE; } tvItem.cchTextMax = dwMaxSubKeyLen; if (!(tvItem.pszText = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR)))) { HeapFree(GetProcessHeap(), 0, Name); return FALSE; } /* Now go through all the children in the registry, and check if any have to be added. */ for (dwIndex = 0; dwIndex < dwCount; dwIndex++) { DWORD cName = dwMaxSubKeyLen, dwSubCount; BOOL found; found = FALSE; if (RegEnumKeyExW(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS) { continue; } /* Find the number of children of the node. */ dwSubCount = 0; if (RegOpenKeyExW(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) { if (RegQueryInfoKeyW(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { dwSubCount = 0; } RegCloseKey(hSubKey); } /* Check if the node is already in there. */ for (childItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem); childItem; childItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)childItem)) { tvItem.mask = TVIF_TEXT; tvItem.hItem = childItem; if (!TreeView_GetItemW(hwndTV, &tvItem)) { HeapFree(GetProcessHeap(), 0, Name); HeapFree(GetProcessHeap(), 0, tvItem.pszText); return FALSE; } if (!lstrcmpiW(tvItem.pszText, Name)) { found = TRUE; break; } } if (found == FALSE) { WINE_TRACE("New subkey %s\n", wine_dbgstr_w(Name)); AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount); } } HeapFree(GetProcessHeap(), 0, Name); HeapFree(GetProcessHeap(), 0, tvItem.pszText); RegCloseKey(hKey); /* Now go through all the children in the tree, and check if any have to be removed. */ childItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem); while (childItem) { HTREEITEM nextItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)childItem); if (RefreshTreeItem(hwndTV, childItem) == FALSE) { SendMessageW(hwndTV, TVM_DELETEITEM, 0, (LPARAM)childItem); } childItem = nextItem; } return TRUE; }