示例一:创建不规则窗体
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
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073