I wrote a control in which I overrode WndProc to implement a custom
MouseMove. I caught the MouseMove message and passed it to a function which
raises a custom event. In this function I get the x and y from the LParam of
the message; x being the low order word, y being the high order word. I use
two functions to get the LoWord and HiWord from the LParam
Private Shared Function HiWord(ByVal Number As Integer) As Integer
Return ((Number >> 16) And &HFFFF)
End Function
Private Shared Function LoWord(ByVal Number As Integer) As Integer
Return (Number And &HFFFF)
End Function
This gets me x and y correctly except when x or y is negative.
Example:
LParam.ToInt32: 5636101 (&H00560005)
x: 5 (&H0005)
y: 86 (&H0056)
LParam.ToInt32: 5636100 (&H00560004)
x: 4 (&H0004)
y: 86 (&H0056)
LParam.ToInt32: 5636099 (&H00560003)
x: 3 (&H0003)
y: 86 (&H0056)
LParam.ToInt32: 5570562 (&H00550002)
x: 2 (&H0002)
y: 85 (&H0055)
LParam.ToInt32: 5570561 (&H00550001)
x: 1 (&H0001)
y: 85 (&H0055)
LParam.ToInt32: 5570560 (&H00550000)
x: 0 (&H0000)
y: 85 (&H0055)
LParam.ToInt32: 5636095(&H0055F FFF)
x: 65535 (&HFFFF) <-- This should be -1!!!!
y: 85 (&H0055)
If this were VB6, &HFFFF would produce -1 and &HFFFF& would produce 65535.
In VB.Net &HFFFF and &HFFFF& are the same, both producing 65535. Negative 1
is represented by &HFFFFFFFF. How can I make my calculation aware that
&HFFFF is like vb6, using a 2-byte integer instead of a 4-byte integer.
By the way, I used Lutz Roeder's Reflector to see how Controls handle this
by default. I understand that it is not a perfect decompiler already,
because it works backwards from MSIL. It would seem that Controls get x and
y like this:
x = CType(m.LParam. ToInt32, Short)
y = (m.LParam.ToInt 32) >> 16)
If I were to try this, I would get an OverflowExcepti on when LParam.ToInt32
equaled 5636095 (way more than a Short can hold)
How can I extract x and y properly?
--
Any help is appreciated.
Thanks in advance.
Hong Kong Phooey