投稿日 | : 2003/05/09(Fri) 17:50 |
投稿者 | : シャフト |
Eメール | : |
URL | : |
タイトル | : Re^3: 同じ処理を複数起動する方法 |
あまり良い方法ではないのかもしれませんがタイマーを使用してみました。(100ms)
Command1(0),Command1(1),Command1(2),Command1(3)がフォルダtest1,test2,test3,test4
の監視を開始する為のボタンです。
Command2で監視を停止します。
Option Explicit
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Const INVALID_HANDLE_VALUE = -1
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const WAIT_OBJECT_0 As Long = 0
Private bSurvey() As Boolean
Private NotificationHandle() As Long
Private Sub Command1_Click(Index As Integer)
If Not bSurvey(Index%) Then
NotificationHandle(Index%) = FindFirstChangeNotification("E:\software\test" & CStr(Index% + 1), False, FILE_NOTIFY_CHANGE_FILE_NAME)
If NotificationHandle(Index%) = INVALID_HANDLE_VALUE Then
Call MsgBox("Notificate Start Error")
Exit Sub
End If
bSurvey(Index%) = True
End If
End Sub
Private Sub Command2_Click()
Dim i As Integer
For i% = 0 To 3
If bSurvey(i%) Then
Call FindCloseChangeNotification(NotificationHandle(i%))
bSurvey(i%) = False
End If
Next i%
End Sub
Private Sub Form_Load()
ReDim bSurvey(3) As Boolean
ReDim NotificationHandle(3) As Long
Me.Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
Dim lRet As Long
For i% = 0 To 3
If bSurvey(i%) Then
lRet& = WaitForSingleObject(NotificationHandle(i%), 0)
If lRet& = WAIT_OBJECT_0 Then
Call MsgBox("Notify!")
Call FindNextChangeNotification(NotificationHandle(i%))
End If
End If
Next i%
End Sub