Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
How to download a file from the FTP server using FtpGetFile
Detecting changes in connections to removable drives (VFP9)
Enumerating data formats currently available on the clipboard
How to play AVI file on the _screen
Winsock: sending email messages (SMTP, port 25)
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Custom FTP Class for Visual FoxPro application
Custom HttpRequest class (WinHTTP)
Deleting files into the Recycle Bin
Creating the Open dialog box to specify the drive, directory, and name of a file to open
How to activate Windows Calculator
Custom HttpRequest class (WinINet)
Splash Screen for the VFP application
Using Font and Text functions
Mapping and disconnecting network drives
How to display the Properties dialog box for a file (ShellExecuteEx)
Establishing connection using the SQLDriverConnect
How to convert a bitmap file to monochrome format (1 bpp)
Using EnumPrinters function to enumerate locally installed printers
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: 101  
    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-2013 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.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.234.231.49)
    4 sec.Function: 'GdipSetMatrixElements'
    1.19 hrs.Example: 'Encapsulating access to the Windows Services in a class'
     Example: 'Retrieving long values associated with the class of the VFP window'
    1.3 hrs.
    Function group: 'Registry'
    1.31 hrs.
    2.56 hrs.Function: 'GetSystemDefaultLCID'
    Function group: 'National Language Support'
    10.64 hrs.Example: 'Retrieving the name of the primary domain controller (PDC) and join status information (NT/2000/XP)'
    10.77 hrs.Example: 'Quering a waveform-audio input device'
    19.19 hrs.Example: 'How to change the name and the size of the font in the MessageBox dialog'
     Example: 'Creating a device context for the specified printer'
    Google
    Advertise here!