[Mono-winforms-list] SWF Theme: Windows XP
Tue, 14 Sep 2004 09:45:52 -0400
This section of an article on
c/platform/commctls/userex/cookbook.asp) mentions that the uxTheme API
header and documentation is in the windows platform SDK:
Using Visual Styles with a Custom Control
The UxTheme API referenced in the steps to add visual styles to a control
and in the corresponding code examples are defined in the header file,
Uxtheme.h. The elements of the API are documented in the Platform SDK. In
addition to describing the steps for applying visual styles to a control,
this section provides a drawing code sample and tips on drawing controls.
Example of Drawing Code
To enable a control to apply visual styles.
Call OpenThemeData and pass the hwnd of the control you want to apply visual
styles to and a class list that describes the control's type. The classes
are defined in Tmschema.h. OpenThemeData returns an HTHEME handle, but if
the visual style manager is disabled or the current visual style does not
supply specific information for a given control, the function returns NULL.
If the return value is NULL use nonvisual style drawing functions.
To draw the control, call DrawThemeBackground and pass the following:
Theme handle returned from OpenThemeData, the HDC to use for rendering the
Part identifier that describes the part of the control to render. For
information about control parts and states, see Parts and States.
State identifier that describes the current state of the part.
Pointer to the RECT structure that contains the coordinates of the rectangle
where the control will be rendered.
Some parts can be partially transparent. You can determine this by calling
IsThemeBackgroundPartiallyTransparent with the theme handle, a control part,
and a control state.
If your control draws text, position the text within the content rectangle
of the control and select a font.
To determine the location of the content rectangle call
Add your desired font to the device context (DC) then call DrawThemeText.
This function enables visual effects such as shadowed text in some controls.
When your control receives a WM_THEMECHANGED message, it should do the
Call CloseThemeData to close the existing theme handle.
Call OpenThemeData to get the theme handle for the newly loaded visual
//This code sample illustrates the two calls.
hTheme = OpenThemeData (hwnd, L"MyClassName");
When your control receives a WM_DESTROY message, call CloseThemeData to
release the theme handle that was returned when you called OpenThemeData.
Example of Drawing Code
The following code sample demonstrates how to draw a button control.
HTHEME hTheme = NULL;
hTheme = OpenThemeData(hwndButton, "Button");
DrawMyControl(hDC, hwndButton, hTheme, iState);
void DrawMyControl(HDC hDC, HWND hwndButton, HTHEME hTheme, int iState)
RECT rc, rcContent;
hr = StringCchLength(szButtonText,
hr = DrawThemeBackground(hTheme, hDC, BP_BUTTON,
iState, &rc, 0);
// Always check your result codes.
hr = GetThemeBackgroundContentRect(hTheme,
BP_BUTTON, iState, &rc, &rcContent);
hr = DrawThemeText(hTheme, hDC, BP_BUTTON, iState,
DT_CENTER | DT_VCENTER | DT_SINGLELINE,
// Draw the control without using visual styles.
[mailto:firstname.lastname@example.org] On Behalf Of Peter Dennis
Sent: Tuesday, September 14, 2004 1:31 AM
To: Mono Winforms List
Subject: Re: [Mono-winforms-list] SWF Theme: Windows XP
>Today, I've started to create a class to theme apps running on Windows XP.
>With the first three, I've found it's not possible to draw the state
>where the mouse is over the control. Button state does not have a
Hm, I believe that only applies when the FlatStyle for the button is
FlatStyle.System. We should be able to add something there. (See my UxTheme
>One more thing I've found it's that the image and text of the control,
>when not disabled, it's not draw through the theme class, but inside
Good catch. I'll add a DrawStringEnabled function to the theme interface. Is
there complete documentation for Microsoft's UxTheme API? Should we model
after theirs? I couldn't find complete docs when I tried a few months back.
Mono-winforms-list maillist - Monoemail@example.com