窗体还能在屏幕任意拖动
新手上路!
请多指教!
[CODE]'in modle
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 CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject 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 Const RGN_OR = 2
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Sub SetFormRgn(F As Form)
Dim RGNMain&, RGNTemp&
Dim i As Control
Dim RWindow As RECT, POffset As POINTAPI
F.ScaleMode = 3 'pixel
ClientToScreen F.hWnd, POffset
GetWindowRect F.hWnd, RWindow
POffset.X = POffset.X - RWindow.Left
POffset.Y = POffset.Y - RWindow.Top
On Error Resume Next
For Each i In F
If i.Visible = True Then
RGNTemp = CreateRectRgn(i.Left + POffset.X, i.Top + POffset.Y, i.Left + i.Width + POffset.X, i.Top + i.Height + POffset.Y)
If RGNMain = 0 Then
RGNMain = RGNTemp
Else
CombineRgn RGNMain, RGNMain, RGNTemp, RGN_OR
DeleteObject RGNTemp
End If
End If
Next
SetWindowRgn F.hWnd, RGNMain, True
DeleteObject RGNMain
End Sub
[/CODE]
[CODE]
' in form,add command 2 label 1
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 WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const HTCAPTION = 2
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_Click()
SetFormRgn Me
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
End If
End Sub