Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Displaying standard progress dialog box when copying files
Enumerating sessions established on a server
How to create a desktop shortcut (shell link)
How to display advanced Task Dialog (Vista)
How to generate GUID values
How to retrieve adapter information for the local computer (including MAC address)
How to retrieve configuration data for a specified printer stored in the registry (PrinterDriverData key)
Retrieving IP statistics for the computer
Winsock: creating a socket that is bound to a specific service provider
Converting twips to pixels and vice versa
Enumerating devices installed on the local machine
Finding out if the current user is the Guest account
Passing data records between VFP applications via the Clipboard
Reading data from INI files
How to block the ALT+TAB shortcut (WinXP)
How to run FoxPro application under different user name (impersonating user)
PocketPC: custom RAPI class for executing routines on remote Windows CE device
Quering a waveform-audio input device
System and Local Time values
A class that encrypts and decrypts files using Cryptography API Functions
Displaying all TCP connections for the local system
GDI+: Creating thumbnails to preview images in a directory
How to display the port-configuration dialog box for a port on the specified server
Pocket PC: custom RAPI class for operating with the Object Store Databases
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: 69  
    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.21.156.140)
    39.77 min.Function: 'FreeEnvironmentStrings'
    Function group: 'Process and Thread'
    39.8 min.Example: 'How to retrieve version information for the specified file'
    1.47 hrs.Example: 'How to disable the Windows Clipboard (VFP9)'
     Example: 'Enumerating Performance Counters'
     Example: 'Retrieving the name of the primary domain controller (PDC) and join status information (NT/2000/XP)'
    2.02 hrs.Function: 'InternetAttemptConnect'
    Function group: 'Internet Functions (WinInet)'
     
    2.35 hrs.Example: 'How to display Windows On-Screen Keyboard'
    2.36 hrs.Function: 'SHGetSpecialFolderLocation'
    Function group: 'Shell Functions'
     Example: 'Enumerating print processors and supporting data types installed on the specified server'
    Google
    Advertise here!