Home > OS >  Best way to display hierarchal data using Windows API (like that of the Registry Editor)
Best way to display hierarchal data using Windows API (like that of the Registry Editor)

Time:12-31

What is the best way to display data hierarchally, like that of the registry editor, with the Win32 API? Are there any controls that could do this? I know of this method in .NET, but I really don't feel like creating a ton of interactions between managed code and C .

CodePudding user response:

After you have created the TreeView control and added it to your window (see link in comments), you can load the registry keys like this. You would need some more code to add the values in a list view.

void LoadRegRec(HWND tree_view, HTREEITEM parent, HKEY root)
{
    DWORD index = 0;
    TCHAR name[512];
    while (ERROR_SUCCESS == RegEnumKey(root, index  , name, sizeof(name) / sizeof(name[0]))) {
        TV_INSERTSTRUCT tvinsert = { 0 };
        tvinsert.hParent = parent;
        tvinsert.hInsertAfter = TVI_LAST;
        tvinsert.item.mask = TVIF_TEXT;
        tvinsert.item.pszText = name;
        HTREEITEM node = (HTREEITEM)SendMessage(tree_view, TVM_INSERTITEM, 0, (LPARAM)&tvinsert);
        HKEY next_key;
        RegOpenKey(root, name, &next_key);
        LoadRegRec(tree_view, node, next_key);
        RegCloseKey(next_key);
    }
}
void LoadRegistry(HWND tree_view)
{
    HKEY root;
    RegOpenKey(HKEY_CURRENT_USER, TEXT("Software"), &root);
    LoadRegRec(tree_view, NULL, root);
    RegCloseKey(root);
}
  • Related