I am trying to change the color of static开发者_如何学JAVA controls that are child of a tab control. Now the thing is that, when I try to change it using WM_CTLCOLORSTATIC, it does not work.
When I define the main window as static's parent, it works fine. But how can I change the color while they are child of tab?
As David Heffernan says, when Visual Styles (themes) are enabled, the tab control has a fancy gradient-filled background. Since this only works when the child controls of the tab page have the same background, controls parented by tab controls actually have their backgrounds drawn by the parent.
Yep, it does not work with Themes. How do I make it work?
You don't, that's the whole point of Visual Styles. If you want this kind of fine-grained control over appearance, you should disable visual styles for your particular controls.
You can use the SetWindowTheme
function to do this. Pass a handle to your control window as the first parameter and an empty string for the last two parameters:
SetWindowTheme(hwndCtrl, L" ", L" ");
Of course, you'll have to include uxtheme.h
in order to call this function, and link to uxtheme.lib
.
If you want your application to continue working on versions of Windows prior to XP (when the theming APIs were introduced), then you'll need to either use delay-loading or LoadLibrary
and GetProcAddress
to call the function dynamically.
You could also try calling the EnableThemeDialogTexture
function and specifying the ETDT_DISABLE
flag to disable the background texturing applied to tab dialogs.
Child controls send WM_CTLCOLORSTATIC to their parent. If you want the tab control to be parent of the static control, you need to subclass the tab control and handle WM_CTLCOLORSTATIC in there
精彩评论