定义 OpenThemeData API 和 DrawThemeTextEx,以及一些必需的结构和常量:
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr OpenThemeData(IntPtr hwnd, string pszClassList);
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
private extern static Int32 DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string pszText, int iCharCount, uint flags, ref RECT rect, ref DTTOPTS poptions);
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct DTTOPTS
{
public int dwSize;
public int dwFlags;
public int crText;
public int crBorder;
public int crShadow;
public int iTextShadowType;
public int ptShadowOffsetX;
public int ptShadowOffsetY;
public int iBorderSize;
public int iFontPropId;
public int iColorPropId;
public int iStateId;
public bool fApplyOverlay;
public int iGlowSize;
public IntPtr pfnDrawTextCallback;
public IntPtr lParam;
}
// taken from vsstyle.h
private const int WP_CAPTION = 1;
private const int CS_ACTIVE = 1;
然后,这样称呼它:
IntPtr handle = OpenThemeData(IntPtr.Zero, "WINDOW");
DrawThemeTextExt(handle, hdc, WS_CAPTION, CS_ACTIVE, ...)
WS_CAPTION 和 CS_ACTIVE 值分别与 .NET 2 的 Caption 和 Active 匹配。值的官方描述如下:零件和状态 http://msdn.microsoft.com/en-us/library/bb773210.aspx