怎摸用VB做各种形状的窗体?分不够再给!

Dickson 2003-04-21 09:10:41
椭圆等简单的我知道,我是问象组合型(如圆和矩形等)或五角星型等。
最好给点例子,谢了
...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
DimVar 2003-04-22
  • 打赏
  • 举报
回复
这样的话,比较重要的是CombineRgn函数了。参考这个例子,把setWindowFigure()放到FORM_LOAD里。
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Public Const RGN_AND = 1
Public Const RGN_DIFF = 4
Public Const RGN_XOR = 3

Function setWindowFigure() As Boolean
'Set windows figure
Dim rgnDes As Long
Dim rgnSrc1 As Long
Dim rgnSrc2 As Long
Dim rgnTmp As Long
Dim rgnOri As Long

'rgnOri = CreateRectRgn(me.Left / Screen.TwipsPerPixelX, me.Top / Screen.TwipsPerPixelX, (me.Left + me.Width) / Screen.TwipsPerPixelX, (me.Top + me.Height) / Screen.TwipsPerPixelY)
rgnOri = CreateRectRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)

rgnSrc1 = CreateRectRgn(0, 0, 10, 10)
rgnSrc2 = CreateEllipticRgn(0, 0, 20, 20)
rgnTmp = CreateRectRgn(0, 0, 1, 1)
rgnDes = CreateRectRgn(0, 0, 1, 1)
CombineRgn rgnTmp, rgnSrc1, rgnSrc2, RGN_DIFF
CombineRgn rgnDes, rgnOri, rgnTmp, RGN_XOR

rgnOri = rgnDes

rgnSrc1 = CreateRectRgn((Me.Width / Screen.TwipsPerPixelX - 10), 0, (Me.Width / Screen.TwipsPerPixelX), 10)
rgnSrc2 = CreateEllipticRgn((Me.Width / Screen.TwipsPerPixelX - 20), 0, (Me.Width / Screen.TwipsPerPixelX), 20)
rgnTmp = CreateRectRgn(0, 0, 1, 1)
rgnDes = CreateRectRgn(0, 0, 1, 1)

CombineRgn rgnTmp, rgnSrc1, rgnSrc2, RGN_DIFF
CombineRgn rgnDes, rgnOri, rgnTmp, RGN_XOR

SetWindowRgn Me.hWnd, rgnDes, True

End Function
Rozre 2003-04-21
  • 打赏
  • 举报
回复
up
danielinbiti 2003-04-21
  • 打赏
  • 举报
回复
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode 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 CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim ap(4) As POINTAPI
Dim hx As Integer
Dim hy As Integer
'棱形,其有边和点组成的图形都可以模仿,把ap得坐标点变一下就成了
Private Sub Command1_Click()
ap(0).X = 0: ap(0).Y = hy
ap(1).X = hx: ap(1).Y = 0
ap(2).X = Form1.Width \ Screen.TwipsPerPixelX: ap(2).Y = hy
ap(3).X = hx: ap(3).Y = Form1.Height \ Screen.TwipsPerPixelY
ap(4) = ap(0)
reRgn = CreatePolygonRgn(ap(0), 5, 1)
SetWindowRgn Form1.hWnd, reRgn, True
End Sub
'圆形
Private Sub Command2_Click()
Dim hr As Long
Dim dl As Long
hr = CreateEllipticRgn(0, 0, hx, hy)
dl = SetWindowRgn(Me.hWnd, hr, True)
End Sub

Private Sub Form_Load()
Dim reRgn As Long
hy = Form1.Height \ (2 * Screen.TwipsPerPixelY)
hx = Form1.Width \ (2 * Screen.TwipsPerPixelX)
End Sub
那五角星只要算出那十个点的坐标就成了,
圆和矩形组合倒是没试过
ikumei 2003-04-21
  • 打赏
  • 举报
回复
用window api
ikumei 2003-04-21
  • 打赏
  • 举报
回复
api

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧