Article ID: 189170
Article Last Modified on 7/1/2004
Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
Only a few API functions require that you unpack a double word into two
short Integers. If you find that you need to perform such a task, you can
use conversion routines similar to these:
Function LoWord(DWord As Long) As Integer
If DWord And &H8000& Then ' &H8000& = &H00008000
LoWord = DWord Or &HFFFF0000
Else
LoWord = DWord And &HFFFF&
End If
End Function
Function HiWord(DWord As Long) As Integer
HiWord = (DWord And &HFFFF0000) \ &H10000
End Function
Both these functions simply mask the portion of the Long integer they want
to return using the bitwise "And" operator. The HiWord function shifts this
value right 16-bits by dividing it by &H10000. The LoWord function can
simply return the value of the "And" operation in most cases. However,
because Visual Basic Integers are signed, any low word value that has its
high bit set must be converted back into a negative value using the "Or"
operator and a mask of &HFFFF0000.
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const MK_LBUTTON = &H1
Private Const WM_LBUTTONDOWN = &H201
Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Form1.Cls
Form1.Print "Button Click Event Fired"
Form1.Print "Position X:" & Str$(X / Screen.TwipsPerPixelX)
Form1.Print "Position Y:" & Str$(Y / Screen.TwipsPerPixelY)
End Sub
Private Sub Command1_Click()
Dim nMousePosition As Long
' nMousePosition stores the x (hiword) and y (loword) values
' of the mouse cursor as measured in pixels.
Let nMousePosition = MakeDWord(16, 18)
Call SendMessage(Me.hwnd, WM_LBUTTONDOWN, MK_LBUTTON, _
nMousePosition)
End Sub
112651 How To Mimic HIWORD, LOWORD, HIBYTE, LOBYTE C Macros in VB
Additional query words: kbDSupport kbDSD kbVBp kbVBp500 kbAPI kbSDKWin32 kbVBp600
Keywords: kbhowto KB189170