📄 apiownerdrawitem.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ApiOwnerDrawItem"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Public Enum OwnerDrawItemTypes
ODT_BUTTON = 4
ODT_COMBOBOX = 3
ODT_LISTBOX = 2
ODT_MENU = 1
End Enum
Public Enum OwnerDrawItemActions
ODA_SELECT = &H2
ODA_FOCUS = &H4
ODA_DRAWENTIRE = &H1
End Enum
Public Enum OwnerDrawItemStates
ODS_CHECKED = &H8
ODS_DISABLED = &H4
ODS_FOCUS = &H10
ODS_GRAYED = &H2
ODS_SELECTED = &H1
'\\ Win NT4 +
ODS_DEFAULT = &H20
ODS_COMBOBOXEDIT = &H1000
'\\ Win2k +
ODS_HOTLIGHT = &H40
ODS_INACTIVE = &H80
End Enum
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type DRAWITEMSTRUCT
CtlType As Long
CtlID As Long
ItemId As Long
itemAction As Long
ItemState As Long
hwndItem As Long
hdc As Long
rcItem As RECT
itemData As Long
End Type
'\\ Private memory handling functions
Private Declare Sub CopyMemoryDRAWITEMSTRUCT Lib "kernel32" Alias "RtlMoveMemory" (Destination As DRAWITEMSTRUCT, ByVal Source As Long, ByVal Length As Long)
Private Declare Function IsBadReadPtrDRAWITEMSTRUCT Lib "kernel32" Alias "IsBadReadPtr" (ByVal lp As Long, ByVal ucb As Long) As Long
Private Declare Function IsBadWritePtrDRAWITEMSTRUCT Lib "kernel32" Alias "IsBadWritePtr" (ByVal lp As Long, ByVal ucb As Long) As Long
Private mRect As APIRect
Private mCtlType As OwnerDrawItemTypes
Public ControlId As Long
Public ItemId As Long
Public Action As OwnerDrawItemActions
Public ItemState As OwnerDrawItemStates
Private mHwnd As Long
Private mHdc As Long
Private CreatedOK As Boolean
Public Property Let ControlType(ByVal newControlType As OwnerDrawItemTypes)
mCtlType = newControlType
End Property
'\\ --[CreateFromPointer]---------------------------------------------
'\\ Fills this DRAWITEMSTRUCT object from the location poiunted to by
'\\ lpDRAWITEMSTRUCT
'\\ VB.NET Porting note: This function should be replaced with an override
'\\ of the New() for correctness
'\\ ----------------------------------------------------------------------------------------
'\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
'\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
'\\ ----------------------------------------------------------------------------------------
Public Function CreateFromPointer(lpDRAWITEMSTRUCT As Long) As Boolean
Dim ftThis As DRAWITEMSTRUCT
CreatedOK = False
If Not IsBadReadPtrDRAWITEMSTRUCT(lpDRAWITEMSTRUCT, Len(ftThis)) Then
Call CopyMemoryDRAWITEMSTRUCT(ftThis, lpDRAWITEMSTRUCT, Len(ftThis))
If Err.LastDllError = 0 Then
With ftThis
mCtlType = .CtlType
ControlId = .CtlID
ItemId = .ItemId
Action = .itemAction
ItemState = .ItemState
mHwnd = .hwndItem
mHdc = .hdc
If Err.LastDllError = 0 Then
CreatedOK = True
End If
End With
End If
End If
CreateFromPointer = CreatedOK
End Function
Public Property Get ControlType() As OwnerDrawItemTypes
ControlType = mCtlType
End Property
Public Property Get DeviceContext() As ApiDeviceContext
Dim tmpDC As ApiDeviceContext
Set tmpDC = New ApiDeviceContext
tmpDC.hdc = mHdc
Set DeviceContext = tmpDC
End Property
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -