找到了 Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const GWL_STYLE = (-16) Private Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME Private Const WS_SIZEBOX = &H40000 Private Const HTCAPTION = 2 Private Const WM_NCLBUTTONDOWN = &HA1
Private Sub Form_Load() Dim OldStyle As Long ScaleMode = 3 ForeColor = vbGreen OldStyle = GetWindowLong(hWnd, GWL_STYLE) SetWindowLong hWnd, GWL_STYLE, OldStyle And Not WS_CAPTION And Not WS_SIZEBOX End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then If Y >= 0 And Y <= 25 Then ReleaseCapture SendMessageLong hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 End If End If End Sub
Private Sub Form_Paint() Line (0, 0)-(ScaleWidth, 25), vbBlue, BF CurrentX = 10 CurrentY = 10 Print "标题栏" End Sub
Option Explicit '移动窗口 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 Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) ReleaseCapture SendMessage Me.hWnd, &HA1, 2, 0& End Sub