Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Monitoring changes in a directory
Retrieving top-child window for the VFP form
Using FrameRgn for displaying system colors
Creating a device context for the specified printer
How to drag a Form not using its Titlebar or Caption
Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)
Displaying OS Memory Status
Displaying the main Dial-Up Networking dialog box
GDI+: Storing DLL icon resources in image files
How to retrieve version information for the specified file
Reading parameters of streams in AVI file
Connecting a local device to a network resource
Using Multimedia Command Strings to play MIDI files
Using Shell for performing operations on files
Displaying hypertext links with the SysLink control (VFP9, Comctl32.dll)
Displaying printer-properties Property Sheet for the specified printer
Pocket PC: custom RAPI class for operating with files and folders on mobile device
Reading and setting explicit Application User Model ID for the current process (Win7)
Drawing Windows frame controls using the DrawFrameControl function
GDI+: reading and writing metadata in JPEG and TIFF files
How to display the Print property sheet
HOWTO: Use the Win32 API to Access File Dates and Times
Number of clipboard formats available
Changing file attributes
Monitoring changes in a directory

User rating: 9/10 (1 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
Imagine that an application needs to be notified upon file changes in a particular directory: files added or deleted, changed, or accessed. The ChangeNotification function is an answer.

After starting this code sample, try to add, change or delete files in the target directory (must be valid path). Create a FoxPro table in it and operate with its records.

See also::
  • FileSystemWatcher ActiveX Control for Visual FoxPro
  • Monitoring changes occurring within a directory
  • Enumerating files opened on the network
  • PUBLIC oForm
    oForm = CREATEOBJECT("Tform", SYS(2023)) && watching TEMP dir
    oForm.Visible = .T.
    * end of main
    
    DEFINE CLASS Tform As Form
    #DEFINE FILE_NOTIFY_CHANGE_FILE_NAME 1
    #DEFINE FILE_NOTIFY_CHANGE_DIR_NAME 2
    #DEFINE FILE_NOTIFY_CHANGE_ATTRIBUTES 4
    #DEFINE FILE_NOTIFY_CHANGE_SIZE 8
    #DEFINE FILE_NOTIFY_CHANGE_LAST_WRITE 16
    #DEFINE FILE_NOTIFY_CHANGE_LAST_ACCESS 32
    #DEFINE FILE_NOTIFY_CHANGE_CREATION 64
    #DEFINE FILE_NOTIFY_CHANGE_SECURITY 128
    #DEFINE INVALID_HANDLE_VALUE -1
    #DEFINE WAIT_OBJECT_0 0
    #DEFINE WATCHING_INTERVAL 1000  && milliseconds
    
    PROTECTED hNotify, PathBeingWatched
    
        Width=400
        Height=150
        MaxButton=.F.
        BorderStyle=2
        AutoCenter=.T.
        Caption="Watching directory"
    
        hNotify=INVALID_HANDLE_VALUE
        PathBeingWatched=""
    
        ADD OBJECT lblTarget As Label WITH Left=10, Top=7, Autosize=.T.
        ADD OBJECT tm As Timer WITH Interval=0
    
        ADD OBJECT lblAlert As Label WITH Left=10, Top=30,;
        Autosize=.T., Caption="Notification:"
    
    FUNCTION Init(cPath)
        THIS.declare
        THIS.PathBeingWatched = FULLPATH(m.cPath)
    
        IF Not THIS.StartWatching()
            = MESSAGEBOX("Notification handle error.")
            RETURN .F.
        ENDIF
    
    PROCEDURE Destroy
        THIS.StopWatching
    
    PROTECTED FUNCTION StartWatching
        LOCAL lResult
    
        * no subdirs watched
        THIS.hNotify = FindFirstChangeNotification(;
            THIS.PathBeingWatched, 0,;
            FILE_NOTIFY_CHANGE_FILE_NAME +;
            FILE_NOTIFY_CHANGE_LAST_WRITE )
    
        lResult = (THIS.hNotify <> INVALID_HANDLE_VALUE)
    
        IF lResult
            THIS.lblTarget.Caption = "Watched: " +;
                THIS.PathBeingWatched
            THIS.tm.Interval = WATCHING_INTERVAL
        ENDIF
    RETURN  lResult
    
    PROTECTED PROCEDURE ContinueWatching
        IF FindNextChangeNotification(THIS.hNotify) = 0
            THIS.StopWatching
            = MESSAGEBOX("Request error.")
            THIS.Release
        ENDIF
        THIS.tm.Interval = WATCHING_INTERVAL
    
    PROTECTED FUNCTION StopWatching
        THIS.tm.Interval = 0
        IF THIS.hNotify <> INVALID_HANDLE_VALUE
            = FindCloseChangeNotification(THIS.hNotify)
        ENDIF
    
    FUNCTION _signaled        && returns signaled state
    RETURN (WaitForSingleObject(THIS.hNotify, 0) = WAIT_OBJECT_0)
    
    PROCEDURE _notify        && triggered on event
        LOCAL cMessage
        cMessage = "Notification: " + TTOC(DATETIME())
        THIS.lblAlert.Caption = cMessage
        ACTIVATE SCREEN
        ? cMessage
        THIS.ContinueWatching
    
    PROCEDURE tm.Timer
        IF ThisForm._signaled()
            ThisForm._notify
        ENDIF
    
    PROTECTED PROCEDURE declare
        DECLARE SHORT FindNextChangeNotification IN kernel32;
            INTEGER hChangeHandle
    
        DECLARE SHORT FindCloseChangeNotification IN kernel32;
            INTEGER hChangeHandle
    
        DECLARE INTEGER FindFirstChangeNotification IN kernel32;
            STRING lpPathName, INTEGER bWatchSubtree,;
            INTEGER dwNotifyFilter
    
        DECLARE INTEGER WaitForSingleObject IN kernel32;
            INTEGER hHandle, INTEGER dwMilliseconds
    
    ENDDEFINE
    
    
    

    User rating: 9/10 (1 votes)
    Rate this code sample:
    • ~
    2819 bytes  
    Created: 2001-08-23 12:00:00  
    Modified: 2011-02-16 13:28:43  
    Visits in 7 days: 135  
    Listed functions:
    FindCloseChangeNotification
    FindFirstChangeNotification
    FindNextChangeNotification
    WaitForSingleObject
    Printer friendly API declarations
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright 2001-2018 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.91.16.95)
    3 sec.Function: 'FtpRenameFile'
    Function group: 'Internet Functions (WinInet)'
    5 sec.Function: 'WSAWaitForMultipleEvents'
    Function group: 'Windows Sockets 2 (Winsock)'
    6 sec.Function: 'mmioAscend'
    Function group: 'Windows Multimedia'
    8 sec.Example: 'Moving shortcut to a specified position on the Windows Desktop'
    11 sec.
    Function group: 'Process and Thread'
    13 sec.Function: 'CryptGetHashParam'
    Function group: 'Cryptography Reference'
    15 sec.Function: 'NetServerEnum'
    Function group: 'Network Management'
    17 sec.Function: 'FtpGetCurrentDirectory'
    Function group: 'Internet Functions (WinInet)'
    20 sec.Function: 'SCardGetProviderId'
    Function group: 'Authentication'
    22 sec.Function: 'waveInOpen'
    Function group: 'Windows Multimedia'
    Google
    Advertise here!