' 无标题栏的窗体的拖动问题
'在特殊窗体的应用中,我们有时需要把窗体的标题栏屏蔽掉,
'以窗体换上自己的外壳。是,当去掉了窗体标题栏后,移动窗体就成了一个问题。
'我们还是来看一下在VB6中的实现,VB6中实现(借助API函数SendMessage)
'在设计时将窗体的BorderStyle属性设置为0 -none
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngReturnValue As Long
If Button = 1 And WindowState = 0 Then
'Release capture
Call ReleaseCapture
'Send a 'left mouse button down on caption'-message to our form
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
Private Sub Form_Paint()
Me.Print ("Click on the form, hold the mouse button and drag it")
End Sub
'拖动窗体的API
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 HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'拖动窗体
If Button = 1 Then
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub