Board index » cppbuilder » TImage OnMouseMove in a TScrollBox error

TImage OnMouseMove in a TScrollBox error


2008-02-23 03:41:49 AM
cppbuilder21
I have a TImage inside a TScrollBox. When the mouse
is moved over the TImage, the OnMouseMove code
displays the X and Y coordinates to the user in some
way. This works great until the image height or width is
greater than 32,767. After this the X or Y coordinate wraps
around to a negative number (IE. 32,767 + 1 = -32,768).
The image is 100 pixels wide by 40,000 pixels high. I
have done some searching on the internet and am unable
to determine where the bug is at (in the TImage
OnMouseMove or the TScrollBox)? I know that the size
of one of the variables in the calculation has to be smaller
than a 32bit int in order to wrap around like it does.
What can I do to get the accurate X and Y coordinates when
the X or Y is past 32,767?
Here is the sample code in the OnMouseMove:
void __fastcall TForm1::Image1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
Form1->Caption = IntToStr(Y) ; //works great inside
//scroll box until Y is greater than 32,767
}
I am using BCB C++ 4. Maybe this has been fixed in a later
version of BCB? Is there any way to work around this error
to get the correct coordinates?
 
 

Re:TImage OnMouseMove in a TScrollBox error

"ANTHONY WEST" < XXXX@XXXXX.COM >wrote in message
Quote
This works great until the image height or width is greater than 32,767.
The WM_MOUSEMOVE message only supports 16-bit coordinates to begin with.
Values greater than 32,767 require 32-bits parameters instead, which Windows
cannot give you.
Quote
I have done some searching on the internet and am unable
to determine where the bug is at
It is not a bug. Your image is simply too large for Windows to report
proper coordinates for once you go past 32,767 in either direction.
Quote
I know that the size of one of the variables in the calculation has
to be smaller than a 32bit int in order to wrap around like it does.
Correct. It is the original variables from the WM_MOUSEMOVE message itself
that are too small for your situation.
Quote
What can I do to get the accurate X and Y coordinates when
the X or Y is past 32,767?
You can try type-casting the parameters to "unsigned int". That should, at
least, allow you to get values up to 65,535. But beyond that, you will have
to ignore OnMouseMove's coordinates altogether and just calculate them
manually yourself instead.
Gambit
 

Re:TImage OnMouseMove in a TScrollBox error

Thank you Gambit! The type casting works great for
pictures below the height or width of an unsigned
short int. I can now double the size of my images.
You said below that I can calculate the
coordinates myself for larger images. Any hints on
how this can be done in a with the TImage inside
a TScrollBox?
Quote
But beyond that, you will have
to ignore OnMouseMove's coordinates altogether and just calculate them
manually yourself instead.
 

{smallsort}

Re:TImage OnMouseMove in a TScrollBox error

"ANTHONY WEST" < XXXX@XXXXX.COM >wrote in message
Quote
You said below that I can calculate the coordinates myself for
larger images. Any hints on how this can be done in a with the
TImage inside a TScrollBox?
Grab the mouse's current coordinates within the ScrollBox's client area, and
then adjust them according to how much the TScrollBox is currently scrolled
from side to side. TScrollBox has properties for that.
Gambit