Lock mouse to window corner

Started by
21 comments, last by kittycat768 15 years, 3 months ago
Quote:Original post by EasilyConfused
The default Windows behaviour is that the cursor keeps moving, even if the window is at its minimum or maximum size, but no longer stretches or shrinks the window.

I'd say this is the more desired behaviour. It is very rare that manually changing the cursor position improves user experience. Consistency is the most important thing in interfaces so I'd always suggest mimicking the way the OS behaves where possible.


You have to fight back against the default OS behavior in order to keep the window's aspect ratio. If you don't it looks really, really weird. I put in code that limits how fare each edge can go when the window reaches it's minimum size. I'm in the process of making my code less ugly. Windows may not like it, but the idea we're implementing is very nice looking in my opinion.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
Advertisement
Sounds like a job for ClipCursor.

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

Quote:Original post by ApochPiQ
Sounds like a job for ClipCursor.


Mmm... for me it's kind of the opposite. I don't confine the cursor to a rectangle. I try to keep it out of the rectangle that defines the window's minimum size. One major problem I'm running into is that the WM_SIZING message is getting called a bajillion times per second so when my window reaches it's minimum size the cursor sort of become trapped until I move the cursor a lot in one motion. I'm going to try to implement a timer in order to slow this down. If I can't slow it down I'm going to remove the code that limits the window's size. If the user wants a window that's 123 pixels by like 20 pixels, more power to them.

kittycat768 casts Xfer on ApochPiQ's Lobo avatar. ApochPiQ's Lobo avatar dies.

Edit: Acutally, I removed the "p.x = rcWnd.left" and "p.x = rcWnd.right" from my corner sections. It was an unnecessary bit of code that was causing the trapped cursor.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
Quote:Original post by kittycat768

Mmm... for me it's kind of the opposite. I don't confine the cursor to a rectangle. I try to keep it out of the rectangle that defines the window's minimum size. One major problem I'm running into is that the WM_SIZING message is getting called a bajillion times per second so when my window reaches it's minimum size the cursor sort of become trapped until I move the cursor a lot in one motion. I'm going to try to implement a timer in order to slow this down. If I can't slow it down I'm going to remove the code that limits the window's size. If the user wants a window that's 123 pixels by like 20 pixels, more power to them.

kittycat768 casts Xfer on ApochPiQ's Lobo avatar. ApochPiQ's Lobo avatar dies.

Edit: Acutally, I removed the "p.x = rcWnd.left" and "p.x = rcWnd.right" from my corner sections. It was an unnecessary bit of code that was causing the trapped cursor.


I thought about enforcing the cursor position at the time the subsequent message that is called after WM_SIZING, which I believe is WM_WINDOWPOSCHANGED or something similar. But I would have to store which window size the cursor was on and then calculate where to snap the cursor.
Quote:Original post by lordikon
Quote:Original post by kittycat768

Mmm... for me it's kind of the opposite. I don't confine the cursor to a rectangle. I try to keep it out of the rectangle that defines the window's minimum size. One major problem I'm running into is that the WM_SIZING message is getting called a bajillion times per second so when my window reaches it's minimum size the cursor sort of become trapped until I move the cursor a lot in one motion. I'm going to try to implement a timer in order to slow this down. If I can't slow it down I'm going to remove the code that limits the window's size. If the user wants a window that's 123 pixels by like 20 pixels, more power to them.

kittycat768 casts Xfer on ApochPiQ's Lobo avatar. ApochPiQ's Lobo avatar dies.

Edit: Acutally, I removed the "p.x = rcWnd.left" and "p.x = rcWnd.right" from my corner sections. It was an unnecessary bit of code that was causing the trapped cursor.


I thought about enforcing the cursor position at the time the subsequent message that is called after WM_SIZING, which I believe is WM_WINDOWPOSCHANGED or something similar. But I would have to store which window size the cursor was on and then calculate where to snap the cursor.


What does your program do differently that that makes it have to calculate all that stuff, or store it for that matter?

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
I haven't gotten around to messing with the cursor much. My first attempt a couple of days ago I got the cursor within about 1 pixel of where I needed it most of the time, but if I altered the position during the WM_SIZING message it would cause the cursor to move by about 1 pixel each time WM_SIZING would be called, which caused the window to move erratically.

So my thought was to not try and move the cursor during the sizing itself, but rather to let the sizing message finish, which would cause the window to resize, and then on whatever message came next I could then calculate where to place the cursor. However, once I get to the next message I would no longer have information about which corner/side the cursor was moving because that info is within WM_SIZING, so I'd have to store that info during WM_SIZING to use later.
Quote:Original post by lordikon
I haven't gotten around to messing with the cursor much. My first attempt a couple of days ago I got the cursor within about 1 pixel of where I needed it most of the time, but if I altered the position during the WM_SIZING message it would cause the cursor to move by about 1 pixel each time WM_SIZING would be called, which caused the window to move erratically.

So my thought was to not try and move the cursor during the sizing itself, but rather to let the sizing message finish, which would cause the window to resize, and then on whatever message came next I could then calculate where to place the cursor. However, once I get to the next message I would no longer have information about which corner/side the cursor was moving because that info is within WM_SIZING, so I'd have to store that info during WM_SIZING to use later.


I don't know what's causing that to happen. Are you literally snapping the cursor to the corners? (Which my code does)

GetCursorPos(&p);rcWnd -> left = p.x;rcWnd -> top  = p.y// Do stuffp.y = rcWnd -> top; // Update p.y because the top edge was scaled to fit the aspect ratioSetCursorPos(p.x, p.y);


I've absolutely perfected my code. I've been hacking away at it for about 6 hours and I don't think I could make it look any nicer. I wish I could offer better assistance. I think there's a miscommunication going on. I can't figure out what your program does that mine doesn't. I'm not saying mine's better. I just can't figure out exactly what you're trying to do. I'd also like to thank you for inspiring me to write my resizing code :)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
I was snapping it to the corner, or at least I thought so. I've honestly only spent a little time on the mouse cursor issue among other things, chances are my calculations may be off by 1 pixel or so somewhere and it might be causing the strange behavior.

This is a work project, and I just got moved to another system so I may not get to solve the cursor issue for a little while.
Quote:Original post by lordikon
I was snapping it to the corner, or at least I thought so. I've honestly only spent a little time on the mouse cursor issue among other things, chances are my calculations may be off by 1 pixel or so somewhere and it might be causing the strange behavior.

This is a work project, and I just got moved to another system so I may not get to solve the cursor issue for a little while.


Would you mind cutting and pasting your entire WM_SIZING message into your post. If I saw what your <do stuff> comments actually did it might help. err... your up-to-date code. I can clearly see that your previous code post just changes the window's aspect ratio and such.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------I once read that World of Warcraft is poor fishing simulator. I don't know about you but I catch a lot more fish in World of Warcraft than I do in real life.
Because it is code from work I cannot copy and paste it, and I'm not currently at work so I don't have the code in front of me anyhow.

Which comments do you mean, the only stuff I think I left out what the corner sizing. For the corner sizing if the user has resized the window more horizontally then I treat the movement the same as I would if they were dragging the the right or left, and so I adjust the width, otherwise I adjust the height.

This topic is closed to new replies.

Advertisement