⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 folderwatcher.h

📁 c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++6.0
💻 H
字号:
//////////////////////////////////////////////////////////////////////
// FileFury
// Copyright (c) 2000 Tenebril Incorporated
// All rights reserved.
//
// This source code is governed by the Tenebril open source
// license (http://www.tenebril.com/developers/opensource/license.html)
//
// For more information on this and other open source applications,
// visit the Tenebril OpenSource page:
//       http://www.tenebril.com/developers/opensource
//
//////////////////////////////////////////////////////////////////////

#if !defined FOLDER_WATCHER_H
#define FOLDER_WATCHER_H
//------------------------------------
//  FolderWatcher.h
//  (c) Reliable Software, 1997
//------------------------------------

#include "ActiveObject.h"
#include "WinExcept.h"

class FileChangeEvent
{
public:
    FileChangeEvent (char const * folder, BOOL recursive, DWORD notifyFlags)
    {
        _handle = FindFirstChangeNotification (folder, recursive, notifyFlags);
        if (INVALID_HANDLE_VALUE == _handle)
            throw WinException ("Cannot create change notification handle");
    }
    ~FileChangeEvent ()
    {
        if (INVALID_HANDLE_VALUE != _handle)
            FindCloseChangeNotification (_handle);
    }

    operator HANDLE () const { return _handle; }
    BOOL ContinueNotification ()
    {
        return FindNextChangeNotification (_handle);
    }

private:
    HANDLE _handle;
};

class FolderChangeEvent : public FileChangeEvent
{
public:
    FolderChangeEvent (char const * folder)
        : FileChangeEvent (folder, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME)
    {}
};

class TreeChangeEvent : public FileChangeEvent
{
public:
    TreeChangeEvent (char const * root)
        : FileChangeEvent (root, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME)
    {}
};

UINT const WM_FOLDER_CHANGE = WM_USER;

class FolderWatcher : public ActiveObject
{
public:
    FolderWatcher (char const * folder, HWND hwnd)
        : _notifySource (folder),
          _hwndNotifySink (hwnd)
    {
        strcpy (_folder, folder);
        _thread.Resume ();
    }
    ~FolderWatcher ()
    {
        Kill ();
    }

private:
    void InitThread () {}
    void Loop ();
    void FlushThread () {}

    FolderChangeEvent _notifySource;
    HWND _hwndNotifySink;
    char _folder [MAX_PATH];
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -