1,485
社区成员
发帖
与我相关
我的任务
分享
'form1代码
Private Sub Form_Load()
prevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
Form2.Show
End Sub
Private 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 Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_MOVE = &H3
Public Const WM_SIZE = &H5
Public 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
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 Long
Private 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