speedup listing items in the treeview

svn path=/trunk/; revision=8493
This commit is contained in:
Gunnar Dalsnes 2004-03-01 00:50:56 +00:00
parent 772d5765b7
commit f4ae5098cc

View file

@ -117,7 +117,12 @@ static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPTSTR label, HK
tvi.cChildren = dwChildren; tvi.cChildren = dwChildren;
tvi.lParam = (LPARAM)hKey; tvi.lParam = (LPARAM)hKey;
tvins.u.item = tvi; tvins.u.item = tvi;
tvins.hInsertAfter = (HTREEITEM)(hKey ? TVI_LAST : TVI_SORT); /*
* Inserting items at front is faster then inserting to back.
* Sorting after inserting each item is painfully slow...
* -Gunnar
*/
tvins.hInsertAfter = TVI_FIRST;//(HTREEITEM)(hKey ? TVI_LAST : TVI_SORT);
tvins.hParent = hParent; tvins.hParent = hParent;
return TreeView_InsertItem(hwndTV, &tvins); return TreeView_InsertItem(hwndTV, &tvins);
} }
@ -151,6 +156,8 @@ static BOOL InitTreeViewItems(HWND hwndTV, LPTSTR pHostName)
if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_USERS"), HKEY_USERS, 1)) return FALSE; if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_USERS"), HKEY_USERS, 1)) return FALSE;
if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_CONFIG"), HKEY_CURRENT_CONFIG, 1)) return FALSE; if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_CONFIG"), HKEY_CURRENT_CONFIG, 1)) return FALSE;
SendMessage(hwndTV, TVM_SORTCHILDREN, 0, hRoot);
/* expand and select host name */ /* expand and select host name */
TreeView_Expand(hwndTV, hRoot, TVE_EXPAND); TreeView_Expand(hwndTV, hRoot, TVE_EXPAND);
TreeView_Select(hwndTV, hRoot, TVGN_CARET); TreeView_Select(hwndTV, hRoot, TVGN_CARET);
@ -242,6 +249,9 @@ BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
printf("dwSubCount=%ld, Name=%s\n", dwSubCount, Name); printf("dwSubCount=%ld, Name=%s\n", dwSubCount, Name);
AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount); AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount);
} }
SendMessage(hwndTV, TVM_SORTCHILDREN, 0, pnmtv->itemNew.hItem);
RegCloseKey(hNewKey); RegCloseKey(hNewKey);
HeapFree(GetProcessHeap(), 0, Name); HeapFree(GetProcessHeap(), 0, Name);