Browse Source

简单的Windows文件监控示例

Jeff 6 years ago
parent
commit
eadca4efff

+ 74 - 0
FileWatcher/FileWatcher.cpp

@@ -0,0 +1,74 @@
+// FileWatcher.cpp : Defines the class behaviors for the application.
+//
+
+#include "stdafx.h"
+#include "FileWatcher.h"
+#include "FileWatcherDlg.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherApp
+
+BEGIN_MESSAGE_MAP(CFileWatcherApp, CWinApp)
+	//{{AFX_MSG_MAP(CFileWatcherApp)
+		// NOTE - the ClassWizard will add and remove mapping macros here.
+		//    DO NOT EDIT what you see in these blocks of generated code!
+	//}}AFX_MSG
+	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherApp construction
+
+CFileWatcherApp::CFileWatcherApp()
+{
+	// TODO: add construction code here,
+	// Place all significant initialization in InitInstance
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// The one and only CFileWatcherApp object
+
+CFileWatcherApp theApp;
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherApp initialization
+
+BOOL CFileWatcherApp::InitInstance()
+{
+	AfxEnableControlContainer();
+
+	// Standard initialization
+	// If you are not using these features and wish to reduce the size
+	//  of your final executable, you should remove from the following
+	//  the specific initialization routines you do not need.
+
+#ifdef _AFXDLL
+	Enable3dControls();			// Call this when using MFC in a shared DLL
+#else
+	Enable3dControlsStatic();	// Call this when linking to MFC statically
+#endif
+
+	CFileWatcherDlg dlg;
+	m_pMainWnd = &dlg;
+	int nResponse = dlg.DoModal();
+	if (nResponse == IDOK)
+	{
+		// TODO: Place code here to handle when the dialog is
+		//  dismissed with OK
+	}
+	else if (nResponse == IDCANCEL)
+	{
+		// TODO: Place code here to handle when the dialog is
+		//  dismissed with Cancel
+	}
+
+	// Since the dialog has been closed, return FALSE so that we exit the
+	//  application, rather than start the application's message pump.
+	return FALSE;
+}

+ 150 - 0
FileWatcher/FileWatcher.dsp

@@ -0,0 +1,150 @@
+# Microsoft Developer Studio Project File - Name="FileWatcher" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=FileWatcher - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "FileWatcher.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "FileWatcher.mak" CFG="FileWatcher - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "FileWatcher - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "FileWatcher - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "FileWatcher - Win32 Release"
+
+# PROP BASE Use_MFC 6
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 6
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yu"stdafx.h" /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
+# ADD RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
+# ADD LINK32 /nologo /subsystem:windows /machine:I386
+
+!ELSEIF  "$(CFG)" == "FileWatcher - Win32 Debug"
+
+# PROP BASE Use_MFC 6
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 6
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /Yu"stdafx.h" /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
+# ADD RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "FileWatcher - Win32 Release"
+# Name "FileWatcher - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\FileWatcher.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\FileWatcher.rc
+# End Source File
+# Begin Source File
+
+SOURCE=.\FileWatcherDlg.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\StdAfx.cpp
+# ADD CPP /Yc"stdafx.h"
+# End Source File
+# Begin Source File
+
+SOURCE=.\Watcher.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\FileWatcher.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\FileWatcherDlg.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Resource.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\StdAfx.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Watcher.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\res\FileWatcher.rc2
+# End Source File
+# Begin Source File
+
+SOURCE=.\res\Icon.ico
+# End Source File
+# End Group
+# End Target
+# End Project

+ 49 - 0
FileWatcher/FileWatcher.h

@@ -0,0 +1,49 @@
+// FileWatcher.h : main header file for the FILEWATCHER application
+//
+
+#if !defined(AFX_FILEWATCHER_H__D4C6B482_3739_4E6E_B8EA_D8DD1FA74887__INCLUDED_)
+#define AFX_FILEWATCHER_H__D4C6B482_3739_4E6E_B8EA_D8DD1FA74887__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#ifndef __AFXWIN_H__
+	#error include 'stdafx.h' before including this file for PCH
+#endif
+
+#include "resource.h"		// main symbols
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherApp:
+// See FileWatcher.cpp for the implementation of this class
+//
+
+class CFileWatcherApp : public CWinApp
+{
+public:
+	CFileWatcherApp();
+
+// Overrides
+	// ClassWizard generated virtual function overrides
+	//{{AFX_VIRTUAL(CFileWatcherApp)
+	public:
+	virtual BOOL InitInstance();
+	//}}AFX_VIRTUAL
+
+// Implementation
+
+	//{{AFX_MSG(CFileWatcherApp)
+		// NOTE - the ClassWizard will add and remove member functions here.
+		//    DO NOT EDIT what you see in these blocks of generated code !
+	//}}AFX_MSG
+	DECLARE_MESSAGE_MAP()
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_FILEWATCHER_H__D4C6B482_3739_4E6E_B8EA_D8DD1FA74887__INCLUDED_)

+ 228 - 0
FileWatcher/FileWatcher.rc

@@ -0,0 +1,228 @@
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// Chinese (P.R.C.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
+#ifdef _WIN32
+LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
+#pragma code_page(936)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "#include ""afxres.h""\r\n"
+    "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
+    "#define _AFX_NO_OLE_RESOURCES\r\n"
+    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
+    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
+    "\r\n"
+    "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)\r\n"
+    "#ifdef _WIN32\r\n"
+    "LANGUAGE 4, 2\r\n"
+    "#pragma code_page(936)\r\n"
+    "#endif //_WIN32\r\n"
+    "#include ""res\\FileWatcher.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
+    "#include ""l.chs\\afxres.rc""          // Standard components\r\n"
+    "#endif\r\n"
+    "\0"
+END
+
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_ABOUTBOX DIALOG DISCARDABLE  0, 0, 235, 41
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "关于 FileWatcher"
+FONT 9, "宋体"
+BEGIN
+    ICON            IDR_MAINFRAME,IDC_STATIC,7,7,21,21
+    LTEXT           "FileWatcher 1.0 版",IDC_STATIC,40,10,119,8,SS_NOPREFIX
+    LTEXT           "版权所有 (C) 2009",IDC_STATIC,40,25,78,8
+    DEFPUSHBUTTON   "确定",IDOK,178,7,50,14,WS_GROUP
+END
+
+IDD_FILEWATCHER_DIALOG DIALOGEX 0, 0, 320, 235
+STYLE WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_APPWINDOW
+CAPTION "FileWatcher"
+FONT 9, "宋体", 0, 0, 0x1
+BEGIN
+    EDITTEXT        IDC_EDIT_PATH,7,214,249,14,ES_CENTER | ES_AUTOHSCROLL | 
+                    ES_READONLY
+    PUSHBUTTON      "开始",IDC_BTN_CTRL,263,214,50,14
+    CONTROL         "List1",IDC_LIST_DATA,"SysListView32",LVS_REPORT | 
+                    LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | 
+                    WS_BORDER | WS_TABSTOP,7,7,306,201
+END
+
+
+#ifndef _MAC
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,1
+ PRODUCTVERSION 1,0,0,1
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "080404b0"
+        BEGIN
+            VALUE "Comments", "\0"
+            VALUE "CompanyName", "\0"
+            VALUE "FileDescription", "FileWatcher Microsoft 基础类应用程序\0"
+            VALUE "FileVersion", "1, 0, 0, 1\0"
+            VALUE "InternalName", "FileWatcher\0"
+            VALUE "LegalCopyright", "版权所有 (C) 2009\0"
+            VALUE "LegalTrademarks", "\0"
+            VALUE "OriginalFilename", "FileWatcher.EXE\0"
+            VALUE "PrivateBuild", "\0"
+            VALUE "ProductName", "FileWatcher 应用程序\0"
+            VALUE "ProductVersion", "1, 0, 0, 1\0"
+            VALUE "SpecialBuild", "\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x804, 1200
+    END
+END
+
+#endif    // !_MAC
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO DISCARDABLE 
+BEGIN
+    IDD_ABOUTBOX, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 228
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 34
+    END
+
+    IDD_FILEWATCHER_DIALOG, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 313
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 228
+    END
+END
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDR_MNU_POP MENU DISCARDABLE 
+BEGIN
+    POPUP "菜单"
+    BEGIN
+        MENUITEM "打开目标",                    IDR_MNU_OPEN
+        MENUITEM SEPARATOR
+        MENUITEM "删除数据",                    IDR_MNU_DELSEL
+        MENUITEM "删除所有",                    IDR_MNU_DELALL
+    END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDR_MAINFRAME           ICON    DISCARDABLE     "res\\Icon.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE DISCARDABLE 
+BEGIN
+    IDS_ABOUTBOX            "关于 FileWatcher(&A)..."
+END
+
+#endif    // Chinese (P.R.C.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+#define _AFX_NO_SPLITTER_RESOURCES
+#define _AFX_NO_OLE_RESOURCES
+#define _AFX_NO_TRACKER_RESOURCES
+#define _AFX_NO_PROPERTY_RESOURCES
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
+#ifdef _WIN32
+LANGUAGE 4, 2
+#pragma code_page(936)
+#endif //_WIN32
+#include "res\FileWatcher.rc2"  // non-Microsoft Visual C++ edited resources
+#include "l.chs\afxres.rc"          // Standard components
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+#endif    // not APSTUDIO_INVOKED
+

+ 20 - 0
FileWatcher/FileWatcher.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileWatcher", "FileWatcher.vcproj", "{E3DE76B5-21FB-4541-A67E-5EC95D3756D5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E3DE76B5-21FB-4541-A67E-5EC95D3756D5}.Debug|Win32.ActiveCfg = Debug|Win32
+		{E3DE76B5-21FB-4541-A67E-5EC95D3756D5}.Debug|Win32.Build.0 = Debug|Win32
+		{E3DE76B5-21FB-4541-A67E-5EC95D3756D5}.Release|Win32.ActiveCfg = Release|Win32
+		{E3DE76B5-21FB-4541-A67E-5EC95D3756D5}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 360 - 0
FileWatcher/FileWatcher.vcproj

@@ -0,0 +1,360 @@
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="FileWatcher"
+	ProjectGUID="{E3DE76B5-21FB-4541-A67E-5EC95D3756D5}"
+	Keyword="MFCProj"
+	TargetFrameworkVersion="0"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory=".\Release"
+			IntermediateDirectory=".\Release"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+			UseOfMFC="2"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="NDEBUG"
+				MkTypLibCompatible="true"
+				SuppressStartupBanner="true"
+				TargetEnvironment="1"
+				TypeLibraryName=".\Release/FileWatcher.tlb"
+				HeaderFileName=""
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				StringPooling="true"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="stdafx.h"
+				PrecompiledHeaderFile=".\Release/FileWatcher.pch"
+				AssemblerListingLocation=".\Release/"
+				ObjectFile=".\Release/"
+				ProgramDataBaseFileName=".\Release/"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="2052"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile=".\Release/FileWatcher.exe"
+				LinkIncremental="1"
+				SuppressStartupBanner="true"
+				ProgramDatabaseFile=".\Release/FileWatcher.pdb"
+				SubSystem="2"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+				SuppressStartupBanner="true"
+				OutputFile=".\Release/FileWatcher.bsc"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory=".\Debug"
+			IntermediateDirectory=".\Debug"
+			ConfigurationType="1"
+			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+			UseOfMFC="2"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="_DEBUG"
+				MkTypLibCompatible="true"
+				SuppressStartupBanner="true"
+				TargetEnvironment="1"
+				TypeLibraryName=".\Debug/FileWatcher.tlb"
+				HeaderFileName=""
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="stdafx.h"
+				PrecompiledHeaderFile=".\Debug/FileWatcher.pch"
+				AssemblerListingLocation=".\Debug/"
+				ObjectFile=".\Debug/"
+				ProgramDataBaseFileName=".\Debug/"
+				BrowseInformation="1"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="2052"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile=".\Debug/FileWatcher.exe"
+				LinkIncremental="2"
+				SuppressStartupBanner="true"
+				GenerateDebugInformation="true"
+				ProgramDatabaseFile=".\Debug/FileWatcher.pdb"
+				SubSystem="2"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+				SuppressStartupBanner="true"
+				OutputFile=".\Debug/FileWatcher.bsc"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+			>
+			<File
+				RelativePath="FileWatcher.cpp"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="FileWatcher.rc"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCResourceCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCResourceCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="FileWatcherDlg.cpp"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="StdAfx.cpp"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="Watcher.cpp"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						PreprocessorDefinitions=""
+					/>
+				</FileConfiguration>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl"
+			>
+			<File
+				RelativePath="FileWatcher.h"
+				>
+			</File>
+			<File
+				RelativePath="FileWatcherDlg.h"
+				>
+			</File>
+			<File
+				RelativePath="Resource.h"
+				>
+			</File>
+			<File
+				RelativePath="StdAfx.h"
+				>
+			</File>
+			<File
+				RelativePath="Watcher.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+			>
+			<File
+				RelativePath="res\FileWatcher.rc2"
+				>
+			</File>
+			<File
+				RelativePath="res\Icon.ico"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

+ 572 - 0
FileWatcher/FileWatcherDlg.cpp

@@ -0,0 +1,572 @@
+// FileWatcherDlg.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "FileWatcher.h"
+#include "FileWatcherDlg.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CAboutDlg dialog used for App About
+
+class CAboutDlg : public CDialog
+{
+public:
+	CAboutDlg();
+
+// Dialog Data
+	//{{AFX_DATA(CAboutDlg)
+	enum { IDD = IDD_ABOUTBOX };
+	//}}AFX_DATA
+
+	// ClassWizard generated virtual function overrides
+	//{{AFX_VIRTUAL(CAboutDlg)
+	protected:
+	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
+	//}}AFX_VIRTUAL
+
+// Implementation
+protected:
+	//{{AFX_MSG(CAboutDlg)
+	//}}AFX_MSG
+	DECLARE_MESSAGE_MAP()
+};
+
+CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
+{
+	//{{AFX_DATA_INIT(CAboutDlg)
+	//}}AFX_DATA_INIT
+}
+
+void CAboutDlg::DoDataExchange(CDataExchange* pDX)
+{
+	CDialog::DoDataExchange(pDX);
+	//{{AFX_DATA_MAP(CAboutDlg)
+	//}}AFX_DATA_MAP
+}
+
+BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
+	//{{AFX_MSG_MAP(CAboutDlg)
+		// No message handlers
+	//}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherDlg dialog
+
+CFileWatcherDlg::CFileWatcherDlg(CWnd* pParent /*=NULL*/)
+	: CDialog(CFileWatcherDlg::IDD, pParent)
+{
+	//{{AFX_DATA_INIT(CFileWatcherDlg)
+	m_csStrPath = _T("");
+	//}}AFX_DATA_INIT
+	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
+	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
+}
+
+void CFileWatcherDlg::DoDataExchange(CDataExchange* pDX)
+{
+	CDialog::DoDataExchange(pDX);
+	//{{AFX_DATA_MAP(CFileWatcherDlg)
+	DDX_Control(pDX, IDC_LIST_DATA, m_csListData);
+	DDX_Control(pDX, IDC_EDIT_PATH, m_csEdtPath);
+	DDX_Control(pDX, IDC_BTN_CTRL, m_csBtnCtrl);
+	DDX_Text(pDX, IDC_EDIT_PATH, m_csStrPath);
+	//}}AFX_DATA_MAP
+}
+
+BEGIN_MESSAGE_MAP(CFileWatcherDlg, CDialog)
+	//{{AFX_MSG_MAP(CFileWatcherDlg)
+	ON_WM_SYSCOMMAND()
+	ON_WM_PAINT()
+	ON_WM_QUERYDRAGICON()
+	ON_NOTIFY(NM_RCLICK, IDC_LIST_DATA, OnRclickListData)
+	ON_COMMAND(IDR_MNU_OPEN, OnMnuOpen)
+	ON_COMMAND(IDR_MNU_DELSEL, OnMnuDelsel)
+	ON_COMMAND(IDR_MNU_DELALL, OnMnuDelall)
+	ON_BN_CLICKED(IDC_BTN_CTRL, OnBtnCtrl)
+	ON_WM_SIZE()
+	//}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherDlg message handlers
+
+BOOL CFileWatcherDlg::OnInitDialog()
+{
+	CDialog::OnInitDialog();
+
+	// Add "About..." menu item to system menu.
+
+	// IDM_ABOUTBOX must be in the system command range.
+	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
+	ASSERT(IDM_ABOUTBOX < 0xF000);
+
+	CMenu* pSysMenu = GetSystemMenu(FALSE);
+	if (pSysMenu != NULL)
+	{
+		CString strAboutMenu;
+		strAboutMenu.LoadString(IDS_ABOUTBOX);
+		if (!strAboutMenu.IsEmpty())
+		{
+			pSysMenu->AppendMenu(MF_SEPARATOR);
+			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
+		}
+	}
+
+	// Set the icon for this dialog.  The framework does this automatically
+	//  when the application's main window is not a dialog
+	SetIcon(m_hIcon, TRUE);			// Set big icon
+	SetIcon(m_hIcon, FALSE);		// Set small icon
+	
+	//=======> 初始化标识符
+	this->m_bStart = FALSE;
+	//======> 初始化视图控件
+	this->InitializeListCtrl();
+	//======> 创建托盘图标
+	this->NotifyTray(TRUE);
+	//=====> 窗口置顶
+	this->SetWindowPos(&this->wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
+	
+	return TRUE;  // return TRUE  unless you set the focus to a control
+}
+
+void CFileWatcherDlg::OnSysCommand(UINT nID, LPARAM lParam)
+{
+	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
+	{
+		CAboutDlg dlgAbout;
+		dlgAbout.DoModal();
+	}
+	else
+	{
+		CDialog::OnSysCommand(nID, lParam);
+	}
+}
+
+// If you add a minimize button to your dialog, you will need the code below
+//  to draw the icon.  For MFC applications using the document/view model,
+//  this is automatically done for you by the framework.
+
+void CFileWatcherDlg::OnPaint() 
+{
+	if (IsIconic())
+	{
+		CPaintDC dc(this); // device context for painting
+
+		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
+
+		// Center icon in client rectangle
+		int cxIcon = GetSystemMetrics(SM_CXICON);
+		int cyIcon = GetSystemMetrics(SM_CYICON);
+		CRect rect;
+		GetClientRect(&rect);
+		int x = (rect.Width() - cxIcon + 1) / 2;
+		int y = (rect.Height() - cyIcon + 1) / 2;
+
+		// Draw the icon
+		dc.DrawIcon(x, y, m_hIcon);
+	}
+	else
+	{
+		CDialog::OnPaint();
+	}
+}
+
+// The system calls this to obtain the cursor to display while the user drags
+//  the minimized window.
+HCURSOR CFileWatcherDlg::OnQueryDragIcon()
+{
+	return (HCURSOR) m_hIcon;
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】初始化视图列表控件
+//【参数】无
+//【描述】创建栏目,设置扩展样式
+void CFileWatcherDlg::InitializeListCtrl()
+{
+	this->m_csListData.InsertColumn(0, "时间", LVCFMT_LEFT, 75);
+	this->m_csListData.InsertColumn(1, "动作", LVCFMT_LEFT, 50);
+	this->m_csListData.InsertColumn(2, "类型", LVCFMT_LEFT, 75);
+	this->m_csListData.InsertColumn(3, "信息", LVCFMT_LEFT, 500);
+
+	//========> 设置扩展样式
+	this->m_csListData.SetExtendedStyle(
+		LVS_EX_GRIDLINES |
+		LVS_EX_FULLROWSELECT |
+		LVS_EX_FLATSB 
+		);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】选择目录路径
+//【参数】无
+//【描述】调用SH函数,弹出目录选择对话框,选择目录
+CString CFileWatcherDlg::SelectPath()
+{
+	BROWSEINFO stBrowseInfo;  
+	ITEMIDLIST *lpstIDLst = NULL;
+	char szPath[MAX_PATH] = {0};
+   
+	//===========> 初始化结构
+	stBrowseInfo.hwndOwner = this->m_hWnd;  
+	stBrowseInfo.pidlRoot = NULL;  
+	stBrowseInfo.pszDisplayName = NULL;
+	stBrowseInfo.lpszTitle = "请选择目录";  
+	stBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;  
+	stBrowseInfo.lpfn = NULL;  
+	stBrowseInfo.lParam = 0;  
+	stBrowseInfo.iImage = 0;
+
+	//=======> 弹出目录选择对话框
+	if ((lpstIDLst = ::SHBrowseForFolder(&stBrowseInfo)) == FALSE)
+	{
+		return "";
+	}
+	//========> 取得目录路径
+	if (::SHGetPathFromIDList(lpstIDLst, szPath) == FALSE)
+	{
+		return "";
+	}
+
+	return szPath;
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】创建程序托盘
+//【参数】bCreate 如果TRUE,创建托盘,反之销毁托盘
+//【描述】为程序创建托盘,显示在任务栏下方
+BOOL CFileWatcherDlg::NotifyTray(BOOL bCreate)
+{
+	NOTIFYICONDATA stNotify = {0};
+
+	stNotify.cbSize = sizeof(NOTIFYICONDATA);
+	stNotify.hIcon = this->m_hIcon;
+	stNotify.hWnd = this->GetSafeHwnd();
+	strcpy(stNotify.szTip, "目录监控程序(双击显示窗口)");
+	stNotify.uCallbackMessage = WM_MY_NOTIFY;
+	stNotify.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
+	stNotify.uID = IDR_MAINFRAME;
+
+	if (bCreate == TRUE)
+	{
+		return ::Shell_NotifyIcon(NIM_ADD, &stNotify);
+	}
+	return ::Shell_NotifyIcon(NIM_DELETE, &stNotify);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】视图控件右击过程
+//【参数】略
+//【描述】右击的是否显示弹出菜单
+void CFileWatcherDlg::OnRclickListData(NMHDR* pNMHDR, LRESULT* pResult) 
+{
+	*pResult = 0;
+	CMenu csMenu;
+	POINT stPos = {0};
+
+	//======> 取得当前鼠标位置
+	::GetCursorPos(&stPos);
+
+	//====> 加载资源菜单
+	csMenu.LoadMenu(IDR_MNU_POP);
+	//===========> 判断是否选中有项目
+	if (this->m_csListData.GetSelectionMark() == -1)
+	{
+		csMenu.EnableMenuItem(IDR_MNU_OPEN, MF_GRAYED);
+		csMenu.EnableMenuItem(IDR_MNU_DELSEL, MF_GRAYED);
+	}
+	//==========> 判断是否存在项目
+	if (this->m_csListData.GetItemCount() == 0)
+	{
+		csMenu.EnableMenuItem(IDR_MNU_DELALL, MF_GRAYED);
+	}
+	//======> 弹出菜单
+	csMenu.GetSubMenu(0)->TrackPopupMenu(
+		TPM_LEFTALIGN,
+		stPos.x,
+		stPos.y,
+		this);	
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】菜单“打开”过程
+//【参数】略
+//【描述】打开视图控件缓冲区中的路径
+void CFileWatcherDlg::OnMnuOpen() 
+{
+	int nItem = 0;
+	DWORD dwAct = 0;
+	CString csStrShell, csStrInfo;
+	HINSTANCE hInst = NULL;
+
+	this->UpdateData();
+
+	nItem = this->m_csListData.GetSelectionMark();
+	dwAct = this->m_csListData.GetItemData(nItem);
+	switch (dwAct)
+	{
+	case CWatcher::actRenameNew:
+		{
+			//=======> 取得内容
+			csStrInfo = this->m_csListData.GetItemText(nItem, 3);
+			//======== 计算路径
+			csStrShell = 
+				this->m_csStrPath + 
+				"\\" + 
+				csStrInfo.Mid(csStrInfo.Find(" -> ", 0), csStrInfo.GetLength());
+		}
+		break;
+	case CWatcher::actRemote:
+		{
+			MessageBox("你会数据恢复吗?");
+			// 返回
+			return;
+		}
+		break;
+	case CWatcher::actCreate:
+	case CWatcher::actChange:
+		{
+			//======> 计算路径
+			csStrShell = 
+				this->m_csStrPath + 
+				"\\" + 
+				this->m_csListData.GetItemText(nItem, 3);
+		}
+		break;
+	}		
+	//======> 打开
+	hInst = ::ShellExecute(NULL, 
+		"open", 
+		csStrShell,
+		NULL,
+		NULL,
+		SW_SHOWNORMAL);
+	if (hInst == NULL)
+	{
+		MessageBox("你当我是生产队?");
+	}
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】菜单“删除选择”过程
+//【参数】略
+//【描述】删除视图控件当前选中的项目
+void CFileWatcherDlg::OnMnuDelsel() 
+{
+	this->m_csListData.DeleteItem(
+		this->m_csListData.GetSelectionMark()
+		);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】菜单“删除所有”过程
+//【参数】略
+//【描述】删除视图控件所有项目
+void CFileWatcherDlg::OnMnuDelall() 
+{
+	this->m_csListData.DeleteAllItems();
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】开始\结束目录监视
+//【参数】略
+//【描述】调用CWatcher::Create开始创建目录监视
+void CFileWatcherDlg::OnBtnCtrl() 
+{
+	this->UpdateData();
+
+	if (this->m_bStart == FALSE)
+	{
+		if (this->m_csWatcher.Create(this->m_csStrPath) == FALSE)
+		{
+			this->MessageBox("监视目录失败");
+		}
+		else
+		{
+			this->m_bStart = TRUE;
+			this->m_csEdtPath.EnableWindow(FALSE);
+			this->m_csBtnCtrl.SetWindowText("停止");
+		}
+	}
+	else
+	{
+		this->m_csWatcher.Destroy();
+		this->m_bStart = FALSE;
+		this->m_csEdtPath.EnableWindow(TRUE);
+		this->m_csBtnCtrl.SetWindowText("开始");
+	}
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】未转换的消息处理过程
+//【参数】略
+//【描述】继承此虚拟函数来处理,在Edit里面的双击事件
+BOOL CFileWatcherDlg::PreTranslateMessage(MSG* pMsg) 
+{
+	if (pMsg->message == WM_LBUTTONDBLCLK)
+	{
+		if (pMsg->hwnd == this->m_csEdtPath.m_hWnd)
+		{
+			//=========> 判断是否已经开始
+			if (this->m_bStart == FALSE)
+			{
+				//======> 取得选中目录纪路径
+				this->m_csEdtPath.SetWindowText(this->SelectPath());
+			}
+		}
+	}
+	return CDialog::PreTranslateMessage(pMsg);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】消息处理过程
+//【参数】略
+//【描述】继承此虚拟函数来处理,在托盘里面的双击事件
+LRESULT CFileWatcherDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
+{
+	if (message == WM_MY_NOTIFY)
+	{
+		if (lParam == WM_LBUTTONDBLCLK)
+		{
+			//=====> 显示窗口
+			ShowWindow(SW_RESTORE);
+			//=====> 激活窗口
+			SetForegroundWindow();
+		}
+	}
+	return CDialog::WindowProc(message, wParam, lParam);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】程序退出过程
+//【参数】略
+//【描述】删除了调用基类的OnOK事件,以免按回车退出程序
+void CFileWatcherDlg::OnOK()
+{
+	// CDialog::OnOK() 取消了此事件
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】程序退出过程
+//【参数】略
+//【描述】退出时候,弹出消息框,提示用户时候退出。销毁监视,删除托盘图标
+void CFileWatcherDlg::OnCancel()
+{
+	if (::AfxMessageBox("你是否要退出程序?", MB_YESNO | MB_ICONSTOP) == IDYES)
+	{
+		this->NotifyTray(FALSE);
+		this->m_csWatcher.Destroy();
+		CDialog::OnCancel();
+	}
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】窗口尺寸改变过程
+//【参数】略
+//【描述】主要利用此过程完成程序最小化的时候隐藏
+void CFileWatcherDlg::OnSize(UINT nType, int cx, int cy) 
+{
+	CDialog::OnSize(nType, cx, cy);
+	
+	if (nType == SIZE_MINIMIZED)
+	{
+		this->ShowWindow(SW_HIDE);
+	}
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】判断是否是一个文件夹
+//【参数】lpszPath 判断路径
+//【描述】取得文件夹属性,然后,与 比较,返回
+BOOL CFileWatcherDlg::IsFolder(LPCTSTR lpszPath)
+{
+	DWORD dwAttrib = 0;
+	dwAttrib = GetFileAttributes(lpszPath);
+	return (dwAttrib != -1) && 
+		((dwAttrib & FILE_ATTRIBUTE_DIRECTORY)?TRUE:FALSE);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】监控过程
+//【参数】dwAction 动作类型。csStrName1, csStrName2 相关名称
+//【描述】处理动作,不要调用Destroy。来自CWatcher转发
+void CFileWatcherDlg::OnWatch(DWORD dwAct, CString csStrName1, CString csStrName2)
+{
+	CString csStrTime, csStrAct, csStrType, 
+		csStrPath , csStrInfo;
+	int nItem = 0;
+
+	//=======> 取得时间
+	csStrTime = ::CTime::GetCurrentTime().Format("%H:%M:%S");
+	//=========> 取得全路径
+	csStrPath = m_csStrPath + "\\" + csStrName1; // Only 1
+	//========> 判断类型,生成字符串
+	if (this->IsFolder(csStrPath) == TRUE)
+	{
+		csStrType = "文件夹";
+	}
+	else
+	{
+		csStrType = "文件";
+	}
+
+	//==========> 判断类型
+	switch (dwAct)
+	{
+	case CWatcher::actCreate:
+		{
+			csStrAct = "创建";
+			csStrInfo = csStrName1;
+		}
+		break;
+	case CWatcher::actRemote:
+		{
+			csStrAct = "删除";
+			csStrInfo = csStrName1;
+		}
+		break;
+	case CWatcher::actRenameNew:
+		{
+			csStrAct = "重命";
+			csStrInfo = csStrName1 + " -> " + csStrName2;
+		}
+		break;
+	case CWatcher::actChange:
+		{
+			csStrAct = "更改";
+			csStrInfo = csStrName1;
+		}
+		break;
+	}
+	
+	//============> 添加信息到视图控件
+	nItem = this->m_csListData.InsertItem(0, csStrTime);
+	this->m_csListData.SetItemText(nItem, 1, csStrAct);
+	this->m_csListData.SetItemText(nItem, 2, csStrType);
+	this->m_csListData.SetItemText(nItem, 3, csStrInfo);
+	//=========> 保存动作到控件内部 
+	this->m_csListData.SetItemData(nItem, dwAct);
+}
+

+ 73 - 0
FileWatcher/FileWatcherDlg.h

@@ -0,0 +1,73 @@
+// FileWatcherDlg.h : header file
+//
+
+#if !defined(AFX_FILEWATCHERDLG_H__CA611DDF_62C0_4DC0_B787_57E4F6F8B4A8__INCLUDED_)
+#define AFX_FILEWATCHERDLG_H__CA611DDF_62C0_4DC0_B787_57E4F6F8B4A8__INCLUDED_
+
+#include "Watcher.h"	// Added by ClassView
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+/////////////////////////////////////////////////////////////////////////////
+// CFileWatcherDlg dialog
+
+#define WM_MY_NOTIFY		WM_USER + 100
+
+class CFileWatcherDlg : public CDialog
+{
+// Construction
+public:
+	BOOL m_bStart;
+	BOOL IsFolder(LPCTSTR lpszPath);
+	void OnWatch(DWORD dwAct, CString csStrName1, CString csStrName2);
+	BOOL NotifyTray(BOOL bCreate);
+	CString SelectPath();
+	void InitializeListCtrl();
+	CWatcher m_csWatcher;
+	CFileWatcherDlg(CWnd* pParent = NULL);	// standard constructor
+
+// Dialog Data
+	//{{AFX_DATA(CFileWatcherDlg)
+	enum { IDD = IDD_FILEWATCHER_DIALOG };
+	CListCtrl	m_csListData;
+	CEdit	m_csEdtPath;
+	CButton	m_csBtnCtrl;
+	CString	m_csStrPath;
+	//}}AFX_DATA
+
+	// ClassWizard generated virtual function overrides
+	//{{AFX_VIRTUAL(CFileWatcherDlg)
+	public:
+	virtual BOOL PreTranslateMessage(MSG* pMsg);
+	protected:
+	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
+	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
+	//}}AFX_VIRTUAL
+
+// Implementation
+protected:
+	HICON m_hIcon;
+
+	// Generated message map functions
+	//{{AFX_MSG(CFileWatcherDlg)
+	virtual BOOL OnInitDialog();
+	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
+	afx_msg void OnPaint();
+	afx_msg HCURSOR OnQueryDragIcon();
+	afx_msg void OnRclickListData(NMHDR* pNMHDR, LRESULT* pResult);
+	afx_msg void OnMnuOpen();
+	afx_msg void OnMnuDelsel();
+	afx_msg void OnMnuDelall();
+	afx_msg void OnBtnCtrl();
+	afx_msg void OnOK();
+	afx_msg void OnCancel();
+	afx_msg void OnSize(UINT nType, int cx, int cy);
+	//}}AFX_MSG
+	DECLARE_MESSAGE_MAP()
+};
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_FILEWATCHERDLG_H__CA611DDF_62C0_4DC0_B787_57E4F6F8B4A8__INCLUDED_)

+ 88 - 0
FileWatcher/ReadMe.txt

@@ -0,0 +1,88 @@
+========================================================================
+       MICROSOFT FOUNDATION CLASS LIBRARY : FileWatcher
+========================================================================
+
+
+AppWizard has created this FileWatcher application for you.  This application
+not only demonstrates the basics of using the Microsoft Foundation classes
+but is also a starting point for writing your application.
+
+This file contains a summary of what you will find in each of the files that
+make up your FileWatcher application.
+
+FileWatcher.dsp
+    This file (the project file) contains information at the project level and
+    is used to build a single project or subproject. Other users can share the
+    project (.dsp) file, but they should export the makefiles locally.
+
+FileWatcher.h
+    This is the main header file for the application.  It includes other
+    project specific headers (including Resource.h) and declares the
+    CFileWatcherApp application class.
+
+FileWatcher.cpp
+    This is the main application source file that contains the application
+    class CFileWatcherApp.
+
+FileWatcher.rc
+    This is a listing of all of the Microsoft Windows resources that the
+    program uses.  It includes the icons, bitmaps, and cursors that are stored
+    in the RES subdirectory.  This file can be directly edited in Microsoft
+	Visual C++.
+
+FileWatcher.clw
+    This file contains information used by ClassWizard to edit existing
+    classes or add new classes.  ClassWizard also uses this file to store
+    information needed to create and edit message maps and dialog data
+    maps and to create prototype member functions.
+
+res\FileWatcher.ico
+    This is an icon file, which is used as the application's icon.  This
+    icon is included by the main resource file FileWatcher.rc.
+
+res\FileWatcher.rc2
+    This file contains resources that are not edited by Microsoft 
+	Visual C++.  You should place all resources not editable by
+	the resource editor in this file.
+
+
+
+
+/////////////////////////////////////////////////////////////////////////////
+
+AppWizard creates one dialog class:
+
+FileWatcherDlg.h, FileWatcherDlg.cpp - the dialog
+    These files contain your CFileWatcherDlg class.  This class defines
+    the behavior of your application's main dialog.  The dialog's
+    template is in FileWatcher.rc, which can be edited in Microsoft
+	Visual C++.
+
+
+/////////////////////////////////////////////////////////////////////////////
+Other standard files:
+
+StdAfx.h, StdAfx.cpp
+    These files are used to build a precompiled header (PCH) file
+    named FileWatcher.pch and a precompiled types file named StdAfx.obj.
+
+Resource.h
+    This is the standard header file, which defines new resource IDs.
+    Microsoft Visual C++ reads and updates this file.
+
+/////////////////////////////////////////////////////////////////////////////
+Other notes:
+
+AppWizard uses "TODO:" to indicate parts of the source code you
+should add to or customize.
+
+If your application uses MFC in a shared DLL, and your application is 
+in a language other than the operating system's current language, you
+will need to copy the corresponding localized resources MFC42XXX.DLL
+from the Microsoft Visual C++ CD-ROM onto the system or system32 directory,
+and rename it to be MFCLOC.DLL.  ("XXX" stands for the language abbreviation.
+For example, MFC42DEU.DLL contains resources translated to German.)  If you
+don't do this, some of the UI elements of your application will remain in the
+language of the operating system.
+
+/////////////////////////////////////////////////////////////////////////////

+ 8 - 0
FileWatcher/StdAfx.cpp

@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+//	FileWatcher.pch will be the pre-compiled header
+//	stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+
+

+ 28 - 0
FileWatcher/StdAfx.h

@@ -0,0 +1,28 @@
+// stdafx.h : include file for standard system include files,
+//  or project specific include files that are used frequently, but
+//      are changed infrequently
+//
+#define _WIN32_WINNT 0x0500
+
+#if !defined(AFX_STDAFX_H__833246A7_9339_438C_9D09_DCF91CFA38FE__INCLUDED_)
+#define AFX_STDAFX_H__833246A7_9339_438C_9D09_DCF91CFA38FE__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
+
+#include <afxwin.h>         // MFC core and standard components
+#include <afxext.h>         // MFC extensions
+#include <afxdisp.h>        // MFC Automation classes
+#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
+#ifndef _AFX_NO_AFXCMN_SUPPORT
+#include <afxcmn.h>			// MFC support for Windows Common Controls
+#endif // _AFX_NO_AFXCMN_SUPPORT
+
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_STDAFX_H__833246A7_9339_438C_9D09_DCF91CFA38FE__INCLUDED_)

+ 286 - 0
FileWatcher/Watcher.cpp

@@ -0,0 +1,286 @@
+// Watcher.cpp: implementation of the CWatcher class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "stdafx.h"
+#include "FileWatcher.h"
+#include "Watcher.h"
+#include "FileWatcherDlg.h"
+
+#ifdef _DEBUG
+#undef THIS_FILE
+static char THIS_FILE[]=__FILE__;
+#define new DEBUG_NEW
+#endif
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CWatcher::CWatcher()
+{
+
+}
+
+CWatcher::~CWatcher()
+{
+	this->Destroy();
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】创建目录监控。
+//【参数】csStrPath 监控目录的路径
+//【描述】打开目录,保存句柄。创建空完成端口,保存句柄。
+//	把目录句柄与完成端口关联,保存句柄。创建线程,并挂起,保存句柄。
+//	投递第一次IO请求,调用Watch。
+BOOL CWatcher::Create(CString csStrPath)
+{
+	//===========> 打开目录,保存句柄
+	if ((this->m_hPath = CreateFile(
+		csStrPath,
+		GENERIC_READ | GENERIC_WRITE,
+		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+		NULL,
+		OPEN_EXISTING,
+		FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
+		NULL
+        )) == INVALID_HANDLE_VALUE)
+	{
+		return FALSE;
+	}
+	//============> 创建新的完成端口
+	if ((this->m_hIOCPApp = ::CreateIoCompletionPort(
+		INVALID_HANDLE_VALUE,
+		NULL,
+		0,
+		0
+		)) == NULL)
+	{
+		this->CloseAllHandle();
+
+		return FALSE;
+	}
+	//============> 关联完成端口,启用单线程
+	if ((this->m_hIOCPNew = ::CreateIoCompletionPort(
+		this->m_hPath,
+		this->m_hIOCPApp,
+		0,
+		2
+		)) == NULL)
+	{
+		this->CloseAllHandle();
+		return FALSE;
+	}
+	//=========> 创建监控线程,挂起,保存句柄
+	if ((this->m_hThread = ::CreateThread(
+		NULL,
+		0,
+		CWatcher::WatchThreadProc,
+		this,
+		CREATE_SUSPENDED,
+		NULL
+		)) == NULL)
+	{
+		this->CloseAllHandle();
+		return FALSE;
+	}
+	//=============> 投递IO请求
+	if (this->Watch() == FALSE)
+	{
+		//=======> 强行退出线程,因为线程没有工作,所以是安全操作
+		::TerminateThread(this->m_hThread, 0);
+
+		this->CloseAllHandle();
+
+		return FALSE;
+	}
+	//============> 恢复线程,让线程工作
+	::ResumeThread(this->m_hThread);
+	return TRUE;
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】关闭所有打开的句柄
+//【参数】无
+//【描述】关闭新完成端口、关联完成端口、目录、线程句柄
+VOID CWatcher::CloseAllHandle()
+{
+	::CloseHandle(this->m_hIOCPApp);
+	::CloseHandle(this->m_hIOCPNew);
+	::CloseHandle(this->m_hPath);
+	::CloseHandle(this->m_hThread);
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】监控
+//【参数】无
+//【描述】调用ReadDirectoryChangesW,相当于投递第一次IO请求
+BOOL CWatcher::Watch()
+{
+	DWORD dwByteRet = 0;
+
+	//==========> 清空OVERLAPPED结构
+	::memset(&this->m_stOverlapped, 0, sizeof(OVERLAPPED));
+
+	//=========> 监控目录
+	if (::ReadDirectoryChangesW(
+		this->m_hPath,
+		this->m_szBuffer,
+		WTH_BUF_LEN,
+		TRUE,
+		FILE_NOTIFY_CHANGE_FILE_NAME |
+		FILE_NOTIFY_CHANGE_DIR_NAME |
+		FILE_NOTIFY_CHANGE_ATTRIBUTES |
+		FILE_NOTIFY_CHANGE_SIZE |
+		FILE_NOTIFY_CHANGE_LAST_WRITE |
+		FILE_NOTIFY_CHANGE_LAST_ACCESS |
+		FILE_NOTIFY_CHANGE_CREATION |
+		FILE_NOTIFY_CHANGE_SECURITY,
+		&dwByteRet,
+		&this->m_stOverlapped,
+		NULL 
+		) == FALSE)
+	{
+		return FALSE;
+	}
+	return TRUE;
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】监控线程过程
+//【参数】lpPara 创建线程时候传递的指针
+//【描述】循环,查询完成端口状态,如果查询失败、触发OnError,中断。
+//	如果dwByteRet为-1,那么说明收到,退出通知,中断
+//	如果没有意外,处理缓冲区以后,触发OnWatch
+DWORD WINAPI CWatcher::WatchThreadProc(LPVOID lpvPara)
+{
+	CWatcher *lpcsWatcher = NULL;
+	DWORD dwByteRet = 0, dwIOKey = 0;
+	LPOVERLAPPED lpstOverlapped = NULL;
+	PFILE_NOTIFY_INFORMATION lpstNotify = NULL;
+	char *lpszBuffer = NULL;
+	CString csStrName1, csStrName2;
+
+	lpcsWatcher = (CWatcher *)lpvPara;
+
+	while (TRUE)
+	{
+		//========> 查询完成端口状态
+		if (::GetQueuedCompletionStatus(
+			lpcsWatcher->m_hIOCPApp,
+			&dwByteRet,
+			&dwIOKey,
+			&lpstOverlapped,
+			INFINITE
+			) == TRUE)
+		{
+			//=========> 判断是否失败
+			if (dwByteRet == 0)
+			{
+				lpcsWatcher->CloseAllHandle();		// 这里会导致程序崩溃;
+				break;
+			}
+			else
+			{
+				//========> 分配内存,复制内存
+				lpszBuffer = new char[dwByteRet];
+				memcpy(lpszBuffer, lpcsWatcher->m_szBuffer, dwByteRet);
+
+				//======> 缓冲区并且转换成FILE_NOTIFY_INFORMATION结构
+				lpstNotify = (PFILE_NOTIFY_INFORMATION)lpszBuffer;
+
+				//========= 转换成CString,得到名称1
+				csStrName1 = lpcsWatcher->WideCharToCString(
+					lpstNotify->FileName,
+					lpstNotify->FileNameLength);
+				//========> 判断是否存在偏移
+				if (lpstNotify->NextEntryOffset != 0)
+				{
+					//==========> 计算第二个字符偏移
+					//======> 一定要记得是
+					// (PFILE_NOTIFY_INFORMATION)(lpszBuffer + lpstNotify->NextEntryOffset)
+					lpstNotify = 
+						(PFILE_NOTIFY_INFORMATION)(lpszBuffer + 
+						lpstNotify->NextEntryOffset);
+					//========= 转换成CString,得到名称2
+					csStrName2 = lpcsWatcher->WideCharToCString(
+						lpstNotify->FileName,
+						lpstNotify->FileNameLength);
+				}
+
+				//=======> 调用OnWatch,剩下的交给此过程处理
+				lpcsWatcher->OnWatch(
+					lpstNotify->Action, 
+					csStrName1, 
+					csStrName2);
+
+				// 释放内存
+				delete[] lpszBuffer;
+
+				//======> 再次投递IO请求
+				if (lpcsWatcher->Watch() == FALSE)
+				{
+					lpcsWatcher->CloseAllHandle();
+				}
+			}
+		}
+		else
+		{
+				lpcsWatcher->CloseAllHandle();
+		}
+	}
+	return 0;
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】宽字符转换成多字节CString
+//【参数】lpszWideChar 宽字符缓冲区。nLength 缓冲区长度
+//【描述】宽字符转换成多字节以后,再转换成CString对象,然后返回
+CString CWatcher::WideCharToCString(LPCWSTR lpszWideChar, UINT nLength)
+{
+	char szString[MAX_PATH] = {0};
+
+	//======> 转换
+	WideCharToMultiByte(
+		CP_ACP,
+		0,
+		lpszWideChar,
+		nLength / 2,
+		szString,
+		MAX_PATH,
+		NULL,
+		NULL 
+		);
+	return szString;
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】销毁目录监控
+//【参数】无
+//【描述】关闭句柄,让它在线程检测到到失败,安全退出
+VOID CWatcher::Destroy()
+{
+	this->CloseAllHandle();
+}
+
+//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+//【名称】监控过程
+//【参数】dwAction 动作类型。csStrName 相关名称
+//【描述】处理动作,不要调用Destroy
+VOID CWatcher::OnWatch(DWORD dwAction, CString csStrName1, CString csStrName2)
+{
+	//========> 交托给窗口的过程处理
+	((CFileWatcherDlg *)AfxGetApp()->GetMainWnd())->OnWatch(
+		dwAction,
+		csStrName1,
+		csStrName2);
+
+}
+

+ 48 - 0
FileWatcher/Watcher.h

@@ -0,0 +1,48 @@
+// Watcher.h: interface for the CWatcher class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(AFX_WATCHER_H__59FB1B23_A774_4A4A_8D09_534FC5CFD9E1__INCLUDED_)
+#define AFX_WATCHER_H__59FB1B23_A774_4A4A_8D09_534FC5CFD9E1__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#define WTH_BUF_LEN		(MAX_PATH * 2)
+
+class CWatcher  
+{ 
+public:
+	enum enmACTION
+	{
+		actCreate = FILE_ACTION_ADDED,
+		actRemote = FILE_ACTION_REMOVED,
+		actRenameNew = FILE_ACTION_RENAMED_NEW_NAME,
+		actRenameOld = FILE_ACTION_RENAMED_OLD_NAME,
+		actChange = FILE_ACTION_MODIFIED
+	};
+public:
+	CWatcher();
+	virtual ~CWatcher();
+public:
+	VOID Destroy();
+
+	BOOL Create(CString csStrPath);
+protected:
+	virtual VOID OnWatch(DWORD dwAction, CString csStrName1, CString csStrName2);
+private:
+	BOOL Watch();
+	static DWORD WINAPI WatchThreadProc(LPVOID lpvPara);
+	VOID CloseAllHandle();
+	CString WideCharToCString(LPCWSTR lpszWideChar, UINT nLength);
+private:
+	char m_szBuffer[WTH_BUF_LEN];		// 缓冲区
+	OVERLAPPED m_stOverlapped;			// 重叠结构
+	HANDLE m_hThread;					// 线程句柄
+	HANDLE m_hIOCPNew;					// 新的完成端口句柄
+	HANDLE m_hIOCPApp;					// 使用的完成端口句柄
+	HANDLE m_hPath;						// 目录句柄
+};
+
+#endif // !defined(AFX_WATCHER_H__59FB1B23_A774_4A4A_8D09_534FC5CFD9E1__INCLUDED_)

+ 13 - 0
FileWatcher/res/FileWatcher.rc2

@@ -0,0 +1,13 @@
+//
+// FILEWATCHER.RC2 - resources Microsoft Visual C++ does not edit directly
+//
+
+#ifdef APSTUDIO_INVOKED
+	#error this file is not editable by Microsoft Visual C++
+#endif //APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+// Add manually edited resources here...
+
+/////////////////////////////////////////////////////////////////////////////

BIN
FileWatcher/res/Icon.ico


+ 28 - 0
FileWatcher/resource.h

@@ -0,0 +1,28 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by FileWatcher.rc
+//
+#define IDM_ABOUTBOX                    0x0010
+#define IDD_ABOUTBOX                    100
+#define IDS_ABOUTBOX                    101
+#define IDD_FILEWATCHER_DIALOG          102
+#define IDR_MAINFRAME                   128
+#define IDR_MNU_POP                     129
+#define IDI_ICON2                       133
+#define IDC_LIST_DATA                   1000
+#define IDC_EDIT_PATH                   1001
+#define IDC_BTN_CTRL                    1002
+#define IDR_MNU_OPEN                    32773
+#define IDR_MNU_DELSEL                  32774
+#define IDR_MNU_DELALL                  32775
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        134
+#define _APS_NEXT_COMMAND_VALUE         32776
+#define _APS_NEXT_CONTROL_VALUE         1003
+#define _APS_NEXT_SYMED_VALUE           101
+#endif
+#endif