Search code examples
visual-c++mfccommon-controls

How do I get updated themes for CTreeCtrl


I have a C++ MFC application which uses a CTreeCtrl, I am running Windows 7 and Visual Studio 2008. I am attempting to get my tree control to have arrows for the expand/collapse buttons instead of the +/-

a good example of what I am looking for is the tree control that you see when you edit the properties of your project in Visual Studio.

no matter what styles or attempts to modify themes I still have the old xp style +/-

I feel like I am missing something simple, any help would be appreciated.


Solution

  • Add this function to get the vista style

    LRESULT EnableVistaTheme(HWND hwnd, LPCWSTR classList, LPCWSTR subApp, LPCWSTR idlist)
    {
        LRESULT lResult = S_FALSE;
    
    HRESULT (__stdcall *pSetWindowTheme)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
    HANDLE (__stdcall *pOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);
    HRESULT (__stdcall *pCloseThemeData)(HANDLE hTheme);
    
    HMODULE hinstDll = ::LoadLibrary(_T("UxTheme.dll"));
    if (hinstDll)
    {
        (FARPROC&)pOpenThemeData = ::GetProcAddress(hinstDll, "OpenThemeData");
        (FARPROC&)pCloseThemeData = ::GetProcAddress(hinstDll, "CloseThemeData");
        (FARPROC&)pSetWindowTheme = ::GetProcAddress(hinstDll, "SetWindowTheme");
        if (pSetWindowTheme && pOpenThemeData && pCloseThemeData)
        {
            HANDLE theme = pOpenThemeData(hwnd,classList);
            if (theme!=NULL)
            {
                VERIFY(pCloseThemeData(theme)==S_OK);
                lResult = pSetWindowTheme(hwnd, subApp, idlist);
            }
        }
        ::FreeLibrary(hinstDll);
    }
    return lResult;
    }
    

    and call this function with parameters as,

    hwnd: Your tree control's handle

    classList: L"TreeView"

    subApp: L"Explorer"

    idlist: NULL