 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
JD Guest
|
Posted: Sun Apr 23, 2006 2:03 pm Post subject: WM_MOUSEMOVE and OnMouseMove |
|
|
I was getting some strange behavior when processing WM_MOUSEMOVE
and traced it back to how I was interpreting X,Y. The points
are passed in the message as words:
if( Message.Msg == WM_MOUSEMOVE )
{
HeaderMouseMove( KeysToShiftState(Message.WParam), LOWORD(Message.LParam), HIWORD(Message.LParam) );
}
and then interpreted as ints in the handler:
void __fastcall TMyListView::HeaderMouseMove( TShiftState Shift, int X, int Y );
The problem was that negative numbers in a WORD just become
large number in the ints and I'm looking for an eligant way
of not loosing the sign.
~ JD |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Sun Apr 23, 2006 8:03 pm Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
JD wrote:
| Quote: | I was getting some strange behavior when processing WM_MOUSEMOVE
and traced it back to how I was interpreting X,Y. The points
are passed in the message as words:
HeaderMouseMove( KeysToShiftState(Message.WParam), LOWORD(Message.LParam), HIWORD(Message.LParam) );
and then interpreted as ints in the handler:
void __fastcall TMyListView::HeaderMouseMove( TShiftState Shift, int X, int Y );
The problem was that negative numbers in a WORD just become
large number in the ints and I'm looking for an eligant way
of not loosing the sign.
|
Convert to shorts:
MAKEPOINTS( Message.LParam ).x
MAKEPOINTS( Message.LParam ).y |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Sun Apr 23, 2006 8:03 pm Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
Bob Gonder wrote:
| Quote: | Convert to shorts:
MAKEPOINTS( Message.LParam ).x
MAKEPOINTS( Message.LParam ).y
|
Wait, that makes pointers, better use
MAKEPOINTS( Message.LParam )->x |
|
| Back to top |
|
 |
JD Guest
|
Posted: Mon Apr 24, 2006 6:03 am Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
Bob Gonder <notbg (AT) notmindspring (DOT) invalid> wrote:
| Quote: |
Convert to shorts:
|
That's what I did to solve the problem but I did it a bit
differently.
| Quote: | HeaderMouseMove( KeysToShiftState(Message.WParam), LOWORD(Message.LParam), HIWORD(Message.LParam) );
|
I left that the same ....
| Quote: | void __fastcall TMyListView::HeaderMouseMove( TShiftState Shift, int X, int Y );
|
and Changed that to ...( ... short X, short Y ); but I was
wondering how the VCL does it because it gets X,Y just like
I'm getting them and they're passed to the event as ints
just like I was doing it.
~ JD |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Mon Apr 24, 2006 7:03 am Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
JD wrote:
| Quote: |
and Changed that to ...( ... short X, short Y ); but I was
wondering how the VCL does it because it gets X,Y just like
I'm getting them and they're passed to the event as ints
just like I was doing it.
|
Maybe they don't process negative values (mouse outside the client
window) ?
MSDN:
"The WM_MOUSEMOVE message is posted to a window when the cursor moves.
If the mouse is not captured, the message is posted to the window that
contains the cursor. Otherwise, the message is posted to the window
that has captured the mouse."
Since most windows likely don't capture the mouse, they would only get
positive values, and the LOWORD to int conversion would be correct.
(or perhaps you are looking at 16 bit code examples?) |
|
| Back to top |
|
 |
JD Guest
|
Posted: Mon Apr 24, 2006 9:03 am Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
Bob Gonder <notbg (AT) notmindspring (DOT) invalid> wrote:
| Quote: |
[...] they would only get positive values, and the LOWORD to
int conversion would be correct.
|
Ok ... you got me. I failed to say that the mouse was captured
because a mouse button was down. The event with ints worked
fine untill I moved out of the control up and/or to the left
and then the fun began.
~ JD |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Apr 24, 2006 8:03 pm Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
"Bob Gonder" <notbg (AT) notmindspring (DOT) invalid> wrote in message
news:vrcn42l1hnspdob90kmpqeei06cssbokme (AT) 4ax (DOT) com...
| Quote: | Wait, that makes pointers, better use
MAKEPOINTS( Message.LParam )->x
|
No it doesn't. MAKEPOINTS returns a POINTS structure by value, not a
pointer to one. Your original use of the '.' operator instead of the '->'
operator was correct.
Gambit |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Apr 24, 2006 8:03 pm Post subject: Re: WM_MOUSEMOVE and OnMouseMove |
|
|
"JD" <nospam (AT) nospam (DOT) com> wrote in message
news:444c5cfe$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I was wondering how the VCL does it
|
I guess you didn't try looking at the VCL source code yet.
| Quote: | it gets X,Y just like I'm getting them
|
No, it is not. You are using the LO/HIWORD macros. The VCL does not do
that.
| Quote: | they're passed to the event as ints just like I was doing it.
|
The VCL is retrieving the values as signed shorts to begin with, but your
code is retreiving them as unsigned shorts instead. A signed short passed
to a signed int parameter will preserve the sign. Passing an unsigned short
to a signed int parameter will not preserve the sign for negative values.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|