When processing some windows messages (ie. WM_LBUTTONDOWN) which pass both the X and Y coordinates of the mouse cursor in the lParam value, you have to extract the X and Y coordinates from a single Long value.
The MS docs say to use HIWRD and LOWRD to extract each value. The problem with this is that the HIWRD and LOWRD functions in PB do not return negative values. The value will always be a positive value, even if the bit that defines a negative value (in an Integer) is set.
While in most instances this doesn't cause a problem, there are some instances that you will need to return a negative value.
For example, when a window captures the mouse, it is possible to get a negative value back for a coordinate when processing a message like WM_LBUTTONDOWN. Using LOWRD and HIWRD to extract a negative value from lParam, will produce an error in your program, since you can't get a negative value back.
Here are some "replacement" functions for LOWRD and HIWRD which will return a negative value when it exists:
If you know that you may get a negative value when extracting a Integer (Low word or high word) from a Long, then use the functions above instead of LOWRD and HIWRD.
[This message has been edited by Chris Boss (edited May 19, 2000).]
The MS docs say to use HIWRD and LOWRD to extract each value. The problem with this is that the HIWRD and LOWRD functions in PB do not return negative values. The value will always be a positive value, even if the bit that defines a negative value (in an Integer) is set.
While in most instances this doesn't cause a problem, there are some instances that you will need to return a negative value.
For example, when a window captures the mouse, it is possible to get a negative value back for a coordinate when processing a message like WM_LBUTTONDOWN. Using LOWRD and HIWRD to extract a negative value from lParam, will produce an error in your program, since you can't get a negative value back.
Here are some "replacement" functions for LOWRD and HIWRD which will return a negative value when it exists:
Code:
FUNCTION NLOWRD(BYVAL L AS LONG) AS LONG LOCAL IP AS INTEGER PTR, I AS INTEGER IP=VARPTR(L) I=@IP FUNCTION=I END FUNCTION ' ' ----------------------------------------- ' FUNCTION NHIWRD(BYVAL L AS LONG) AS LONG LOCAL IP AS INTEGER PTR, I AS INTEGER IP=VARPTR(L)+2 I=@IP FUNCTION=I END FUNCTION
[This message has been edited by Chris Boss (edited May 19, 2000).]
Comment