Link to home
Start Free TrialLog in
Avatar of microboard
microboard

asked on

Refresh the desktop

I can change the recycle bin icon in my program, but to get it to take effect, I have to type F5. I have used every bit of code I can think of, including the API for refreshing the desktop, but nothing will simulate the F5 key without physically typing it. Can anyone help in this matter?
Avatar of Erick37
Erick37
Flag of United States of America image

Try this (if you haven't already):

SendMessage HWND_BROADCAST, WM_WININICHANGE, SPI_SETICONMETRICS, 0


The following code simulates the F5 key...

...
dim c1 as long

c1=FindWindowEx(FindWindowEx(FindWindow("Progman","Program
Manager"),0,"SHELLDLL_DefView",""),0,"SysListView32","")

call PostMessage(c1,WM_KEYDOWN,VK_F5,0)
call PostMessage(c1,WM_KEYUP,VK_F5, 2^31)
...

that should do it...

..-=ViKtOr=-..
Avatar of microboard
microboard

ASKER

viktornet the code you gave doesnt seem to have any effect.

Erick37 the code you sent causes the screen to repaint itself but not to simulate the F5 key; that is, to update itself. This seems to be a very big problem. I'll add another 100 points on to this question then since it seems to be harder than I thought..

thanks
could you show me the exact code you used? and did you declare the API functions?
How about trying the SendKeys command passing "{F5}" as a parameter?

microboard, try

call PostMessage(c1,WM_KEYDOWN,VK_F5,0)
     call PostMessage(c1,WM_KEYUP,VK_F5, 0)

instead of

call PostMessage(c1,WM_KEYDOWN,VK_F5,0)
     call PostMessage(c1,WM_KEYUP,VK_F5, 2^31)

and tell me how that works..
I am sure there is a registry setting you can modify which makes the desktop refresh itself every 10ms or so... can't quite remember where it is.
Here is a link to a very simple program which adds shortcuts to the desktop, and then refreshes the desktop.

http://www.thescarms.com/VBasic/Shortcuts.htm

It uses the following APIs to refresh the desktop:

' Refresh the desktop to display the shortcut.
            '
            Call SHGetSpecialFolderLocationD(Me.hwnd, CSIDL_DESKTOP, lpil)
            Call SHChangeNotify(SHCNE_ALLEVENTS, SHCNF_IDLIST, lpil, 0)

I'm sure with a little modification, this could work.

Try this:|

SetForegroundWindow(GetDesktopWindow())
SendKeys("{F5}")


I have code that will kill the explorer, then it will automatically restart itself.  There are some side effects though, all of the tray icons are emptied out (the startup folder is not re-processed).

If you want to see if this will work, press ctrl+alt+del.  Then end the 'Explorer' task.  If the shut down windows box pops up, press cancel.  Then when the 'End Task' box comes up press 'End Task'.  This will kill the explorer and it will automatically refresh itself.  If this fixed your problem let me know and I will post the code.
microboard, try this one
To Simulate F5 key

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2

keybd_event 115, 31, 0, 0                'key down
keybd_event 115, 31, KEYEVENTF_KEYUP, 0  'key up

Viktornet your new code did refresh the desktop, but again the same problem as before: nothing is being updated. You would think Windows would have made a simple API just to handle the updating of the desktop. I know they have the UpdateWindow but it doesnt do anything but refresh as well

Erick37 thanks for your tip but no good on that. The code isnt actually updateing the desktop but setting in something new, which doesnt affect anything else. But it was a good idea.

MikeP no go on the code.

setiawan, nice twist to the code you posted, but sorry to say it didnt even refresh the screen.

plasmatek, yes your right about the refreshing, but that's all it does. It doesnt update.

As for the code I'm using: when I try new code, I only have that particular code I'm testing in use. There is not anything else to hinder it.
ASKER CERTIFIED SOLUTION
Avatar of setiawan
setiawan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Setiawan. Your code did the trick.
It's not worth the code... 2 pages of code for simple refresh... get outta here... :))
GREETINGS!

This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange