
|
属性名 |
设置值 |
备 注 |
|
AutoCenter |
.T. |
自动居中 |
|
BackColor |
0,0,160 |
蓝色背景 |
|
BorderStyle |
No Border |
窗口无边框 |
|
ControlBox |
.F. |
去掉表单的最大化、最小化、恢复按钮 |
|
Caption |
圆形窗口 |
|
|
FillColor |
128,255,0 |
|
|
ShowWindow |
2-as Top-Level Form |
将表单作为顶层表单,否则表单不能独立于VFP而存在 |
|
TitleBar |
0-Off |
取消标题栏 |
在表1中,对表单界面所做的设定,目的是为了让表单在运行之后更像一圆形窗口,因此,我们需要去掉标题栏、窗口大小控制按钮等常规窗口上的内容。
2.在表单上加入一标签控件(Label1)和按钮控件(Command1),分别设定其标题为“VFP圆形窗口示例”和“退出”。
3.设定表单和控件的事件代码,其中表单的Load事件代码为:
*注册API函数
declare integer SetWindowRgn in win32api integer,integer,integer
declare integer CreateRoundRectRgn in win32api integer,integer,integer,integer,integer,integer
*注册VFP的API例程库
SET LIBRARY TO "C:\Program Files\Microsoft Visual Studio\Vfp98\Foxtools.fll"
*设定表单的大小
thisform.top=0
thisform.left=0
thisform.height=200
thisform.width=200
表单的Activate事件代码为:
thisform.Label1.top=thisform.top+thisform.height/2-thisform.label1.height
thisform.Label1.left=thisform.left+(thisform.width-thisform.label1.width)/2
thisform.command1.top=thisform.height-3*thisform.command1.height
thisform.command1.left=thisform.left+(thisform.width-thisform.command1.width)/2
*上述代码主要是用来在圆形窗口中准确定位各控件的位置
topwindow=_WOnTop( )
*获得顶层窗口
hwnd=_WhToHwnd(topwindow)
*获得顶层窗口的句柄
CRN1=CreateRoundRectRgn(0,0,200,200,200,200)
*建立一圆形窗口,如果要做其他形状的窗口,只需调用不同的建立区域的函数
SetWindowRgn(hWnd,CRN1,.T.)
Command1控件的Click事件代码为:
thisform.release
4.运行该表单,结果如图1所示。 
图1
另外,如果你还想设计出其他形状的窗口,只需要将Form1中的Activate事件代码中的CreateRoundRectRgn(0,0,200,200,200,200)做相应的修改。比如你想要建立一苹果形窗口,将该语句改为: CreateRoundRectRgn(0,0,200,200,90,1800)即可。
通过本文所介绍的程序,以前看起来很困难的事情转眼间就做到了。试试看吧,你能够做出更加丰富多彩的异型窗口!