[Mono-winforms-list] SWF Theme: Windows XP
Dan Maltes
dan@astusa.com
Tue, 14 Sep 2004 10:06:06 -0400
Here's a list of UxTheme functions:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/pla
tform/commctls/userex/refentry.asp?frame=true
Hope this is what you were looking for.
Regards,
Dan Maltes
-----Original Message-----
From: mono-winforms-list-admin@lists.ximian.com
[mailto:mono-winforms-list-admin@lists.ximian.com] On Behalf Of Dan Maltes
Sent: Tuesday, September 14, 2004 9:46 AM
To: 'Peter Dennis Bartok'; 'Mono Winforms List'
Subject: RE: [Mono-winforms-list] SWF Theme: Windows XP
This section of an article on
MSDN(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellc
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
control.
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
GetThemeBackgroundContentRect 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
following:
Call CloseThemeData to close the existing theme handle.
Call OpenThemeData to get the theme handle for the newly loaded visual
style.
//This code sample illustrates the two calls.
case WM_THEMECHANGED:
CloseThemeData (hTheme);
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.
Hide Example
HTHEME hTheme = NULL;
hTheme = OpenThemeData(hwndButton, "Button"); ...
DrawMyControl(hDC, hwndButton, hTheme, iState); ...
if (hTheme)
{
CloseTheme(hTheme);
}
void DrawMyControl(HDC hDC, HWND hwndButton, HTHEME hTheme, int iState) {
RECT rc, rcContent;
TCHAR szButtonText[255];
HRESULT hr;
size_t cch;
GetWindowRect(hwndButton, &rc);
GetWindowText(hwndButton, szButtonText,
(sizeof(szButtonText)/sizeof(szButtonText[0])+1));
hr = StringCchLength(szButtonText,
(sizeof(szButtonText)/sizeof(szButtonText[0])), &cch);
if (hTheme)
{
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,
szButtonText, cch,
DT_CENTER | DT_VCENTER | DT_SINGLELINE,
0, &rcContent);
}
else
{
// Draw the control without using visual styles.
}
}
Regards,
Dan Maltes
-----Original Message-----
From: mono-winforms-list-admin@lists.ximian.com
[mailto:mono-winforms-list-admin@lists.ximian.com] On Behalf Of Peter Dennis
Bartok
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.
Awesome!
>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
>MouseOver value.
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
question below)
>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
>the control.
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.
Cheers,
Peter
_______________________________________________
Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list
_______________________________________________
Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list