CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 1999
    Location
    Tel Aviv, Israel, Earth, Solar System
    Posts
    50

    How can I know when my form's position changes?

    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
    [email protected]
    (in VB from 11/1999)

  2. #2
    Join Date
    Oct 1999
    Location
    Holland
    Posts
    34

    Re: How can I know when my form's position changes?

    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 [email protected] 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).


  3. #3
    Join Date
    Jan 2000
    Location
    Yellowknifw, NT
    Posts
    5

    Re: How can I know when my form's position changes?

    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 [email protected].

    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

  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How can I know when my form's position changes?

    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

  5. #5
    Join Date
    Dec 1999
    Location
    Tel Aviv, Israel, Earth, Solar System
    Posts
    50

    Re: How can I know when my form's position changes?

    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
    [email protected]
    (in VB from 11/1999)

  6. #6
    Join Date
    Dec 1999
    Location
    CA and UT
    Posts
    5

    Re: How can I know when my form's position changes?

    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 [email protected] to apply. We're working on an HTML Editor, Visual HTML. Thanks for your interest! (c:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured