I am using a filelistbox to display a list of files for a user to choose from. Is there a mechanism whereby I can be alerted when the contents of the directory change say, by a user adding or deleting files from the displayed directory?
regards
jim murray
You could always add a timer and refresh the control periodically.
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Const WM_SETREDRAW = &HB
Private Sub Timer1_Timer()
SendMessage Me.hwnd, WM_SETREDRAW, 0, 0
File1.Refresh
SendMessage Me.hwnd, WM_SETREDRAW, 1, 0
End Sub
"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
Actually I think I found a better solution, take a look at the FindChangeNotification API. Basically you monitor the folder for changes and when a change occurs call the File1.Refresh method.
"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
Bizarre. I know we've posted FindFirstChangeNotification solutions in this forum in the past (I've posted at least two), but I can't seem to find any of them. All I can find is my code in thread222-719707, which contains synchronous and asynchronous versions of a ReadDirectoryChangesW solution (which may not becompletely appropriate for this question, but does have the advantage of provding the exact file change that occurred and the name of the file the change occurred to)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.