Windows
由许多动态链接库(DLL)组成,这些DLL中包含成百上千个用于访问Windows 操作系统自身的函数(称之为API
函数)。
这些API 函数能解决不少高级语言解决不了或解决不好的问题。
在VB程序中适当使用API 函数,可以为应用程序增添不少色彩。下面以设置墙纸为例,对API 函数的使用做些说明。API
函数SystemParametersInfo 的格式为:SystemParametersInfo uAction
,uP—aram,lpvParam,fuWinIni
将参数uAction 设为20,uParam 设为0,lpvParam 设为bmp 图片的文件名(含路径)。fuWinIni
设为“&H1”,表示更新INI 文件。在VB5中设置墙纸的操作步骤如下:
1、创建新工程,选择“标准.exe”。
2、向该工程添加一个标准模块Module1,并将以下代码加入到Module1的“通用声明”中(通过API
文本查看器):
Option Explicit
Declare Function SystemParametersInfoLib″user32″Alias″SystemParametersInfoA″(ByVal
uAction As Long ,ByVal uParam AsLong ,ByVal lpvParam As Any,ByValfuWinIni
As Long)As Long
3、向Module1中添加一公用子程序,其代码如下:Public Sub Setbmp()SystemParametersInfo20,0,Form1.Text1.Text
,&H1End Sub
4、向窗体Form1添加一标签控件La—bel1,并设置以下属性:Caption
=″请输入墙纸名称:″
Top =600Left =600
5、向窗体Form1添加一文本框控件Text1,并设置以下属性:
Text =″″
Top =960Left =600Height =375Width =3015
6、向窗体Form1添加一通用对话框控件Commondia。
7、向窗体Form1添加二个按钮控件,并设置以下属性:Command1:Caption =″浏览″
Top =960Left =3960将以下代码添加到Command1的Click 事件中:Private
Sub Command1_Click()Commondia.Filter =″Picture(*.bmp)|*.bmp″Commondia.ShowOpenText1.Text
=Commondia.filenameEnd SubCommand2:Caption =″确定″
Top =2400Left =1680将以下代码添加到Command2的Click事件中:Private
Sub Command2_Click()If Text1.Text =″″ThenMsgBox″墙纸名称不能为空!″Else
SetbmpMsgBox″墙纸已设置完成!″
End IfEnd Sub运行该程序,通过“浏览”按钮选定图片,单击“确定”,选定的图片即成为桌面的墙纸。
(浙江省温岭市太平镇兰田新村3—2号陈小勇317500)