Question

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.

Was it helpful?

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

OTHER TIPS

If your application is targeting Windows XP or above, simply use:

SetWindowTheme(hwndList, L"Explorer", NULL);

where hwndList is your CTreeCtrl handle. See http://msdn.microsoft.com/en-us/library/windows/desktop/bb759827(v=vs.85).aspx for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top