Refresh Screen 100 POINTS

Any code out there for refreshing the desktop screen/icons ? Would like a little working code if possible ?
Thanks
rockroad
rockroadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
The UpdateWindow API will send a WM_PAINT message to the specified window handle. To update the desktop, you need to use the GetDesktopWindow API in conjunction with this API.

Declare the following in a MODULE:

   Declare Function GetDesktopWindow Lib "user32" () As Long
   Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long


Then you can do:

UpdateWindow GetDesktopWindow



Hope this helps!


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VBGuruCommented:
copy and paste the following code to the form and click on the form to refresh the desktop
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, _
lpRect As Any, ByVal bErase As Long) As Long

Private Sub Form_Click()
InvalidateRect 0, ByVal 0, 0
End Sub

0
mcriderCommented:
By the way, this code will first erase the desktop and then redraw it...


Put the following in a MODULE:

Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Public Const RDW_ALLCHILDREN = &H80
Public Const RDW_ERASE = &H4
Public Const RDW_ERASENOW = &H200
Public Const RDW_FRAME = &H400
Public Const RDW_INTERNALPAINT = &H2
Public Const RDW_INVALIDATE = &H1
Public Const RDW_NOCHILDREN = &H40
Public Const RDW_NOERASE = &H20
Public Const RDW_NOFRAME = &H800
Public Const RDW_NOINTERNALPAINT = &H10
Public Const RDW_UPDATENOW = &H100
Public Const RDW_VALIDATE = &H8
Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, lprcUpdate As RECT, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long



Put this in your program:

Dim X As RECT
X.Top = 0
X.Bottom = Screen.Height
X.Left = 0
X.Right = Screen.Width
RedrawWindow 0&, X, 0&, RDW_ERASE Or RDW_INVALIDATE _
    Or RDW_ERASENOW Or RDW_UPDATENOW Or RDW_ALLCHILDREN
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mcriderCommented:
By the way (again)... The documentation for the RedrawWindow API can be found here:

http://msdn.microsoft.com/library/psdk/gdi/pantdraw_81pz.htm 
 

Cheers!
0
rockroadAuthor Commented:
Hey All, sorry i'm late been busy. The code worked fine. Thanks to everyone who participated !
rockroad
0
rockroadAuthor Commented:
Hey mcrider, I know i have accepted your answer but after testing the code it doesn't seem to work. When i run my little program, it changes an icon on the desktop. When the desktop refreshes via your code, it does not change the icon image unless you reboot the computer. I am using windows95 and vb 5.0
Any suggestions would be appreciated. I have 60 more points i will award you if you get this fixed for me ?
rockroad
0
mcriderCommented:
Did you try the code that I posted that erases and redraws the desktop??


Cheers!
0
rockroadAuthor Commented:
Hey mcrider, thanks for getting back with me! Yes i tried the code both ways. The icon that i want to show the change once it happens from my program is a "shortcut" which is already on the desktop. Would this make a difference in what i need ? If i reboot, the change shows in the icon shortcut. I need some code which will update this change immediately if this is possible ?
Thanks Again
rockroad
0
mcriderCommented:
The code I gave you does refresh the desktop... But that's not what you're looking for.

What you're trying to do is send an F5 key to the desktop to trigger a Icon reload...  I'm not quite sure how to do that... Sorry.


Cheers!
0
rockroadAuthor Commented:
mcrider, thanks ! I at least know now what to ask for:) I will post it and see what happens. If you figure out how to do it look for the posting!
Thanks Again
rockroad
0
mcriderCommented:
rockroad,

I saw your new question, you may want to edit the question to say something like:

"UpdateWindow, InvalidateRect and RedrawWindow only redraw the desktop window and do not update Icons... If you focus on the desktop and press F5, the desktop is repainted and, if any icons on the desktop have changed, they are updated."


Cheers!

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.