setwindowlong是个好方法,但是3D边框却出来了,只有用变通的方法:
这个例子展示了左右移动的方法,并且保持原窗体原样!!!!!!
你可以自行加入上下移动,斜移动等
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 Const HTLEFT = 10
Private Const HTRIGHT = 11
Private Const WM_NCLBUTTONDOWN = &HA1
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim nParam As Long
With Me
If X > 0 And X < 100 Then
nParam = HTLEFT
ElseIf X > .Width - 100 And X < .Width Then
nParam = HTRIGHT
End If
If nParam Then
Call ReleaseCapture
Call SendMessage(.hwnd, WM_NCLBUTTONDOWN, nParam, 0)
End If
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Np As MousePointerConstants
With Me
If X > 0 And X < 100 Then
Np = vbSizeWE
ElseIf X > .Width - 100 And X < .Width Then
Np = vbSizeWE
Else '此处还可以继续加
Np = vbDefault
End If
If Np <> .MousePointer Then
.MousePointer = Np
End If
End With
End Sub
'This sample show you how to cut the caption title exactly and create controls with code.
'add a new form ,do nothing but copy this codes for it.
Option Explicit
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private WithEvents cmd1 As CommandButton
Private WithEvents cmd2 As CommandButton
Private Sub cmd1_Click() '******************
Dim capheight As Long, area As Long
Me.ScaleMode = 2
Me.ForeColor = vbRed
Me.Line (1, 0)-(Me.Width, 0) '紧贴标题栏画线做标记
capheight = GetSystemMetrics(33) + GetSystemMetrics(4) ' 边框宽度+标题栏高度
area = CreateRectRgn(0, capheight, Me.Width, Me.Height) '画无标题栏的矩形框
area = SetWindowRgn(Me.hWnd, area, True) '裁剪标题栏
End Sub
Private Sub cmd2_Click() '*******************
Me.ScaleMode = 2
Dim area As Long
area = CreateRectRgn(0, 0, Me.Width, Me.Height) '画含标题栏的矩形框
area = SetWindowRgn(Me.hWnd, area, True) '恢复标题栏
End Sub
Private Sub Form_Load()
Me.WindowState = 0
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 8000, 5000'居中及设置窗体大小
Set cmd1 = Controls.Add("VB.CommandButton", "cmd1", Me)'添加cmd1按纽
Set cmd2 = Controls.Add("VB.CommandButton", "cmd2", Me)'添加cmd2按纽
cmd1.Move 1000, 1000, 1500, 500
cmd2.Move 3000, 1000, 1500, 500
cmd1.Caption = "裁剪标题栏"
cmd2.Caption = "恢复标题栏"
cmd1.Visible = True
cmd2.Visible = True
End Sub