Results 1 to 3 of 3

Thread: Form draging

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301
    Does anyone know how to raise an event everytime a form is dragged and dropped?


  2. #2
    Guest
    You can subclass it.

    Code for a 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)
    Private Const WM_EXITSIZEMOVE = &H232
    Private Const WM_MOVING = &H216
    Private Const HTCAPTION = 2
    Private Const WM_NCLBUTTONDOWN = &HA1
    
    Public 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_NCLBUTTONDOWN And wParam = HTCAPTION Then
            Form1.Cls
            Form1.Print "The form is beginning to move"
        End If
        
        If wMsg = WM_EXITSIZEMOVE Then
            Form1.Cls
            Form1.Print "The form has stopped moving"
        End If
        
        If wMsg = WM_MOVING Then
            Form1.Cls
            Form1.Print "The 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
    Code for a Form
    Code:
    Private Sub Form_Load()
        SubClassWnd hwnd
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubclassWnd hwnd
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301
    Cheers Megatron,

    I gave this a go but the Sub UnSubclassWnd(hwnd As Long)function causes VB to crash. I`ve done it another way now using a image as the pickup (drag) point instead of the title bar. (then used mouse_move and mouseup)


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