wxTreeCtrl does not look so native under Windows 7

94 views
Skip to first unread message

Eran Ifrah

unread,
Dec 5, 2010, 1:20:00 PM12/5/10
to wxu
Hi list,

I asked this question in the IRC channel with no luck, so I am posting
it here hoping for a better answer.

I am using wxTreeCtrl in my application, however, I noticed that under
Windows 7 there are some differences between the wxWidgets tree and
some other applications
tree control.

Attached is an image:
http://codelite.org/tmp_images/treecontrol.png

1) The collapse/expand button is different
2) The text selection
3) The third difference can not be seen on the image, but when
hovering the little triangle on the native tree control it changes its
colour, obviously this does not happen with wxWidgets tree.

I know it may sound like a tiny issue and not that important, but
still, I want my application to look as native as it can - is there a
way to achieve this with wxWidgets?

my wx (monolithic, shared):
2.8.10
2.9 (trunk)
using MinGW (g++4.4.1) as the compiler

Thanks,
--
Eran Ifrah
Cross platform, open source C++ IDE: http://www.codelite.org

Vadim Zeitlin

unread,
Dec 5, 2010, 5:23:54 PM12/5/10
to wx-u...@googlegroups.com
On Sun, 5 Dec 2010 20:20:00 +0200 Eran Ifrah <eran....@gmail.com> wrote:

EI> I am using wxTreeCtrl in my application, however, I noticed that under
EI> Windows 7 there are some differences between the wxWidgets tree and
EI> some other applications tree control.
EI>
EI> Attached is an image:
EI> http://codelite.org/tmp_images/treecontrol.png
EI>
EI> 1) The collapse/expand button is different

These other applications probably use .NET/WPF which seems to implement
its own tree control different from the "standard" one. At least if you
believe the answer from Microsoft person at

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/967cd948-d72f-41c9-803c-bdb50cd9e6e2

I'm not sure if I'm ready to believe it because Spy++ does show Explorer
using SysTreeView32, albeit as a child of DirectUIHWND. So maybe there is
some way to make the standard control to behave like this but I don't know
of it and it doesn't seem to be documented. It's not a matter of style
because if you create the control with exactly the same styles as Explorer
uses, you still get plus and minus signs and not arrows -- but I don't know
what else can it be.


Unfortunately I'm afraid we'll need to get used to non-native code being
second class citizen under Windows now :-(

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Michael Hieke

unread,
Dec 6, 2010, 5:25:44 AM12/6/10
to wx-u...@googlegroups.com
Hi Eran,

2010/12/5 Eran Ifrah <eran....@gmail.com>:

> 1) The collapse/expand button is different
> 2) The text selection
> 3) The third difference can not be seen on the image, but when
> hovering the little triangle on the native tree control it changes its
> colour, obviously this does not happen with wxWidgets tree.

Have you tried calling SetWindowTheme() (see
http://msdn.microsoft.com/en-us/library/bb759827%28VS.85%29.aspx) for
your tree control? If you pass "Explorer" for the second parameter the
"nativeness" of the tree should improve.

HTH

--
Michael Hieke

Eran Ifrah

unread,
Dec 6, 2010, 7:02:37 AM12/6/10
to wx-u...@googlegroups.com
Thanks alot, it works!

Adding these lines to the constructor of my derived class (of
wxTreeCtrl) did the trick:

#ifdef __WXMSW__
SetWindowTheme((HWND)GetHWND(), L"Explorer", NULL);
#endif

> --
> Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
> To unsubscribe, send email to wx-users+u...@googlegroups.com
> or visit http://groups.google.com/group/wx-users

Vadim Zeitlin

unread,
Dec 6, 2010, 7:29:33 AM12/6/10
to wx-u...@googlegroups.com
On Mon, 6 Dec 2010 11:25:44 +0100 Michael Hieke <michae...@googlemail.com> wrote:

MH> Have you tried calling SetWindowTheme() (see
MH> http://msdn.microsoft.com/en-us/library/bb759827%28VS.85%29.aspx) for
MH> your tree control? If you pass "Explorer" for the second parameter the
MH> "nativeness" of the tree should improve.

Wow, the solution was finally very simple, thanks for pointing it out!

Does anybody know of any reason not to do this by default? If not, I'll
add the code to do it to wxTreeCtrl (and also probably wxListCtrl whose
appearance can be improved by doing this too).

Thanks!

Vadim Zeitlin

unread,
Feb 5, 2011, 6:55:07 PM2/5/11
to wx-u...@googlegroups.com
On Mon, 6 Dec 2010 11:25:44 +0100 Michael Hieke <michae...@googlemail.com> wrote:

MH> 2010/12/5 Eran Ifrah <eran....@gmail.com>:
MH>
MH> > 1) The collapse/expand button is different
MH> > 2) The text selection
MH> > 3) The third difference can not be seen on the image, but when
MH> > hovering the little triangle on the native tree control it changes its
MH> > colour, obviously this does not happen with wxWidgets tree.
MH>

MH> Have you tried calling SetWindowTheme() (see
MH> http://msdn.microsoft.com/en-us/library/bb759827%28VS.85%29.aspx) for

MH> your tree control? If you pass "Explorer" for the second parameter the
MH> "nativeness" of the tree should improve.

Just FYI I've implemented wxTR_TWIST_BUTTONS support in wxMSW wxTreeCtrl
in terms of SetWindowTheme("EXPLORER"), i.e. you will get Explorer look if
you use this style now (under Vista or later only, of course).

FWIW I initially wanted to use it by default but this makes the tree
control look inconsistent with other controls, especially wxListCtrl. And
using the same theme for the latter results in various display artefacts,
probably because we don't use WS_EX_COMPOSITED for it and so can't be
enabled by default. Maybe we should make all the windows composited and use
this style but this would require more testing than I can currently
provide.

Regards,

Reply all
Reply to author
Forward
0 new messages