|
-
Feb 15th, 2009, 03:24 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2008] Force a refresh of all Win Explorer windows showing a particular folder
The application I'm developing does some file management chores, such as renaming and deletion of files. I have noticed that often after a file is deleted via code, it is still shown in Windows Explorer although it doesn't exist anymore. A refresh (F5) solves this, however I wouldn't want end users to have to press F5 every couple of minutes when using the application.
Can a refresh of all open Windows Explorer windows be requested via code? Moreover, can the refresh be requested only for windows displaying a particular location?
I've thought of getting all open windows, filtering them and then sending the F5 keystroke, however it sounds a bit like overkill. Any easier way to do it?
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Feb 15th, 2009, 03:40 PM
#2
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
Here you go. This should do it;
Code:
<DllImport("shell32.dll")> _
Shared Sub SHChangeNotify( _
ByVal wEventID As HChangeNotifyEventID, _
ByVal uFlags As HChangeNotifyFlags, _
ByVal dwItem1 As IntPtr, _
ByVal dwItem2 As IntPtr)
End Sub
<Flags()> _
Public Enum HChangeNotifyFlags
SHCNF_DWORD = &H3
SHCNF_IDLIST = &H0
SHCNF_PATHA = &H1
SHCNF_PATHW = &H5
SHCNF_PRINTERA = &H2
' SHCNF_PRINTERW = &H6
SHCNF_FLUSH = &H1000
SHCNF_FLUSHNOWAIT = &H2000
End Enum
<Flags()> _
Public Enum HChangeNotifyEventID
SHCNE_ALLEVENTS = &H7FFFFFFF
SHCNE_ASSOCCHANGED = &H8000000
SHCNE_ATTRIBUTES = &H800
SHCNE_CREATE = &H2
SHCNE_DELETE = &H4
SHCNE_DRIVEADD = &H10
SHCNE_DRIVEADDGUI = &H10000
SHCNE_DRIVEREMOVED = &H80
SHCNE_EXTENDED_EVENT = &H4000000
SHCNE_FREESPACE = &H40000
SHCNE_MEDIAINSERTED = &H20
SHCNE_MEDIAREMOVED = &H40
SHCNE_MKDIR = &H8
SHCNE_NETSHARE = &H200
SHCNE_NETUNSHARE = &H400
SHCNE_RENAMEFOLDER = &H20000
SHCNE_RENAMEITEM = &H1
SHCNE_RMDIR = &H10
SHCNE_SERVERDISCONNECT = &H4000
SHCNE_UPDATEDIR = &H1000
SHCNE_UPDATEIMAGE = &H8000
End Enum
Call it like this.
Code:
SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero)
It will refresh the Explorer windows regardless of their current directory however, but good enough I think.
-
Feb 15th, 2009, 05:07 PM
#3
Thread Starter
Frenzied Member
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
The refresh works fine for all Windows Explorer windows, however it doesn't refresh the desktop. This means that the issue persists for all files residing on the desktop. Any way to solve that?
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Feb 15th, 2009, 05:12 PM
#4
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
Try this;
Code:
SHChangeNotify(&H8000000, &H0, 0, 0)
If that does not work let me know, I have some other API code knocking around.
Last edited by Bulldog; Feb 15th, 2009 at 05:17 PM.
-
Feb 16th, 2009, 10:55 AM
#5
Thread Starter
Frenzied Member
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Feb 16th, 2009, 11:15 AM
#6
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
Hmm.. that previous code works for me, in that case try;
SHChangeNotify(&H8000000, &H1000, 0, 0)
Another one is this;
Code:
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
'Call it as follows
InvalidateRect( 0&, 0&, False)
Last edited by Bulldog; Feb 16th, 2009 at 11:18 AM.
-
Feb 16th, 2009, 04:30 PM
#7
Thread Starter
Frenzied Member
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
InvalidateRect will fail at runtime, False cannot be converted to Long like that. I will try the SHChangeNotify method and report back.
I'm using Windows Vista if that is of any importance.
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Feb 16th, 2009, 04:32 PM
#8
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
Both
SHChangeNotify(&H8000000, &H0, 0, 0)
and
SHChangeNotify(&H8000000, &H1000, 0, 0)
work for me. The second is the more thorough however.
-
Feb 17th, 2009, 10:40 AM
#9
Thread Starter
Frenzied Member
Re: [2008] Force a refresh of all Win Explorer windows showing a particular folder
Ok I've just tried it a couple more times and the desktop was refreshed, but only sporadically. It seems that although the code by itself is ok, a refresh is sometimes prevented. However, it's good enough for now I think. Thank you for your help. Cheers!
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|