Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Starting an external application in VFP using WinExec
Using MessageBeep
Winsock: retrieving the host information corresponding to a network address
Adding and deleting User Accounts
Displaying standard progress dialog box when copying files
Downloading files from the FTP server using InternetReadFile
Enumerating print processors and supporting data types installed on the specified server
How to retrieve version information for the specified file
Locking mouse and keyboard input for the VFP application
Retrieveing information about the active window (even if it is not owned by the calling process)
String representation for disk or memory capacity
Displaying hypertext links with the SysLink control (VFP9, Comctl32.dll)
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
Retrieving the command line for the VFP session
How to browse and connect to printers on a network (WinNT)
How to play AVI file on the _screen
Quering a waveform-audio input device
Starting a dialog box for connecting to network resources (mapping network drive)
Winsock: initializing the service in the VFP application
Winsock: retrieving information from a host database for a given host name
How to position the GETPRINTER() dialog
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Validating URLs using moniker functions
Disconnecting USB Mass Storage Device programmatically
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: 87  
    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 (107.22.127.92)
    1.47 hrs.Example: 'Retrieving top-child window for the VFP form'
    9.97 hrs.Example: 'Winsock: initializing the service in the VFP application'
    12.64 hrs.Function: 'WTSUnRegisterSessionNotification'
     Example: 'How to intercept window messages sent to VFP form'
    19.86 hrs.Example: 'Using Multimedia Command Strings to play MIDI files'
     Example: 'Displaying dimmed window behind VFP top-level form'
    1 day(s)Function: 'GdipFillRectangle'
     Function: 'EnumServicesStatus'
    Function group: 'Service'
     Example: 'How to print a bitmap file'
     Function: 'InternetCheckConnection'
    Google
    Advertise here!