Option Explicit
Private Sub cmbBrowse_Click()
With CommonDialog1 .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly Or cdlOFNLongNames Or cdlOFNExplorer .FileName = txtFilename.Text .ShowOpen If .FileName <> "" Then txtFilename.Text = .FileName End With End Sub
Private Sub cmdChange_Click()
Dim style As WPSTYLE If optStyle(2).Value Then style = WPSTYLE_STRETCH ElseIf optStyle(1).Value Then style = WPSTYLE_TILE Else style = WPSTYLE_CENTER End If SetActiveDesktopWallpaper txtFilename.Text, style, (chkForce.Value = vbChecked) End Sub
Private Sub cmdExit_Click() Unload Me End Sub
Private Sub Form_Load()
Dim ad As ActiveDesktop Dim sCurrentFile As String Dim wpo As WALLPAPEROPT wpo.dwSize = Len(wpo) sCurrentFile = String$(260, 0) ' check current options Set ad = New ActiveDesktop ad.GetWallpaper sCurrentFile, 260, 0 ad.GetWallpaperOptions wpo, 0 Set ad = Nothing txtFilename.Text = sCurrentFile optStyle(wpo.dwStyle And &H3&).Value = True End Sub
'' '' Sub SetActiveDesktopWallpaper '' '' sFileName: [in] Path to the new wallpaper '' lStyle: [in] Wallpaper style flag (center/stretch/tile) '' fForce: [in] Enables Active Desktop if it's currently disabled '' Private Sub SetActiveDesktopWallpaper(ByVal sFileName As String, ByVal lStyle As Long, ByVal fForce As Boolean)
Dim ad As ActiveDesktop Dim co As COMPONENTSOPT Dim wpo As WALLPAPEROPT Set ad = New ActiveDesktop ' check if AD is enabled co.dwSize = Len(co) ad.GetDesktopItemOptions co, 0& If (co.fActiveDesktop = 0) And fForce Then co.fActiveDesktop = 1 ad.SetDesktopItemOptions co, 0& End If With wpo .dwSize = Len(wpo) .dwStyle = lStyle End With With ad ' set wallpaper style... .SetWallpaperOptions wpo, 0& ' ... and wallpaper path .SetWallpaper sFileName, 0& ' finally, save changes .ApplyChanges AD_APPLY_ALL End With Set ad = Nothing End Sub