Click to See Complete Forum and Search --> : How can I know when my form's position changes?


Jean Spector
January 5th, 2000, 11:03 AM
How can I know when my form's position changes?
I mean user drags my window and drops it somewhere? Is there an API function that can detect pos change and report or I have to set timer and compare coordinates?
Any help on the issue will be appreciated ( the phrase becomes so ... boring? )


Jean Spector
Tech Support Team Leader, CET
mage@lycosmail.com
(in VB from 11/1999)

Waseem Sadiq
January 5th, 2000, 03:29 PM
You could try to capture a mousedrag event and then look if the coordinates have changed (using form1.top and form1.left) If you need a code-sample reply to this message or mail me at sadiq@quicknet.nl and I'll see if I can set something up for you.
This is my first reply ever, if i did help, let me know (feels good).

Richard Barnes
January 5th, 2000, 05:25 PM
A simple way to do this would be to use the GetWindowRect API (Declare Function GetWindowRect Lib "USER32" (ByVal hwnd As Long, lprc As RECT) As Long) By passing the Hwnd of the window it will give you the rect region of the window. You could store these positions and then check for a change. You will also need the RECT type from the API manager. Email if you need hand at cmc@coynet.com.

Sample:

Put this in a Module in the Declerations


Type RECT
Left as Long
Top as Long
Right as Long
Bottom as Long
End Type

Declare Function GetWindowRect Lib "USER32" (byval hwnd as Long, lprc as RECT) as Long




put a timer on a form and add set the interval to 2000. add this code to the timer event

Dim NewRect as RECT
Dim ReturnVal as Long
ReturnVal = GetWindowRect(Form1.hwnd, NewRect)
Debug.print "______________________________________"
Debug.print "Left = " & NewRect.Left
Debug.print "Right = " & NewRect.Right
Debug.print "Top = " & NewRect.Top
Debug.print "Bottom = " & NewRect.Bottom
Debug.print




Every 2 seconds the window position will be printed to the debug window.
This also has the ability to determine a resize as well, for if they drag the form larger (or smaller) the rect.right number will grow larger. you could use this to make forms that grow larger and not smaller or to check if the window position is of a border of the screen (- number)

Hope this helps



Richard Barnes
Lead Design Scientist
Coynet International/Public Access Technologies

Chris Eastwood
January 6th, 2000, 02:41 AM
The best (well, windows/c) way of doing this is to subclass your form and look for the WM_WINDOWPOSCHANGING and WM_EXITSIZEMOVE messages - these will let you know when your window is being dragged (and you can capture WM_MOVE for that also) and when it is dropped.

There's a good example that comes with the free subclassing control from SoftCircuits (an lot's of other good subclassing examples).

You can visit the SoftCircuits site at http://www.softcircuits.com and download the subclassing control (with source code) from their VB Samples page at : http://www.softcircuits.com/sw_vbsrc.htm


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Jean Spector
January 6th, 2000, 09:03 AM
Thank you all, I'll try all the suggestions in case I'll succeed you'll know it. 10x again.

Jean Spector
Tech Support Team Leader, CET
mage@lycosmail.com
(in VB from 11/1999)

vhtml
February 24th, 2000, 02:25 PM
Hello! (c:
You need to subclass the form you're on and look for the WM_WINDOWPOSCHANGING message. That should do the trick! (c: VB itself doesn't provide methods to tell when a form is moving unfortunately. Subclassing is the only effective and efficient way to do it. You can find resources on the 'Net for subclassing if you don't know what I'm talking about. Hope I could help! (c: Have a great day! Bye! (c:

Sincerely,
- David Hoyt -
We're currently looking for any programmer who wants to join our programming team. Please check out the website for more information. Feel free to e-mail me at vhtml@hotmail.com to apply. We're working on an HTML Editor, Visual HTML. Thanks for your interest! (c: