HOW TO:墙纸设置
来源:互联网 发布:itools for mac序列号 编辑:程序博客网 时间:2024/04/20 07:58
Imports System.Security
Imports System.Runtime.InteropServices
<SuppressUnmanagedCodeSecurity()> _
Friend NotInheritable Class UnsafeNativeMethods
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function SystemParametersInfo( _
ByVal nAction As Integer, _
ByVal nParam As Integer, _
ByVal lpvParam As String, _
ByVal nUpdate As Integer _
) As Boolean
End Function
Public Const SPI_SETDESKWALLPAPER As Integer = &H14
Public Const SPIF_UPDATEINIFILE As Integer = &H1
Public Const SPIF_SENDWININICHANGE As Integer = &H2
End Class
Public Class DesktopWallpaper
Private Sub New()
End Sub
Public Shared Function Clear(ByVal update As UpdateType) As Boolean
Return InternalChange("", update)
End Function
Public Shared Function Change(ByVal bmpFile As String, ByVal update As UpdateType) As Boolean
Return InternalChange(bmpFile, update)
End Function
Public Shared Function Change(ByVal path As String, ByVal bmpFilename As String, ByVal update As UpdateType) As Boolean
Dim bmpFile As String = Microsoft.VisualBasic.FileIO.FileSystem.CombinePath(path, bmpFilename)
Return InternalChange(bmpFile, update)
End Function
Private Shared Function InternalChange(ByVal bmpFile As String, ByVal update As UpdateType) As Boolean
Return UnsafeNativeMethods.SystemParametersInfo( _
UnsafeNativeMethods.SPI_SETDESKWALLPAPER, _
0, _
bmpFile, _
GetUpdateValue(update))
End Function
Private Shared Function GetUpdateValue(ByVal update As UpdateType) As Integer
Select Case update
Case UpdateType.Save
Return UnsafeNativeMethods.SPIF_UPDATEINIFILE
Case UpdateType.Reflesh
Return UnsafeNativeMethods.SPIF_SENDWININICHANGE
Case UpdateType.SaveAndReflesh
Return UnsafeNativeMethods.SPIF_UPDATEINIFILE Or UnsafeNativeMethods.SPIF_SENDWININICHANGE
End Select
End Function
Public Enum UpdateType
''' <summary>
''' 保存设置,重启系统后有效
''' </summary>
Save = 1
''' <summary>
''' 更新设置,本次有效,重启系统后无效
''' </summary>
Reflesh = 2
''' <summary>
''' 保存设置并生效
''' </summary>
SaveAndReflesh = 3
End Enum
End Class
'没全部测试。在我的简单测试中,SaveOnly都会Reflesh了。
Public Class Demo
Public Shared Sub RefleshOnly()
DesktopWallpaper.Change("c: /test.bmp", DesktopWallpaper.UpdateType.Reflesh)
End Sub
Public Shared Sub SaveOnly()
DesktopWallpaper.Change("c:/ test.bmp", DesktopWallpaper.UpdateType.Save)
End Sub
Public Shared Sub Update()
DesktopWallpaper.Change("c:/ test.bmp", DesktopWallpaper.UpdateType.SaveAndReflesh)
End Sub
Public Shared Sub Clear()
DesktopWallpaper.Clear(DesktopWallpaper.UpdateType.SaveAndReflesh)
End Sub
End Class
Imports System.Runtime.InteropServices
<SuppressUnmanagedCodeSecurity()> _
Friend NotInheritable Class UnsafeNativeMethods
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function SystemParametersInfo( _
ByVal nAction As Integer, _
ByVal nParam As Integer, _
ByVal lpvParam As String, _
ByVal nUpdate As Integer _
) As Boolean
End Function
Public Const SPI_SETDESKWALLPAPER As Integer = &H14
Public Const SPIF_UPDATEINIFILE As Integer = &H1
Public Const SPIF_SENDWININICHANGE As Integer = &H2
End Class
Public Class DesktopWallpaper
Private Sub New()
End Sub
Public Shared Function Clear(ByVal update As UpdateType) As Boolean
Return InternalChange("", update)
End Function
Public Shared Function Change(ByVal bmpFile As String, ByVal update As UpdateType) As Boolean
Return InternalChange(bmpFile, update)
End Function
Public Shared Function Change(ByVal path As String, ByVal bmpFilename As String, ByVal update As UpdateType) As Boolean
Dim bmpFile As String = Microsoft.VisualBasic.FileIO.FileSystem.CombinePath(path, bmpFilename)
Return InternalChange(bmpFile, update)
End Function
Private Shared Function InternalChange(ByVal bmpFile As String, ByVal update As UpdateType) As Boolean
Return UnsafeNativeMethods.SystemParametersInfo( _
UnsafeNativeMethods.SPI_SETDESKWALLPAPER, _
0, _
bmpFile, _
GetUpdateValue(update))
End Function
Private Shared Function GetUpdateValue(ByVal update As UpdateType) As Integer
Select Case update
Case UpdateType.Save
Return UnsafeNativeMethods.SPIF_UPDATEINIFILE
Case UpdateType.Reflesh
Return UnsafeNativeMethods.SPIF_SENDWININICHANGE
Case UpdateType.SaveAndReflesh
Return UnsafeNativeMethods.SPIF_UPDATEINIFILE Or UnsafeNativeMethods.SPIF_SENDWININICHANGE
End Select
End Function
Public Enum UpdateType
''' <summary>
''' 保存设置,重启系统后有效
''' </summary>
Save = 1
''' <summary>
''' 更新设置,本次有效,重启系统后无效
''' </summary>
Reflesh = 2
''' <summary>
''' 保存设置并生效
''' </summary>
SaveAndReflesh = 3
End Enum
End Class
'没全部测试。在我的简单测试中,SaveOnly都会Reflesh了。
Public Class Demo
Public Shared Sub RefleshOnly()
DesktopWallpaper.Change("c: /test.bmp", DesktopWallpaper.UpdateType.Reflesh)
End Sub
Public Shared Sub SaveOnly()
DesktopWallpaper.Change("c:/ test.bmp", DesktopWallpaper.UpdateType.Save)
End Sub
Public Shared Sub Update()
DesktopWallpaper.Change("c:/ test.bmp", DesktopWallpaper.UpdateType.SaveAndReflesh)
End Sub
Public Shared Sub Clear()
DesktopWallpaper.Clear(DesktopWallpaper.UpdateType.SaveAndReflesh)
End Sub
End Class
- HOW TO:墙纸设置
- 设置墙纸
- 设置Windows墙纸
- 设置墙纸(可用htm,bmp)
- HOW TO:设置默认打印机
- 如何在程序中动态设置墙纸
- 如何在程序中动态设置墙纸
- 如何在程序中动态设置墙纸
- 如何在程序中动态设置墙纸
- 如何在程序中动态设置墙纸
- 将Android Activity背景设置为墙纸
- 如何在程序中动态设置墙纸
- android2.3 Launcher墙纸设置代码追踪
- PAIP.在程序中设置壁纸墙纸
- OnLongClickListener长按事件设置墙纸
- 如何在程序中动态设置墙纸
- Launcher App:墙纸太大造成设置墙纸时产生“OutOfMemoryError: bitmap size exceeds VM budget”
- 为JEdit设置墙纸(add wallpaper for jedit)
- 看看黑客如何破解MS SQL SERCVER密码
- 分析 病毒杀不死的原因
- hibernate的父子关系及inverse
- TabPage
- Nokia N70与PC的连接问题
- HOW TO:墙纸设置
- [原创]SXU (Software Extreme Usage)挖掘软件的潜力--极端使用-用最少的软件做最多的事
- 希望我们仍然是朋友
- [原创]侯佩日记摘录之一:2000年10月x日
- One Piece!
- 今天正式入侵Csdn博客
- oracle查看权限
- PHP对象中的 方法回调
- Business English 商务一点通