Don't worry
here 's the code
try it
this code is useful if you are trying to change desktop wallpaper
That is ,if "Show Web Content " is enabled for active desktop you should refresh desktop in order to change the wallpaper.
By using the API systemparameter info and using this code you can change the wallpaper with very ease.There are somany codes to refresh the desktop in this forums.but they only redraw the desktop icons .
They can't really refresh the desktop. please use this and tell me any modifications required etc, thankyou
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_COMMAND As Long = &H111
Private Const MIN_ALL As Long = 419
Private Const MIN_ALL_UNDO As Long = 416
Const SW_SHOWNORMAL = 1
Const VK_F5 = &H74
Const KEYEVENTF_KEYUP = &H2
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Dim a As Integer, b As Integer
Dim cname As String
Dim cp As POINTAPI
Dim rval As Long
Private Sub Form_Load()
rval = GetCursorPos(cp)
If a = 0 Then a = cp.x
If b = 0 Then b = cp.y
SetCursorPos 5, 5
Me.Hide
Timer1.Enabled = True
Timer1.Interval = 10
End Sub
Public Sub refreshdesktop()
mouse_event &H2, 0, 0, 0, 0
mouse_event &H4, 0, 0, 0, 0
keybd_event &H74, 0, 0, 0
keybd_event &H74, 0, KEYEVENTF_KEYUP, 0
Restore
SetCursorPos a, b
Unload Me
End
End Sub
Private Sub Timer1_Timer()
Dim hwnd As Long
Dim name As String
rval = GetCursorPos(cp)
hwnd = WindowFromPoint(cp.x, cp.y)
cname = Space(128)
rval = GetClassName(hwnd, cname, 128)
Form1.Caption = Left(cname, InStr(cname, Chr(0)) - 1)
name = Left(cname, InStr(cname, Chr(0)) - 1)
Minimize
If name = "Internet Explorer_Server" Then refreshdesktop
If name = "SysListView32" Then refreshdesktop
End Sub
Private Sub Minimize()
Dim r As Long
r = FindWindow("Shell_TrayWnd", vbNullString)
Call PostMessage(r, WM_COMMAND, MIN_ALL, 0&)
End Sub
Private Sub Restore()
Dim r As Long
r = FindWindow("Shell_TrayWnd", vbNullString)
Call PostMessage(r, WM_COMMAND, MIN_ALL_UNDO, 0&)
End Sub
Perhaps this is more efficient, I got this on this forum but don't remember source.
Code:
Public 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
Public Const SPI_SCREENSAVERRUNNING = 97
Public Const SPI_SETDESKWALLPAPER = 20
Public Const SPIF_SENDWININICHANGE = &H2
Public Const SPIF_UPDATEINIFILE = &H1
Call SystemParametersInfo(SPI_SETDESKWALLPAPER, True, "C:\Test.bmp", SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
To change the wallpaper you can use the code you 've given
But ,if "show web content" ,(that is when you right click
on the desktop)is enabled .the desktop should be refreshed
to so that new wallpaper is displayed.
so the code which i've given should be used after you use
your code.then only new wallpaper will be displayed otherwise you
should restart your computer.
let me make it clear again
1.my code is not used to change wallpaper it will only
refresh desktop
2. It should be used after you call 'systemparameter info'