In a view of my MFC application, I can select certain rectangular area with click & drag. But when user wants to select larger area than current screen, he can’t do that because the view does not automatically scroll when mouse pointer is near bound of the client area.
How can I resolve this problem? Any reference would suffice.
Normally you only do this when the user has the mouse button held down. That being the case, you normally want to capture the mouse when the click. You’ll then handle
WM_MOUSEMOVEmessages. In your case, you’ll compare the current position of the mouse to the border of your window, and when it gets close enough (e.g., within 10 pixels) you start to scroll in that position.I feel obliged to add that I’d control scrolling speed pretty carefully when you do this — some programs scroll so far so fast that this becomes nearly unusable, because the moment you’ve gotten close to the edge of the window, you’ve already scrolled way past where you intended. Others tend toward the opposite: no matter what you do, they scroll so slowly that moving even a short distance seems like it takes forever.
I doubt there’s an easy answer to getting the “right” speed. You do generally want a gradient, so as they get sort of close to the border, it scrolls slowly, and as they get closer, the scrolling gets faster. You still need to be fairly careful about the upper and lower bounds of that though, so they get a reasonable range of speeds, not just jumping from “oh, am I ever going to get there”, directly to “whoa, back up, that’s way too far already!”.