菜鸟学堂:
在vb6中设置墙纸
private declare function systemparametersinfo lib "user32" alias "systemparametersinfoa" (byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long) as long
const spi_setdeskwallpaper = 20
const spif_sendwininichange = &h2
const spif_updateinifile = &h1
private sub command1_click()
re = systemparametersinfo(spi_setdeskwallpaper, 0, "c:/test.bmp", 0)
end sub
在vb.net 2003中设置墙纸
private const spi_setdeskwallpaper as integer = &h14
private const spif_updateinifile as integer = &h1
private const spif_sendwininichange as integer = &h2
private declare auto function systemparametersinfo lib "user32.dll" ( _
byval uaction as integer, byval uparam as integer, _
byval lpvparam as string, byval fuwinini as integer) as integer
'设置墙纸
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
systemparametersinfo(spi_setdeskwallpaper, 0, "c:/test.bmp", 0)
end sub
'取消设置
private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
systemparametersinfo(spi_setdeskwallpaper, 0, "", 0)
end sub
在vb.net 2005中设置墙纸:
private const spi_setdeskwallpaper as integer = &h14
private const spif_updateinifile as integer = &h1
private const spif_sendwininichange as integer = &h2
private declare auto function systemparametersinfo lib "user32.dll" ( _
byval uaction as integer, byval uparam as integer, _
byval lpvparam as string, byval fuwinini as integer) as integer
''' <summary>
''' 设置墙纸
''' </summary>
private sub setwallpaper()
'得到我的图片目录中的文件,在vb2005中,利用my.computer简单得到我的图片目录
dim imglocation as string = my.computer.filesystem.combinepath(my.computer.filesystem.specialdirectories.mypictures, "myimage.bmp")
try
systemparametersinfo(spi_setdeskwallpaper, 0, imglocation or spif_sendwininichange)
catch ex as exception
msgbox("设置过程中出现错误: " & ex.message)
end try
end sub
参考:
systemparametersinfo函数的定义和参数:
声明如下:
private declare function systemparametersinfo lib "user32" alias "systemparametersinfoa" (byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long) as long
其中各参数的意义如下表:
参数: 意义
uaction long,指定要设置的参数。参考uaction常数表
uparam long,参考uaction常数表
lpvparam any,按引用调用的integer、long和数据结构。
fuwinini 这个参数规定了在设置系统参数的时候,是否应更新用户设置参数
下面是部分uaction参数,和使用它们的方法:
参数 意义和使用方法
6 设置视窗的大小,systemparametersinfo(6, 放大缩小值, p, 0),lpvparam为long型
17 开关屏保程序,systemparametersinfo(17, false, p, 1),uparam为布尔型
13,24 改变桌面图标水平和垂直间距,uparam为间距值(像素),lpvparam为long型
15 设置屏保等待时间,systemparametersinfo(15, 秒数, p, 1),lpvparam为long型
20 设置桌面背景墙纸,systemparametersinfo(20, true, 图片路径, 1)
93 开关鼠标轨迹,systemparametersinfo(93, 数值, p, 1),uparam为false则关闭
97 开关ctrl+alt+del窗口,systemparametersinfo(97, false, a, 0),uparam为布尔型
本例中我们选择图片并取得图片的完整路径,然后通过调用api函数,将这幅图设为墙纸,使用的语法为:systemparametersinfo spi_setdeskwallpaper, 0, bmpfile, 1
其中systemparametersinfo表示要设置桌面墙纸,bmpfile是要设置的图片的路径。