Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than uxtheme, prefix the name with the module name and a period.
DrawThemeText (uxtheme)
.
C# Signature:
[DllImport("uxtheme.dll")]
static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int length, DT flags, ref RECT rect, ref DTTOPTS poptions);
VB.NET Signature:
<DllImport("uxtheme.dll", ExactSpelling:=True, CharSet:=CharSet.Unicode)> _
Public Shared Function DrawThemeTextEx(hTheme As IntPtr, hdc As IntPtr, iPartId As Integer, iStateId As Integer, text As [String], length As Integer, flags As DT, ByRef rect As RECT, ByRef poptions As DTTOPTS) As Int32
End Function
[DllImport("uxtheme", ExactSpelling=true, CharSet=CharSet.Unicode)]
public extern static Int32 DrawThemeText(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, String text, int textLength, UInt32 textFlags, UInt32 textFlags2, ref RECT pRect);
VB .NET Signature:
Declare Function DrawThemeText Lib "uxtheme.dll" (TODO) As TODO
'// Make sure Themes are enabled in the application
Public Sub New()
MyBase.New()
' Enable WindowsXP Themes without a manifest file
System.Windows.Forms.Application.EnableVisualStyles()
System.Windows.Forms.Application.DoEvents()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'//
'// P/Invoke events
<DllImport("Comctl32.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
Private Overloads Shared Function DllGetVersion(ByRef pdvi As DLLVERSIONINFO) As Integer
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure DLLVERSIONINFO
Friend cbSize As Integer
Friend dwMajorVersion As Integer
Friend dwMinorVersion As Integer
Friend dwBuildNumber As Integer
Friend dwPlatformID As Integer
End Structure
<DllImport("UxTheme.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
Public Overloads Shared Function OpenThemeData(ByVal hwnd As IntPtr, <MarshalAs(UnmanagedType.LPTStr)> ByVal pszClassList As String) As IntPtr
End Function
<DllImport("UxTheme.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
Public Overloads Shared Function CloseThemeData(ByVal htheme As IntPtr) As Integer
End Function
<DllImport("UxTheme.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Unicode)> _
Public Overloads Shared Function IsAppThemed() As Boolean
End Function
' IsAppThemed will return true if the Os is themed even if the app is not.
' To overcome this problem we must also check which version of ComCtl32.dll is
' being used. Since ComCtl32.dll version 6 is exclusive to WindowsXP, we do not
' need to check the OSVersion.
Public ReadOnly Property IsAppXPThemed() As Boolean
Get
Dim dllVer As New DLLVERSIONINFO
dllVer.cbSize = Marshal.SizeOf(dllVer)
DllGetVersion(dllVer)
If dllVer.dwMajorVersion >= 6 Then If IsAppThemed() Then Return True
End Get
End Property
'//
'// Use the P/Invoke API
Public Function DrawThemedText(ByVal Text As String, ByVal ThemeClass As UX_ThemeClass, ByVal ThemePart As UX_ThemePart, ByVal ThemeState As UX_ThemeState, ByVal Bounds As Rectangle) As Bitmap
' The handle for the theme objects.
Dim My_ThemeHandle As IntPtr
' Setup String Pointer.
Dim My_ThemeText As String = Text
' Create Destination Bitmap from bounding dimensions.
Dim My_Bitmap As New Bitmap(Bounds.Width, Bounds.Height)
' Create Graphics to ge the HDC from.
Dim My_Graphics As Graphics = Graphics.FromImage(My_Bitmap)
' If Themed then draw themed, otherwise draw non-themed.
If IsAppXPThemed Then
' Get the HDC from the hidden atribute.
Dim My_HDC As IntPtr = My_Graphics.GetHdc
' If we have a Pointer open we will now close it.
If Not My_ThemeHandle.Equals(IntPtr.Zero) Then CloseThemeData(My_ThemeHandle)
' We will now open a pointer to a Theme Data object. Notice that the string is being parsed from the Enum.
My_ThemeHandle = OpenThemeData(Me.Handle, [Enum].GetName(GetType(UX_ThemeClass), ThemeClass))
If My_ThemeText.Text <> "" Then
' Draw Theme Background to the destination Bitmap.
DrawThemeText(My_ThemeHandle, My_HDC, ThemePart, ThemeState, My_ThemeText, -1, DrawTextFlags.DT_CENTER Or DrawTextFlags.DT_VCENTER, 0, Bounds)
End If
' HDC is do longer required so clean it up.
My_Graphics.ReleaseHdc(My_HDC)
End If
' Finished using the Graphics object so dispose of it.
My_Graphics.Dispose()
' Return the extracted bitmap.
Return My_Bitmap
End Function
'//
'// How to use the Functions
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawImage(DrawThemedText("Hellow World!", UX_ThemeClass.Button, UX_ThemePart.BP_PUSHBUTTON, UX_ThemeState.ABS_DOWNHOT, New Rectangle(Point.Empty, Me.Size)), Point.Empty)
End Sub
'//
Please add some more!
Alternative Managed API:
TODO
The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.
6/3/2013 5:41:04 PM - dahminator-75.174.65.168
Used with [DTTOPTS]
7/7/2014 9:00:03 AM - -50.241.168.105
Used with [DrawThemeTextEx]
9/6/2016 1:46:14 PM - -50.241.168.105
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).