Författaren till den fetmarkerade koden skriver att bakgrundsbilden skall bytas ut men det gör den inte. Jag ser att skrivbordet blinkar till när jag kör mitt program men bilden byts inte ut förrän jag trycker F5. Kan ni se vad som är fel?
Länk till källkoden på vbcity: Force Background Reload
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
[b]Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, _
ByVal uParam As Long, _
ByVal lpvParam As String, _
ByVal fuWinIni As Long) As Long
Public Const SPI_SETDESKWALLPAPER = 20
Public Const SPIF_UPDATEINIFILE = &H1
Public Const SPIF_SENDWININICHANGE = &H2[/b]
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(104, 0)
Me.Name = "Form1"
Me.Opacity = 0
Me.ShowInTaskbar = False
Me.WindowState = FormWindowState.Minimized
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CopyImage()
End Sub
[b]Function ChangeWallpaper(ByVal Filename As String)
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, Filename, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Function[/b]
Private Sub CopyImage()
Dim ArrVars(2)
ArrVars(0) = "c:\desktopimages\"
ArrVars(1) = "c:\desktopimages\collection\"
ArrVars(2) = "\desktopimager.jpg"
Dim Dir As Directory
If File.Exists(Dir.GetCurrentDirectory & "\config.cfg") Then
Dim SR As StreamReader = New StreamReader(Dir.GetCurrentDirectory & "\config.cfg")
Dim StrCfg As String = Trim(SR.ReadLine) : SR.Close()
If Int(Len(StrCfg)) = 0 Then File.Delete(Dir.GetCurrentDirectory & "\config.cfg") : GoTo NoCfg
If Dir.Exists(StrCfg) Then : ArrVars(1) = StrCfg
Else
If Dir.Exists(Mid(StrCfg, 1, 2)) And Not Int(Len(StrCfg)) = 2 Then
Dir.CreateDirectory(StrCfg)
ArrVars(1) = StrCfg
End If
End If
End If
NoCfg:
If Dir.Exists(ArrVars(0)) Then
DirExists:
If Dir.Exists(ArrVars(1)) Then
CollectorExists:
Dim ArrFiles = Dir.GetFiles(ArrVars(1), "*.jpg")
If Int(UBound(ArrFiles)) > -1 Then
Randomize()
File.Copy(ArrFiles(Int(Rnd() * (UBound(ArrFiles) + 1))), ArrVars(0) & ArrVars(2), True)
End If
Else
Dir.CreateDirectory(ArrVars(1)) : GoTo CollectorExists
End If
Else
Dir.CreateDirectory(ArrVars(0)) : GoTo DirExists
End If
[b]ChangeWallpaper("c:\desktopimages\desktopimager.jpg")[/b]
Application.Exit()
End Sub
End Class
