VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 创建不规则窗体
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:9171, 日期:2001-06-14
示例一:创建不规则窗体

  Win32 API 有很多让你意想不到的功能。要创建特殊的不规则窗口看上去似乎很难。 但我们运用API,则几行代码就可以实现,这似乎不可思议。但事实就是如此,不信看看吧!实现步骤:

  (1 ) 建立一个新项目文件DEMO1.PRJ;

  (2 ) 建立模块文件DEMO1.BAS.并在模块的声明部分加入以下代码:

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
注释:定义顶点结构
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Dim XYPOINT() As POINTAPI
   

  (3)在窗体Form1的Command1_Click处理程序中加入以下代码:

Private Sub Command1_Click()
注释:定义区域句柄
Dim hRgn As Long
Dim lRes As Long
注释:定义T型顶点坐标数组
ReDim XYPOINT(7) As POINTAPI 注释:T shape has 8 points
注释:确定T型顶点坐标的值
With Me
XYPOINT(0).X = 0
XYPOINT(0).Y = 0
XYPOINT(1).X = .ScaleWidth
XYPOINT(1).Y = 0
XYPOINT(2).X = .ScaleWidth
XYPOINT(2).Y = .ScaleHeight / 2
XYPOINT(3).X = .ScaleWidth - (.ScaleWidth / 3)
XYPOINT(3).Y = .ScaleHeight / 2
XYPOINT(4).X = .ScaleWidth - (.ScaleWidth / 3)
XYPOINT(4).Y = .ScaleHeight
XYPOINT(5).X = .ScaleWidth / 3
XYPOINT(5).Y = .ScaleHeight
XYPOINT(6).X = .ScaleWidth / 3
XYPOINT(6).Y = .ScaleHeight / 2
XYPOINT(7).X = 0
XYPOINT(7).Y = .ScaleHeight / 2
End With
hRgn = CreatePolygonRgn(XYPOINT(0), 8, 1)
lRes = SetWindowRgn(Me.hWnd, hRgn, True)
Me.BackColor = vbBlue
End Sub
   

  (4)在窗体的Form_Unload处理程序中加入代码:

Private Sub Form1_DbClick()
Unload Me
End Sub