说明: SystemParametersInfo, SystemParametersInfoByval VB声明 Declare Function SystemParametersInfo& Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) Declare Function SystemParametersInfoByVal& Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) 说明 允许获取和设置数量众多的windows系统参数 返回值 Long,非零表示成功,零表示失败。会设置GetLastError 参数表 参数 类型及说明 uAction Long,指定要设置的参数。参考uAction常数表 uParam Long,参考uAction常数表 lpvParam Any,按引用调用的Integer、Long和数据结构。对于String数据,请用SystemParametersInfoByval函数。具体用法参考uAction常数表 fuWinIni Long,取决于不同的参数及操作系统,随同这个函数设置的用户配置参数保存在win.ini或注册表里,或同时保存在这两个地方。这个参数规定了在设置系统参数的时候,是否应更新用户设置参数。可以是零(禁止更新),或下述任何一个常数: SPIF_UPDATEINIFILE 更新win.ini和(或)注册表中的用户配置文件 SPIF_SENDWININICHANGE 倘若也设置了SPIF_UPDATEINIFILE,将一条WM_WININICHANGE消息发给所有应用程序。否则没有作用。这调消息告诉应用程序已经改变了用户配置设置 注解 在调用这个函数之前,特别要注意将lpvParam参数定义成正确的数据类型 ****************************** *注意图片文件必须是BitMap类型* ****************************** 示例代码: '更改墙纸的参数信息及调用的API函数 Public Const SPI_SETDESKWALLPAPER = 20& Public Const SPIF_SENDWININICHANGE = &H2 Public Const SPIF_UPDATEINIFILE = &H1 Public Const SS_CENTER = &H1& Public Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long '平铺 lRet = RegOpenKeyEx(HKEY_CURRENT_USER, gREGKEYWallPaper, 0, KEY_ALL_ACCESS, hKey) '打开相应注册键值 lRet = RegSetValueEx(hKey, "TileWallpaper", 0, REG_SZ, ByVal "1", 2) '写入相应键值信息 lRet = RegSetValueEx(hKey, "WallpaperStyle", 0, REG_SZ, ByVal "0", 2) '写入相应键值信息 lRet = WritePrivateProfileString("Desktop", "Wallpaper", FileName, "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = WritePrivateProfileString("Desktop", "TileWallpaper", "1", "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = WritePrivateProfileString("Desktop", "WallpaperStyle", "0", "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, ByVal FileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE) '更新系统参数信息 '拉伸 lRet = RegOpenKeyEx(HKEY_CURRENT_USER, gREGKEYWallPaper, 0, KEY_ALL_ACCESS, hKey) '打开相应注册键值 lRet = RegSetValueEx(hKey, "TileWallpaper", 0, REG_SZ, ByVal "0", 2) '写入相应键值信息 lRet = RegSetValueEx(hKey, "WallpaperStyle", 0, REG_SZ, ByVal "2", 2) '写入相应键值信息 lRet = WritePrivateProfileString("Desktop", "Wallpaper", FileName, "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = WritePrivateProfileString("Desktop", "TileWallpaper", "0", "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = WritePrivateProfileString("Desktop", "WallpaperStyle", "2", "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, ByVal FileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE) '更新系统参数信息 '居中 lRet = RegOpenKeyEx(HKEY_CURRENT_USER, gREGKEYWallPaper, 0, KEY_ALL_ACCESS, hKey) '打开相应注册键值 lRet = RegSetValueEx(hKey, "TileWallpaper", 0, REG_SZ, ByVal "0", 2) '写入相应键值信息 lRet = RegSetValueEx(hKey, "WallpaperStyle", 0, REG_SZ, ByVal "0", 2) '写入相应键值信息 lRet = WritePrivateProfileString("Desktop", "Wallpaper", FileName, "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = WritePrivateProfileString("Desktop", "TileWallpaper", "0", "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = WritePrivateProfileString("Desktop", "WallpaperStyle", "0", "Win.ini") '更换结果写入到Win.ini中相应相置 lRet = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, ByVal FileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE) '更新系统参数信息 刷新桌面 Option Explicit Private Declare Sub keybd_event Lib "user32" _ (ByVal bVk As Byte, _ ByVal bScan As Byte, _ ByVal dwFlags As Long, _ ByVal dwExtraInfo As Long) Private Const VK_F5 = &H74 Private Const VK_LWIN = &H5B Private Const VK_M = &H4D Private Const KEYEVENTF_KEYUP = &H2 Private Sub Command1_Click() '模拟按下Win+M键,最小化所有应用程序窗口以显示桌面 Call keybd_event(VK_LWIN, 0, 0, 0) Call keybd_event(VK_M, 0, 0, 0) Call keybd_event(VK_M, 0, KEYEVENTF_KEYUP, 0) Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0) '产生一定延时 DoEvents DoEvents '模拟按下F5键,刷新桌面 Call keybd_event(VK_F5, 0, 0, 0) Call keybd_event(VK_F5, 0, KEYEVENTF_KEYUP, 0) End Sub |