希望做一个椭圆型的窗体,用了以下方法
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Dim rtn As Long
BorderStyler = 0
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, RGB(252, 3, 21), 0, LWA_COLORKEY 结果无论怎么弄,都无法去掉窗体的边框。请高手指教了。
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Dim rtn As Long
BorderStyler = 0
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, RGB(252, 3, 21), 0, LWA_COLORKEY 结果无论怎么弄,都无法去掉窗体的边框。请高手指教了。
返回或设置对象的边框样式。对 Form 对象和 Textbox 控件在运行时是只读的
设计时将窗体的BorderStyle属性设为0
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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
Dim ret As Long, w, h
Me.ScaleMode = 3
w = Me.ScaleWidth: h = Me.ScaleHeight
ret = CreateEllipticRgn(0, 0, w, h)
SetWindowRgn hWnd, ret, True
DeleteObject ret
End Sub
设计时将窗体的BorderStyle属性设为0
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Sub Form_Load()
Dim Rgn As Long
Dim r As Long
Me.ScaleMode = vbPixels
r = 20 ' 圆角大小
Rgn = CreateRoundRectRgn(0, 0, Me.ScaleWidth, Me.ScaleHeight, r, r)
SetWindowRgn hWnd, Rgn, True
DeleteObject Rgn
End Sub
如果窗体没有菜单栏,只要先修改BorderStyle再设置一下窗体的caption就可以了。
如果有菜单栏就麻烦一点。