在vb中怎么实现,拖动一个窗体时,另一个窗体也随之改变。类似于千千静听一样。
注:用windows api实现。
大侠们,帮帮忙。在此先谢过了

解决方案 »

  1.   


    Option Explicit
    Private Const HWND_TOPMOST = -1
    Private Const SWP_NOSIZE = &H1
    Private Const WM_SYSCOMMAND = &H112&
    Private Const SC_MOVE = &HF012&Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    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 LongPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Button = vbLeftButton Then
            Call ReleaseCapture
            SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0
            Form2.Left = Form1.Left
            Form2.Top = Form1.Top + Form1.Height + 5
        End If
    End Sub
    Private Sub Form_Load()
        Me.BorderStyle = 0
        Form2.Show
        Form2.BorderStyle = 0
        Form2.Left = Form1.Left
        Form2.Top = Form1.Top + Form1.Height + 5
    End Sub
      

  2.   

    如果桌面上有qq窗口(主窗口),和另一个窗口(我写的,副窗口)。当主窗口移动的时候,副窗口也一起移动,用windows api能实现吗
      

  3.   

    这个要用Hook⋯⋯
    呵呵
    我就是说说,我这里没存代码。
      

  4.   

    不用Hook就能实现,没有那么复杂,看看我在1楼给出的代码就是。
      

  5.   

    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long
     这俩是可以解决,看你怎么写了,首先要不停的判断那个所谓的QQ有没有移动
    然后 
       ReleaseCapture
       SendMessage hwnd, &HA1, 2, 0    '让被点中的(mousedown)窗口跟着鼠标移动的轨痕走
      

  6.   


    'form1代码
    Private Sub Form_Load()
            prevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
            SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
            Form2.Show
            
    End SubPrivate Sub Form_Unload(Cancel As Integer)
            SetWindowLong Me.hwnd, GWL_WNDPROC, prevWndProc
    End Sub
    ' ' '新建一个模块,代码如下: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
    Declare Function SetWindowLong Lib "user32 " Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Declare Function GetWindowLong Lib "user32 " Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPublic Const GWL_WNDPROC = (-4)
    Public Const WM_MOVE = &H3
    Public Const WM_SIZE = &H5Public prevWndProc As Long                   ' ' ' '默认窗口程序地址
    Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    On Error GoTo ShowErr
    ' ' ' ' ' '处理窗体移动的消息
           
            If Msg = WM_MOVE Or Msg = WM_SIZE Then
            ''''
               Form2.Move Form1.Left, Form1.Top + Form1.Height
            End If
           
    ' ' ' ' ' '
            WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
            Exit Function
    ShowErr:
            MsgBox Err.Source & "- " & Err.Description
    End Function