?
Solved

Refresh Screen 100 POINTS

Posted on 1999-12-21
11
Medium Priority
?
180 Views
Last Modified: 2010-05-02
Any code out there for refreshing the desktop screen/icons ? Would like a little working code if possible ?
Thanks
rockroad
0
Comment
Question by:rockroad
  • 6
  • 4
11 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 400 total points
ID: 2299708
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
 
LVL 6

Expert Comment

by:VBGuru
ID: 2299717
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2299738
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 14

Expert Comment

by:mcrider
ID: 2299747
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
 

Author Comment

by:rockroad
ID: 2300796
Hey All, sorry i'm late been busy. The code worked fine. Thanks to everyone who participated !
rockroad
0
 

Author Comment

by:rockroad
ID: 2301251
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2301794
Did you try the code that I posted that erases and redraws the desktop??


Cheers!
0
 

Author Comment

by:rockroad
ID: 2301896
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2302092
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
 

Author Comment

by:rockroad
ID: 2302151
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2302167
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question