用VB5设置墙纸
来源:岁月联盟
时间:2007-02-01
?这些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 ,&H1?End Sub
4、向窗体Form1添加一标签控件La—bel1,并设置以下属性:?Caption =″请输入墙纸名称:″
?Top =600?Left =600
?5、向窗体Form1添加一文本框控件Text1,并设置以下属性:?
Text =″″
?Top =960?Left =600?Height =375?Width =3015
?6、向窗体Form1添加一通用对话框控件Commondia。
?7、向窗体Form1添加二个按钮控件,并设置以下属性:?Command1:?Caption =″浏览″
?Top =960?Left =3960?将以下代码添加到Command1的Click 事件中:?Private Sub Command1_Click()?Commondia.Filter =″Picture(*.bmp)|*.bmp″?Commondia.ShowOpen?Text1.Text =Commondia.filename?End Sub?Command2:?Caption =″确定″
?Top =2400?Left =1680?将以下代码添加到Command2的Click?事件中:?Private Sub Command2_Click()?If Text1.Text =″″Then?MsgBox″墙纸名称不能为空!″?Else? Setbmp?MsgBox″墙纸已设置完成!″
?End If?End Sub?运行该程序,通过“浏览”按钮选定图片,单击“确定”,选定的图片即成为桌面的墙纸。
上一篇:如何自动移动Mouse