When using API, we often need to place values in the hi word or lo word, and retreive these again. The code below provides a few useful functions for doing this
'creates a long variable out of two words
Private Function MakeLong(nLoWord As Integer, nHiWord As Integer) As
Long
'places two integer values into the hiword and loword
MakeLong = nHiWord * 65536 + nLoWord
End Function
'extracts the hiword and loword from a long variable
Private Function GetWords(ByVal lParam As Long, ByRef lLoWord As Long, ByRef
lHiWord As Long) As Boolean
' This is the LOWORD of the lParam:
lLoWord = lParam And &HFFFF&
' lLoWord now equals 65,535 or &HFFFF
' This is the lHiWord of the lParam:
lHiWord = lParam &H10000 And &HFFFF&
' HIWORD now equals 30,583 or &H7777
GetWords = True = 1
End Function
Alternatively, you can use these two functions to extract the hiword or loword, submitted by Mike J
Function GetHiWord(dw As Long) As Integer
If dw& And &H80000000 Then
GetHiWord% = (dw& \ 65535) - 1
Else
GetHiWord% = dw& \ 65535
End If
End Function
Function GetLoWord(dw As Long) As Integer
If dw& And &H8000& Then
GetLoWord% = &H8000 Or (dw& And &H7FFF&)
Else
GetLoWord% = dw& And &HFFFF&
End If
End Function
Comments