WM_MOUSEMOVING ??

Started by
12 comments, last by Kincaid 14 years, 10 months ago
Hello, I need the mouse to stay within a (rectangle) window. I do this by catching WM_MOUSEMOVE, and checking the position. if outside, I simply set it back inside. However, ideally I would like to catch this message earlier, before the mouse actually moves. like WM_WINDOWPOSCHANGING, where you can check to coordinates before actually moving there. There is no WM_MOUSEMOVING, but something like that maybe ?? The way it is has the drawback of 'jerkiness' in the mouse on borders (jumping back to the region), which I would like to get rid of. thanx in advance.
Advertisement
Try ClipCursor() instead, it does exactly what you want.

http://msdn.microsoft.com/en-us/library/ms648383(VS.85).aspx
Thanx
Though it fixes my problem only halfway :)
The cursor stays neatly inside my rectangle, but I also dont receive any coordinates outside that.

I want to 'scroll' my view by 'bumping' at the edges of the screen with the mouse (like some strategy games have)
So I would like to register a move e.g. [-3, 0] (outside the rectangle) so I know I should scroll -3 over the 'x-axis', but then not project the mouse outside it.

ClipCursor also alters the value to the corrected position being 0 instead of -3.
Make the rectangle you pass to ClipCursor slightly bigger than it needs to be (10 pixels on each side should work well). Then just check if you are inside that "border" zone when getting the cursor position, and you have all you need for scrolling [smile]

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

yes, and i have considered that, though picky as I am :), thats not what I want.
Its fine and works great, but it would be a border-zone in which the camera starts scrolling when the mouse is there (basically like a button around the screen).
I would like to have the user explicitly (while pressing the right mouse button) scroll against the sides, and only when he keeps moving 'outside' pan camera. the real 'bump-scroll' version of it.
(as I mentoined, just as with the POSCHANGING message, I really need the actual coordinates, but then have ability to alter those to utlimatly position the mouse)
thanx though.
Do you want the scroll speed to be determined by the distance the mouse is moved outside the view? i.e. You say that if the mouse is at [-3, 0] relative to the window/view/rectangle then it should scroll 3 pixels to the left, so i assume you mean that if the mouse was further out then it will scroll more.
Have you tried using SetCapture with ClipCursor? That may solve the problem of having the coords also clipped. I think that only works when the mouse button is pressed but you said that you only want it to scroll when the button is pressed so that should be ok
[Window Detective] - Windows UI spy utility for programmers
yes exactly, the more/faster you move outside / bump at the side, the more/faster it should scroll.
(giving the user an intuitive way the pan the view over the map in a controlled manner)

I use SetCapture all over the place, and you're suggesting that when ClipCursor is active, AND the window also has the capture, then the coordinates passed to lParam of WM_MOUSEMOVE are not clipped (but normal/usual) ?
(i dont see why the mousebutton should have to pressed though ..)

This sounds exactly right/what I need, and Ill try that asap

thanx

edit:
I have tried it (had it captured to begin with) but it seems that ClipCursor clips the coordinates and then hands them off to the message... :(

any more suggestions ?
When my mouse at the border, e.g. the left side (x=0), and I scroll further to the left, when ClipCursor is enabled, no mousemoves are generated.
But I must have that information

So I guess clipcursor wont do it :(

So it looks like I have ot use SetCursor (like I did), simply putting the cursor back in his place after he has crossed the border...

It seems to be the only (& ugly) way for it work like I described..

thnx
The easy solution would be to set a flag when the mouse moves into the "scroll region." When this flag is active, you grab the mouse cursor position via GetCursorPos each frame, and use that position to decide how much to scroll. If that position is outside the hot zone, you clear the flag, and proceed as normal.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I hate applications that hijack my cursor. It's mine - I paid for it, leave it alone.

This topic is closed to new replies.

Advertisement