迄今为止,我们用VB编制的程序窗口大都是标准的四方形,看上去很没有个性。如果你想让你的程序与众不同的话,可以利用以下几个API函数来创建不规则窗口:
CreateRectRgn(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) '创建一个矩形区域,四个参数分别代表左、上、右、下的坐标;
CreateEllipticRgn(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) '创建一个椭圆形区域,参数同上;
CreatePolygonRgn(pPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) '创建一个多边形区域,pPoint参数为一个POINTAPI型数组,nCount参数说明顶点数,nPolyFillMode参数为填充模式;
CombineRgn(ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) '合并两个区域,hDestRgn是合并后的区域,hSrcRgn1和hSrcRgn2是欲合并的目标区域,nCombineMode为合并方式;
SetWindowRgn((ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) '设置窗体为指定样式,hRgn为上述几个函数创建的区域,bRedraw决定是否立即重画窗体。
有了这些“神兵利器”,我们就可以随心所欲地制作出各式各样的窗体。示范程序如下:
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 SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Sun Form_load()
Dim x,y As Long
x=CreateEllipticRgn(0,0,100,200)
y=SetWindowRgn(Me.hwnd,x,True)
End Sub
以上程序可以创建一个椭圆形窗体,并在VB6.0,Win 98环境下调试通过。有兴趣的朋友可以参考以上的API函数以及示范程序编写其它几种不规则窗口。
本文地址:http://com.8s8s.com/it/it6693.htm