Results 1 to 3 of 3

Thread: form move

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Willow Spring, NC, USA
    Posts
    7

    Question

    How can I set something to be changed whenever the form is moved?
    thanks in advance
    -Rog

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Put a timer on the form, set its Interval property to something small, and include this code in your form:
    Code:
    Option Explicit
    
    Private mlngStartLeft As Long
    Private mlngStartTop As Long
    
    Private Sub Form_Load()
    
        mlngStartLeft = Me.Left
        mlngStartTop = Me.Top
        
    End Sub
    
    
    Private Sub Timer1_Timer()
    
        
        If Me.Left <> mlngStartLeft Or _
           Me.Top <> mlngStartTop Then
            ' Put code to set whatever you want here
            mlngStartLeft = Me.Left
            mlngStartTop = Me.Top
        End If
        
    End Sub

  3. #3
    Guest
    This code, from Megatron, may be better for going about to detect when yoru form is being moved.

    Code:
    'Module code:
    
    Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const GWL_WNDPROC = (-4)
    Const WM_MOVE = &H3
    Const WM_EXITSIZEMOVE = &H232
     
    Global WndProcOld As Long
    
    Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
        If wMsg = WM_EXITSIZEMOVE Then
            'The Form has finished moving
            MsgBox ("Form1 has been moved")
        End If
        
        If wMsg = WM_MOVE Then
            'The Form is moving
            Form1.Print "Form is moving"
        End If
        
        WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
        
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
        WndProcOld& = 0
    End Sub
    
    
    'Form code:
    
    Private Sub Form_Load()
        SubClassWnd Me.hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd Me.hwnd
    End Sub

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