Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent a form being dragged too left or too far

Status
Not open for further replies.

tarang2969

IS-IT--Management
Aug 25, 2006
1
0
0
US
Hi,
I have a VB6 application and I am having users to drag the windows to a 2nd monitor. How can i check if they have dragged the window too left or too right, so that i can restrict them within the screen space.

I can use the form_mousemove or form_mousedown event but these events wont fire-up if using the title bar of the window.

Any help is appreciated.

 
One way is to subclass the form, capture the WM_MOVE message and then modify it's behaviour.

thread222-494440 shows how to subclass a window (for a slightly different purpose) and so should give you a good starting point.

You'll need to look up and define in your project the value of WM_MOVE (Use the API viewer). Also worth checking the definition of WM_MOVE and WM_GETMINMAXINFO in MSDN, which should give more background. (they are defined in C/C++ syntax, but the notes are still valid)

Having captured the message, you depending on how you want the limit to behave (probably just not move any further rather than return to original position), you will need to compare the X and Y values against appropriate limits, if greater then set the X & Y values to the limits.

I'd recommend caution when subclassing windows, it can result in messy crashes of the IDE, if you don't unhook the window before ending the project, so... I do the following
ensure you have a good backup of your project, ensure that you do not use the stop button on the IDE to stop your program and ensure that you do not use the END command anywhere in your code.

Good luck

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top