2 个解决方案
#1
利用Windows API的SetWindowRgn可以做这件事,下面就是一个这方面的例子。
Option Explicit
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
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 CreateRoundRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn 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 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 Type POINTAPI
X As Long
Y As Long
End Type
Private Const RGN_AND = 1
Private Const RGN_COPY = 5
Private Const RGN_DIFF = 4
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Function CreateFormRegion() As Long
Dim ResultRegion As Long, HolderRegion As Long, ObjectRegion As Long, nRet As Long
Dim PolyPoints() As POINTAPI
ResultRegion = CreateRectRgn(0, 0, 0, 0)
HolderRegion = CreateRectRgn(0, 0, 0, 0)
'!Shaped Form Region Definition
'!3,16,105,423,328,0,0,1
ObjectRegion = CreateEllipticRgn(105 * 12 / Screen.TwipsPerPixelX, 16 * 12 / Screen.TwipsPerPixelY, 423 * 12 / Screen.TwipsPerPixelX, 328 * 12 / Screen.TwipsPerPixelY)
nRet = CombineRgn(ResultRegion, ObjectRegion, ObjectRegion, RGN_COPY)
DeleteObject ObjectRegion
CreateFormRegion = ResultRegion
End Function
Private Sub Form_Load()
Dim nRet As Long
nRet = SetWindowRgn(Me.hWnd, CreateFormRegion, True)
'If the above two lines are modified or moved a second copy of
'them may be added again if the form is later Modified by VBSFC.
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Next two lines enable window drag from anywhere on form. Remove them
'to allow window drag from title bar only.
ReleaseCapture
SendMessage Me.hWnd, &HA1, 2, 0&
Option Explicit
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
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 CreateRoundRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn 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 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 Type POINTAPI
X As Long
Y As Long
End Type
Private Const RGN_AND = 1
Private Const RGN_COPY = 5
Private Const RGN_DIFF = 4
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Function CreateFormRegion() As Long
Dim ResultRegion As Long, HolderRegion As Long, ObjectRegion As Long, nRet As Long
Dim PolyPoints() As POINTAPI
ResultRegion = CreateRectRgn(0, 0, 0, 0)
HolderRegion = CreateRectRgn(0, 0, 0, 0)
'!Shaped Form Region Definition
'!3,16,105,423,328,0,0,1
ObjectRegion = CreateEllipticRgn(105 * 12 / Screen.TwipsPerPixelX, 16 * 12 / Screen.TwipsPerPixelY, 423 * 12 / Screen.TwipsPerPixelX, 328 * 12 / Screen.TwipsPerPixelY)
nRet = CombineRgn(ResultRegion, ObjectRegion, ObjectRegion, RGN_COPY)
DeleteObject ObjectRegion
CreateFormRegion = ResultRegion
End Function
Private Sub Form_Load()
Dim nRet As Long
nRet = SetWindowRgn(Me.hWnd, CreateFormRegion, True)
'If the above two lines are modified or moved a second copy of
'them may be added again if the form is later Modified by VBSFC.
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Next two lines enable window drag from anywhere on form. Remove them
'to allow window drag from title bar only.
ReleaseCapture
SendMessage Me.hWnd, &HA1, 2, 0&
#2
谢谢楼上这位大哥的回复,我先去试一下。要是行的话,一定给分你
#1
利用Windows API的SetWindowRgn可以做这件事,下面就是一个这方面的例子。
Option Explicit
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
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 CreateRoundRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn 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 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 Type POINTAPI
X As Long
Y As Long
End Type
Private Const RGN_AND = 1
Private Const RGN_COPY = 5
Private Const RGN_DIFF = 4
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Function CreateFormRegion() As Long
Dim ResultRegion As Long, HolderRegion As Long, ObjectRegion As Long, nRet As Long
Dim PolyPoints() As POINTAPI
ResultRegion = CreateRectRgn(0, 0, 0, 0)
HolderRegion = CreateRectRgn(0, 0, 0, 0)
'!Shaped Form Region Definition
'!3,16,105,423,328,0,0,1
ObjectRegion = CreateEllipticRgn(105 * 12 / Screen.TwipsPerPixelX, 16 * 12 / Screen.TwipsPerPixelY, 423 * 12 / Screen.TwipsPerPixelX, 328 * 12 / Screen.TwipsPerPixelY)
nRet = CombineRgn(ResultRegion, ObjectRegion, ObjectRegion, RGN_COPY)
DeleteObject ObjectRegion
CreateFormRegion = ResultRegion
End Function
Private Sub Form_Load()
Dim nRet As Long
nRet = SetWindowRgn(Me.hWnd, CreateFormRegion, True)
'If the above two lines are modified or moved a second copy of
'them may be added again if the form is later Modified by VBSFC.
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Next two lines enable window drag from anywhere on form. Remove them
'to allow window drag from title bar only.
ReleaseCapture
SendMessage Me.hWnd, &HA1, 2, 0&
Option Explicit
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
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 CreateRoundRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn 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 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 Type POINTAPI
X As Long
Y As Long
End Type
Private Const RGN_AND = 1
Private Const RGN_COPY = 5
Private Const RGN_DIFF = 4
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Function CreateFormRegion() As Long
Dim ResultRegion As Long, HolderRegion As Long, ObjectRegion As Long, nRet As Long
Dim PolyPoints() As POINTAPI
ResultRegion = CreateRectRgn(0, 0, 0, 0)
HolderRegion = CreateRectRgn(0, 0, 0, 0)
'!Shaped Form Region Definition
'!3,16,105,423,328,0,0,1
ObjectRegion = CreateEllipticRgn(105 * 12 / Screen.TwipsPerPixelX, 16 * 12 / Screen.TwipsPerPixelY, 423 * 12 / Screen.TwipsPerPixelX, 328 * 12 / Screen.TwipsPerPixelY)
nRet = CombineRgn(ResultRegion, ObjectRegion, ObjectRegion, RGN_COPY)
DeleteObject ObjectRegion
CreateFormRegion = ResultRegion
End Function
Private Sub Form_Load()
Dim nRet As Long
nRet = SetWindowRgn(Me.hWnd, CreateFormRegion, True)
'If the above two lines are modified or moved a second copy of
'them may be added again if the form is later Modified by VBSFC.
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Next two lines enable window drag from anywhere on form. Remove them
'to allow window drag from title bar only.
ReleaseCapture
SendMessage Me.hWnd, &HA1, 2, 0&
#2
谢谢楼上这位大哥的回复,我先去试一下。要是行的话,一定给分你