如何制作程序启动时与关于时的版权画面

来源:互联网 发布:淘宝欧珀莱全是假的 编辑:程序博客网 时间:2024/06/05 05:37
对于表单的设计我们一般用到的主要有以下几种:
1.启动画面式的表单。如VFP或WORD等的启动画面,上面有使用者、使用单位、版权信息等,如下图:

对于这样的表单,我们可以进行如下操作:
(1)在表单的load事件过程中加入如下代码,调用win32API函数。
public username,usercomp,titletime
declare integer RegOpenKeyEx in Win32API;
integer nkey,string @csubkey,integer nreserved,;
integer naccessmask,integer @nresult
declare integer RegQueryValueEx in Win32API;
integer nkey,string cvaluename,integer nresered,;
integer @ntype,string @cbuffer,integer @nbuffersize
declare integer RegCloseKey in Win32API;
integer nkey
username=
usercomp=
lnresult=0
buffer=space(128)
buffersize=len(buffer)
lnerror=regopenkeyex(-2147483646,Software/microsoft/windows/currentversion,0,1,@lnresult)
if lnerror=0
lntype=0
buffer=space(128)
buffersize=len(buffer)
lnerror=regqueryvalueex(lnresult,registeredowner,0,@lntype,@buffer,@buffersize)
if lnerror=0 and buffer<>chr(0)
username=left(buffer,buffersize-1)
endif
lntype=0
buffer=space(128)
buffersize=len(buffer)
lnerror=regqueryvalueex(lnresult,registeredorganization,0,@lntype,@buffer,@buffersize)
if lnerror=0 and buffer<>chr(0)
usercomp=left(buffer,buffersize-1)
endif
endif
=regclosekey(lnresult)
在表单中增加label1(用户名)和label2(用户单位)两个标签,在label1的ini事件中加入:
this.caption=username
语句,在label2中加入:this.caption=usercomp语句。
在init事件中加入如下语句:
public nn &&设置计时器的初值
nn=0
set bell to 'welcome.wav',2 &&设置启动时的启动音乐,如果你的机器没有声卡,只是响铃
??chr(7) &&一次。

(2)再对表单的属性进行设置。
Alwaysontop=.t.
Autocenter=.t.
BorderStyle=1
Caption=''
Closable=.f.
ControlBox=.f.
Desktop=.f.
Maxbutton=.f.
Minbutton=.f.
Movable=.f.
Picture='begin.bmp' &&设置的此背静图象和该表单的大小一样
ShowWindow=.t.
这样设置的表单是一个没有标题的单线方框。
(3)在表单中加入一个计时器timer1,编写计时器的Timer event过程
nn=nn+1
if nn=45
release thisform
clear event
Endif
这样表单在启动后停留一下后自动关闭。
(4)在表单的Click事件过程.
release thisform
clear event
这样在启动后,如果用户不想等待画面的停留,可以在启动画面上单击表单,以快速进入程序画面。
(5)编写表单的unload事件。
set bell to
clear dells
2.关于画面的设计。
现在大型程序中一般都有自己的关于画面,下面是一个简单的例子,只是少了系统信息一项。画面如下:

(1)设置表单属性。
Alwaysontop=.t.
Autocenter=.t.
BorderStyle=2
Caption='关于'
Maxbutton=.f.
Minbutton=.f.
icon='about.ico'
(2)设置用户名和使用单位。
此项可照启动画面的load事件过程设置。
(3)在表单中设置默认目录、操作系统、硬盘空间、CPU型号、可用内存5个label。
对于默认目录,在INIT事件中加入代码:this.caption=allt(sys(5))+allt(sys(2003))
操作系统,在INIT事件中加入:this.caption=os()
硬盘空间,在INIT事件中加入:this.caption=allt(str(diskspace()))+字节
CPU型号,在INIT中加入:this.caption=sys(17)
可用内存,在INIT中加入:this.caption=sys(1001)+KB
(4)主页地址,技术支持超级链接的编写。
在表单的INIT事件中调用WINDOWS的SHELL32函数。
DECLARE INTEGER ShellExecute IN shell32.DLL INTEGER HWND, STRING,;
STRING lpszFile,STRING ,STRING ,INTEGER
建立一个标签(label18),在caption中输入:http://zhanghongju.163.net/
在其CLICK事件中加入下列代码:
lpszFile='http://zhanghongju.163.net/' &&设定你的主页地址
=ShellExecute(0,0,lpszFile , 0,0,1) &&调用ShellExecute函数

在其mousemove事件中加入下列代码:
LPARAMETERS nButton, nShift, nXCoord, nYCoord
thisform.label18.ForeColor=RGB(255,0,0)
在表单的mousemove事件中加入下列代码
LPARAMETERS nButton, nShift, nXCoord, nYCoord
thisform.label18.ForeColor=RGB(0,0,255)
设置label18的属性:
fontunderline=.t. &&设定下画线
MOuseicon='hand-m.cur' &&设定当鼠标移动到该标签时鼠标会变成一只小手
MousePointer=99 &&要使上面MOuseicon的设置生效,此项的设置必须为99
至此主页的设置已经完成,对于电子邮件的设置只需将上面的http://zhanghongju.163.net/换成mailto:dzzhj@263.net就可以了。别忘了在表单的unload事件中还要加入clear dells命令呀!
3.一般表单的设计
对于一般的表单,如数据录入表单,而且有时需要打开多个表单,一个最主要的问题,便是数据环境的使用问题,表打开多了,给程序的运行速度带来一定的出影响,可是在关闭表单的时候关闭表,如果这个表正在被其他的程序使用,就会出错,而且由于VFP的一些特殊命令不能在共享方式下运行,也给编写程序带来一定的困难,我的一般解决办法是首先要对各种情况分析透彻,尽量不使用数据环境,而是在表单的INIT事件中用USED()和SELECT()等函数首先判断当前表是否被打开,否则用命令打开表,在关闭表单的时候,首先判断有那些表单已经存在,然后关闭那些不被使用的表。这样可能是很麻烦,所以我建议大家使用视图技术和缓存技术,解决上述问题可能比较的合理一些。

原创粉丝点击