Option ExplicitPublic BitPosMask(0 To 31) As Long
Public BitMapMask(0 To 31) As LongPrivate m_Inited As BooleanPublic Property Get Inited() As Boolean
Inited = m_Inited
End PropertyPublic Function Init() As Boolean
If m_Inited Then Exit Function
Dim I As Long
For I = 0 To 30
BitPosMask(I) = 2& ^ I
Next I
BitPosMask(31) = &H80000000
For I = 0 To 7
BitMapMask(I) = BitPosMask(7 - I)
Next I
For I = 8 To &HF
BitMapMask(I) = BitPosMask(&HF - I + 8)
Next I
For I = &H10 To &H17
BitMapMask(I) = BitPosMask(&H17 - I + &H10)
Next I
For I = &H18 To &H1F
BitMapMask(I) = BitPosMask(&H1F - I + &H18)
Next I
m_Inited = True
Init = True
End Function'################################################Public Property Get LoWord(ByRef dword As Long) As Integer
LoWord = (dword And &H7FFF&) Or (((dword And &H8000&) <> 0) And &H8000)
End PropertyPublic Property Get HiWord(ByRef dword As Long) As Integer
HiWord = ((dword And &H7FFF0000) \ &H10000) Or (((dword And &H80000000) <> 0) And &H8000)
End PropertyPublic Property Let LoWord(ByRef dword As Long, ByVal vData As Integer)
dword = (dword And &HFFFF0000) Or (vData And &H7FFF) Or (((vData And &H8000) <> 0) And &H8000&)
End PropertyPublic Property Let HiWord(ByRef dword As Long, ByVal vData As Integer)
dword = (dword And &HFFFF&) Or ((vData And &H7FFF) * &H10000) Or (((vData And &H8000) <> 0) And &H80000000)
End PropertyPublic Function MakeDWord(ByVal HiWord As Integer, ByVal LoWord As Integer) As Long
MakeDWord = ((HiWord And &H7FFF) * &H10000 Or (((HiWord And &H8000) <> 0) And &H80000000)) _
Or ((LoWord And &H7FFF) Or (((LoWord And &H8000) <> 0) And &H8000&))
End FunctionPublic Function MAKELPARAM(ByVal l As Integer, ByVal H As Integer) As Long
MAKELPARAM = MakeDWord(H, l)
End Function'DWORD MAKELONG(
' WORD wLow, // low-order word of long value
' WORD wHigh // high-order word of long value
');
Public Function MAKELONG(ByVal wLow As Integer, ByVal wHigh As Integer) As Long
MAKELONG = MakeDWord(wHigh, wLow)
End Function'################################################Public Property Get LoByte(ByRef Word As Integer) As Byte
LoByte = Word And &HFF
End PropertyPublic Property Get HiByte(ByRef Word As Integer) As Byte
HiByte = ((Word And &H7F00) \ &H100) Or (((Word And &H8000) <> 0) And &H80)
End PropertyPublic Property Let LoByte(ByRef Word As Integer, ByVal vData As Byte)
Word = (Word And &HFF00) Or vData
End PropertyPublic Property Let HiByte(ByRef Word As Integer, ByVal vData As Byte)
Word = (Word And &HFF) Or ((vData And &H7F) * &H100) Or (((vData And &H80) <> 0) And &H8000)
End PropertyPublic Function MakeWord(ByVal HiByte As Byte, ByVal LoByte As Byte) As Integer
MakeWord = ((HiByte And &H7F) * &H100 Or (((HiByte And &H80) <> 0) And &H8000)) Or LoByte
End Function'################################################Public Property Get ColorR(ByRef Color As Long) As Byte
ColorR = Color And &HFF
End PropertyPublic Property Get ColorG(ByRef Color As Long) As Byte
ColorG = (Color And &HFF00&) \ &H100&
End PropertyPublic Property Get ColorB(ByRef Color As Long) As Byte
ColorB = (Color And &HFF0000) \ &H10000
End PropertyPublic Property Get ColorA(ByRef Color As Long) As Byte
ColorA = ((Color And &H7F000000) \ &H1000000) Or (((Color And &H80000000) <> 0) And &H80)
End PropertyPublic Property Let ColorR(ByRef Color As Long, ByVal vData As Byte)
Color = (Color And &HFFFFFF00) Or vData
End PropertyPublic Property Let ColorG(ByRef Color As Long, ByVal vData As Byte)
Color = (Color And &HFFFF00FF) Or (vData * &H100&)
End PropertyPublic Property Let ColorB(ByRef Color As Long, ByVal vData As Byte)
Color = (Color And &HFF00FFFF) Or (vData * &H10000)
End PropertyPublic Property Let ColorA(ByRef Color As Long, ByVal vData As Byte)
Color = (Color And &HFFFFFF) Or ((vData And &H7F) * &H1000000) Or (((vData And &H80) <> 0) And &H80000000)
End PropertyPublic Function RGBA(ByVal Red As Byte, ByVal Green As Byte, ByVal Blue As Byte, ByVal Alpha As Byte) As Long
RGBA = Red Or Green * &H100& Or Blue * &H10000 Or ((Alpha And &H7F) * &H1000000 Or (((Alpha And &H80) <> 0) And &H80000000))
End Function
既可以取得,又可以设置Dim c as Long
c=&H123456
debug.print Hex(c) & ":" & ColorR(c) & "," & ColorG(c) & "," & ColorB(c)
ColorR(c)=&HFF '注意
debug.print Hex(c) & ":" & ColorR(c) & "," & ColorG(c) & "," & ColorB(c)
-----------------------------------
LoWord就是实现VC的LOWORD宏的功能至于为什么要And &H7FFF0000
这是由于VB的整形是带符号的
个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/
------------------------------------------------------------------