Guidance
指路人
g.yi.org
software / rapidq / Examples / Tools - IDE, Designer, Builder / FreeQ IDE src / inc ide / FileMonitor.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $IFNDEF __FREEQ_LEAN


      CONST FILE_NOTIFY_CHANGE_FLAGS_ALL = &H1 OR &H2 OR &H4 OR &H8 OR &H10 OR &H100

      SUB SetFileChangeMonitor(TargetPath AS STRING , CheckSubDir AS INTEGER, Flags AS INTEGER)
       IF Flags = 0 THEN Flags = FILE_NOTIFY_CHANGE_FLAGS_ALL
       IF IDE.FileMonitorHook <> -1 THEN
        ClearFileChangeMonitor
       END IF
       IDE.FileMonitorHook = FindFirstChangeNotification(TargetPath ,CheckSubDir ,Flags)
      END SUB


      FUNCTION CheckFileChangeMonitor () AS LONG
       IF IDE.FileMonitorHook <> -1 THEN               'if not invalid handle
        IF (WaitForSingleObject(IDE.FileMonitorHook , 0) = 0) THEN
         CheckFileChangeMonitor = True
    '            ClearFileChangeMonitor
    '            SetFileChangeMonitor fcmTemp.Path , fcmTemp.CheckSub , fcmTemp.Flags
        ELSE
         CheckFileChangeMonitor = False
        END IF
       END IF
      END FUNCTION


      SUB ClearFileChangeMonitor
       IF NOT (IDE.FileMonitorHook = 0) THEN
        FindCloseChangeNotification IDE.FileMonitorHook           'Clear the hook
        IDE.FileMonitorHook = 0
       END IF
      END SUB

      FUNCTION WaitFileChangeMonitor(TimeOut AS LONG) AS LONG         'if TimeOut = -1 THEN waits forever
       IF NOT (IDE.FileMonitorHook = 0) THEN
        'Wait for the event
        WaitFileChangeMonitor = WaitForSingleObject(IDE.FileMonitorHook , TimeOut)

        'Reset the file monitor hook
'        ClearFileChangeMonitor
'        SetFileChangeMonitor Monitor , fcmTemp.Path , fcmTemp.CheckSub , fcmTemp.Flags
       END IF
      END FUNCTION
'
''sample
'DIM fsStream as QFileStream
'fsStream.Open("crap.txt" , fmCreate)
'fsStream.WriteLine "asdfasdf"
'SetFileChangeMonitor ("C:\RapidQ\IDE\FreeQ\inc_ide", False, FILE_NOTIFY_CHANGE_ATTRIBUTES)
'
''Do some stuff
'DO
''Check to see if a file has changed in the meantime
'Loop UNTIL CheckFileChangeMonitor
'
'Showmessage "you messin with me?"    'do something else here
'
''Wait for another file to change
''WaitFileChangeMonitor(5600)
'
''Do some more stuff
'
''clean up when done
'ClearFileChangeMonitor

     $ENDIF
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-20  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-12-07 21:18:03