Refreshing the Desktop Wallpaper?

G

gregory_may

I need to refresh the desktop wallpaper (Its getting corrupted by a 3rd
party application). Is there a better way than this (This is working, but
it makes me nervous ... it should be simpler)?:

Dim UserWallpaper As String = RegValue(RegistryHive.CurrentUser, "Control
Panel\Desktop", "Wallpaper")

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, UserWallpaper,
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)



It seems like there should be another function that will just refresh the
window without me having to dig the information out of the registry .... any
thoughts?
 
D

Dragon

Hello,

It seems like there should be another function that will just refresh the
window without me having to dig the information out of the registry ..... any
thoughts?

I'm not sure if this will help... but the RedrawWindow function with
hWnd set to IntPtr.Zero will redraw desktop window.

Friend Overloads Declare Function RedrawWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByRef lprcUpdate As RECT, _
ByVal hrgnUpdate As Int32, _
ByVal fuRedraw As Int32 _
) As Boolean
Friend Overloads Declare Function RedrawWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal lprcUpdate As IntPtr, _
ByVal hrgnUpdate As Int32, _
ByVal fuRedraw As Int32 _
) As Boolean

HTH

Roman
 
G

gregory_may

Thanks Dragon:
Below is what I am using from your post. I dont see a "flicker" or
anything, not shure if I have the right "RDW"
constants. Does this look right?

Public Structure User32_RECT 'Seems to work .. not sure if right
Dim Left As Int16
Dim Top As Int16
Dim Right As Int16
Dim Bottom As Int16
End Structure

Public Const RDW_INVALIDATE As Int16 = &H1

Friend Overloads Declare Function RedrawWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByRef lprcUpdate As User32_RECT, _
ByVal hrgnUpdate As Int32, _
ByVal fuRedraw As Int32 _
) As Boolean
Friend Overloads Declare Function RedrawWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal lprcUpdate As IntPtr, _
ByVal hrgnUpdate As Int32, _
ByVal fuRedraw As Int32 _
) As Boolean


Code to Repaint:

Dim MyRect As New User32_RECT
Debug.WriteLine(RedrawWindow(New System.IntPtr(0), MyRect, 0,
RDW_INVALIDATE).ToString)

Returns "True"
 
D

Dragon

A few comments:

RECT's fields are Int32's as well as RDW_INVALIDATE.
IntPtr.Zero is more convenient in my opinion than New IntPtr(0), however
it depends on your liking.
hrgnUpdate is actually IntPtr (my fault — sorry).

Wonder why I included overloaded version of RedrawWindow?
If you want to redraw entire window, you should pass NULL to lprcUpdate,
however you can't do this if it is declared ByRef (by passing New RECT,
as you do, you shouldn't achieve anything). So substitute IntPtr.Zero
for lprcUpdate, and you'll probably get desired result.

I also believe that you have to include RDW_UPDATENOW in fuRedraw.

Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top