在vb中如何精确同步移动多个窗体??

我在搞玻璃窗体,但是要用两个窗体显示内容,如何调用windowsAPI实现多个窗体的同步移动?... 我在搞玻璃窗体,但是要用两个窗体显示内容,如何调用windows API实现多个窗体的同步移动? 展开
 我来答
尘入蜓孟影食1038
2010-01-08 · TA获得超过3512个赞
知道大有可为答主
回答量:2307
采纳率:87%
帮助的人:1348万
展开全部
我做了几行。
对无标题栏的窗体,或者不从标题栏移动的情况下可用。
有标题栏并且点住标题栏移动则不理想。
代码如下,仅供参考。

1、建立模块。
Option Explicit

Public Oldproc As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Public Const WM_MOVE = &H3
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const GWL_WNDPROC = (-4)
Public BnHwnd As Long

Public Function Newproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
If Msg = WM_MOVE Then '捕获窗体移动事件
SendMessage BnHwnd, WM_LBUTTONDOWN, 1, 0
SendMessage BnHwnd, WM_LBUTTONUP, 1, 0 '将消息发送到按纽,使其发生CLICK事件
End If
Newproc = CallWindowProc(Oldproc, hwnd, Msg, wp, lp)
End Function

2、在窗体上有一个按钮(名称为eventbn)
Dim 原垂直 As Single, 原水平 As Single

Private Sub EventBn_Click()
MsgBox "移动了"
End Sub

Private Sub form_load()
Form2.Show
Form3.Show
BnHwnd = EventBn.hwnd '获得按纽句丙
Oldproc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf Newproc)
EventBn.Visible = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
原垂直 = Me.Top + Y
原水平 = Me.Left + X
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Top = Me.Top - 原垂直 + Y
Me.Left = Me.Left - 原水平 + X
Form2.Top = Form2.Top - 原垂直 + Y
Form2.Left = Form2.Left - 原水平 + X
Form3.Top = Form3.Top - 原垂直 + Y
Form3.Left = Form3.Left - 原水平 + X
End Sub

3、其他窗体基本都这样。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式