Results 1 to 6 of 6

Thread: Moving a form hasn't a colored top-titeled

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Location
    egypt
    Posts
    25

    Talking

    I need to move my form as follow
    i mouse_down any point on the form then move the mouse then mouse_up after that the form is being moved

    or any other ,all i need to move a form has no title( the most upper in the form )
    and thank you

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Cool Here's how.

    Here, try this:
    Code:
    Option Explicit
    
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Call ReleaseCapture
        Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0)
    End Sub

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Use SendMessage to send the WM_NCLBUTTONDOWN in the HTCAPTION area.
    Code:
    Private Declare Function SendMessage _
     Lib "user32" Alias "SendMessageA" ( _
     ByVal hwnd As Long, _
     ByVal wMsg As Long, _
     ByVal wParam As Long, _
     lParam As Any) As Long
    
    Private Declare Function ReleaseCapture _
     Lib "user32" () As Long
    
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If (Button And vbLeftButton) = vbLeftButton Then
            ReleaseCapture
            SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
        End If
    End Sub
    Good luck!

  4. #4
    Guest
    Here is how to move a form with no caption without api:

    Code:
    Dim oldX As Long, oldY As Long, isMoving As Boolean
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    oldX = X
    oldY = Y
    isMoving = True
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If isMoving Then
        Me.Top = Me.Top - (oldY - Y)
        Me.Left = Me.Left - (oldX - X)
    End If
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    isMoving = False
    End Sub

  5. #5
    Guest
    An API method, except it uses WM_SYSCOMMAND instead.
    Code:
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const SC_MOVEEX = &HF012
    Const WM_SYSCOMMAND = &H112
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then
            ReleaseCapture
            SendMessage hwnd, WM_SYSCOMMAND, SC_MOVEEX, 0
        End If
    End Sub

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Sorry Megatron!
    Did you ever tried that code? It doesn't work on my WinNT machine anyway.

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