Jump to content
  • Advertisement
Sign in to follow this  

[TIP] - Windows XP Visual Styles

This topic is 4848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well.... after long hours in the salt mines, I'm posting what I've worked out on Visual styles... (especially the parts that don't seem to work automatically...) and you good folk here who need help with Visual styles can benefit from it (mostly just posting this for future searches)... Seems like one of the ONLY controls left un-themed by Microsoft is the static control... now why is that? Even when you get your nice dialog to display the nice background texture of the XP theme buttons with EnableThemeDialogTexture... there are nasty blocks of ugly STOCK_GRAY_BRUSH surrounding all your StaticTexts, your Checkboxes, your Slider controls, and many others. What a mess! Luckily, you can pull the 'ol window subclassing trick out of the hat for all StaticTexts... and it will affect each and every one of these controls... This quick tip assumes you know how to subclass windows, and are familiar with loading .dlls with LoadLibrary and getting their function pointers with "GetProcAddress"... it also assumes you have a manifest file set up for your .exe... (these things can be found easily reading the PSDK docs on Visual styles)... That assumed, here's the code block that does the work, inside the subclassed StaticText's WndProc:
// fOpenThemeData            - ptr to OpenThemeData in uxtheme.dll module
// fCloseThemeData           - ptr to CloseThemeData in uxtheme.dll module
// fDrawThemeText            - ptr to DrawThemeText in uxtheme.dll module
// fDrawThemeBackground      - ptr to DrawThemeBackground in uxtheme.dll module
// fGetThemeBackgroundContentRect - ptr to GetThemeBackgroundContentRect in 
//                                  uxtheme.dll module
// statictheme               - HTHEME handle for static texts

        case WM_PAINT:
                if(fOpenThemeData)                // the function pointer exists
                        RECT client,contentrect;

                        char windowtext[250];
                        wchar_t	widetext[250];

                        ::GetWindowRect(hwnd, &client);
                        ::GetWindowText(hwnd, windowtext, sizeof(windowtext));

                        // Themes use Unicode exclusively


		        // Retrieve the font set in your resource editor;
                        // otherwise, the font from the theme will be used,
                        // and it probably won't match

                        HFONT hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0),
                              hfontorig = 0;
                        // Use Tab control's theme data, since static text has
                        // none

                        statictheme = fOpenThemeData(hwnd,L"Tab"); 
                        HDC hdc     = ::GetWindowDC(hwnd);

                        // set that juicy, XP Visual style bg color


                        // The next function needs client coordinates, not
                        // absolute coordinates

                        ::GetClientRect(hwnd, &client);
                        fGetThemeBackgroundContentRect(statictheme, hdc, 
                                                       TABP_BODY, 0, &client,

                        // Set that font before drawing!

                        hfontorig = SelectFont(hdc,hfont);
                        fDrawThemeText(statictheme, hdc, TABP_TABITEM,
                                       TIS_NORMAL, widetext,
                                       DT_CENTER | DT_VCENTER | DT_SINGLELINE,
                                       0, &contentrect);

                        // return things to normal


                        hfont = SelectFont(hdc,hfontorig);


                        // yes; we processed WM_PAINT

                        return 0;

If you implement the code, you'll see that your widgets are now nicely surrounded by that lovely XP Visual style texture. Chad

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!