Constraining window position to desktop working area

Posted by simplecoder on Stack Overflow See other posts from Stack Overflow or by simplecoder
Published on 2010-03-09T01:59:53Z Indexed on 2010/03/09 2:21 UTC
Read the original article Hit count: 321

Filed under:
|
|
|
|

I want to allow a user to drag my Win32 window around only inside the working area of the desktop. In other words, they shouldn't be able to have any part of the window extend outside the monitor(s) nor should the window overlap the taskbar.

I'd like to do it in a way that does cause any stuttering. Handling WM_MOVE messages and calling MoveWindow() to reposition the window if it goes off works, but I don't like the flickering effect that's caused by MoveWindow().

I also tried handling WM_MOVING which prevents the need to call MoveWindow() by altering the destination rectangle before the move actually happens. This resolves the flickering problem, but another issue I run into is that the cursor some times gets aways from the window when a drag occurs allowing the user to drag the window around while the cursor is not even inside the window.

How do I constrain my window without running into these issues?

© Stack Overflow or respective owner

Related posts about c++

Related posts about win32