菜鳥學堂:
在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是要設置的圖片的路徑。