1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
Option Explicit
Private Declare Function OpenThemeData Lib "UxTheme.dll" (ByVal Hwnd As Long, ByVal LPCWSTR As Any) As Long
Private Declare Function CloseThemeData Lib "UxTheme.dll" (ByVal hTheme As Long) As Long
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private hdc As Long
Private Declare Function DrawThemeBackground Lib "UxTheme.dll" (ByVal hTheme As Long, _
ByVal hdc As Long, ByVal iPartId As Long, _
ByVal iStateId As Long, _
ByRef pRect As Rect, _
ByVal pClipRect As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal Hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal Hwnd As Long) As Long
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Function bounds(L As Long, T As Long, W As Long, H As Long) As Rect
bounds.Left = L
bounds.Top = T
bounds.Right = L + W
bounds.Bottom = T + H
End Function
Private Sub DrawTheme(T As Long, S As Long, B As Rect, St As String)
Dim H As Long
H = OpenThemeData(0, StrPtr(St))
DrawThemeBackground H, hdc, T, S, B, 0
CloseThemeData (H)
End Sub
Public Sub CommandButton1_Click()
Dim Hwnd As Long
Hwnd = FindWindowA(vbNullString, Me.Caption)
hdc = GetDC(Hwnd)
'Button
'Normal
DrawTheme 1, 1, bounds(80 * 0, 10, 70, 30), "button"
'Hot
DrawTheme 1, 2, bounds(80 * 1, 10, 70, 30), "button"
'Pushed
DrawTheme 1, 3, bounds(80 * 2, 10, 70, 30), "button"
'Disabled
DrawTheme 1, 4, bounds(80 * 3, 10, 70, 30), "button"
'Fucused
DrawTheme 1, 5, bounds(80 * 4, 10, 70, 30), "button"
'OptionButton
'Normal
DrawTheme 2, 1, bounds(80 * 0, 50, 70, 30), "button"
'Hot
DrawTheme 2, 2, bounds(80 * 1, 50, 70, 30), "button"
'Pushed
DrawTheme 2, 3, bounds(80 * 2, 50, 70, 30), "button"
'Disabled
DrawTheme 2, 4, bounds(80 * 3, 50, 70, 30), "button"
'Fucused
DrawTheme 2, 5, bounds(80 * 4, 50, 70, 30), "button"
'CheckButton
'Normal
DrawTheme 3, 1, bounds(80 * 0, 70, 70, 30), "button"
'Hot
DrawTheme 3, 2, bounds(80 * 1, 70, 70, 30), "button"
'Pushed
DrawTheme 3, 3, bounds(80 * 2, 70, 70, 30), "button"
'Disabled
DrawTheme 3, 4, bounds(80 * 3, 70, 70, 30), "button"
'Fucused
DrawTheme 2, 5, bounds(80 * 4, 70, 70, 30), "button"
'spin
'Normal
DrawTheme 1, 1, bounds(80 * 0, 100, 20, 20), "spin"
'Hot
DrawTheme 1, 2, bounds(80 * 1, 100, 20, 20), "spin"
'Pushed
DrawTheme 1, 3, bounds(80 * 2, 100, 20, 20), "spin"
'Disabled
DrawTheme 1, 4, bounds(80 * 3, 100, 20, 20), "spin"
'Fucused
DrawTheme 1, 5, bounds(80 * 4, 100, 20, 20), "spin"
'spin
'Normal
DrawTheme 2, 1, bounds(80 * 0, 130, 20, 20), "spin"
'Hot
DrawTheme 2, 2, bounds(80 * 1, 130, 20, 20), "spin"
'Pushed
DrawTheme 2, 3, bounds(80 * 2, 130, 20, 20), "spin"
'Disabled
DrawTheme 2, 4, bounds(80 * 3, 130, 20, 20), "spin"
'Fucused
DrawTheme 2, 5, bounds(80 * 4, 130, 20, 20), "spin"
'progressbar
'Normal
DrawTheme 1, 0, bounds(80 * 0, 160, 150, 20), "progress"
DrawTheme 3, 0, bounds(80 * 2, 160, 150, 20), "progress"
'Vertical
DrawTheme 4, 0, bounds(80 * 0, 200, 20, 100), "progress"
DrawTheme 5, 0, bounds(80 * 2, 200, 20, 100), "progress"
'...
ReleaseDC Hwnd, hdc
End Sub |
Partager