文件名称:Windows下目录监视程序代码
文件大小:350KB
文件格式:RAR
更新时间:2013-10-04 17:31:53
目录监视
用于完成指定目录变化监控 /*----------------------线程函数------------------------------------*/ DWORD WINAPI CDDlg::ThreadProc( LPVOID lParam ) //线程函数 { CDDlg* obj = (CDDlg*)lParam; //参数转化 obj->hDir = CreateFile( //打开目录,得到目录的句柄 obj->m_strWatchedDir, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); if(obj->hDir ==INVALID_HANDLE_VALUE ) return false; char buf[(sizeof(FILE_NOTIFY_INFORMATION)+MAX_PATH)*2]; FILE_NOTIFY_INFORMATION* pNotify=(FILE_NOTIFY_INFORMATION*)buf; DWORD dwBytesReturned; while(true) { if( ::ReadDirectoryChangesW( obj->hDir, pNotify, sizeof(buf), 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, &dwBytesReturned, NULL, NULL ) ) { char tmp[MAX_PATH], str1[MAX_PATH], str2[MAX_PATH]; memset( tmp, 0, sizeof(tmp) ); //ZeroMemory() WideCharToMultiByte( CP_ACP,0,pNotify->FileName,pNotify->FileNameLength/2,tmp,99,NULL,NULL ); strcpy( str1, tmp ); if(pNotify->NextEntryOffset !=0 ) { PFILE_NOTIFY_INFORMATION p = (PFILE_NOTIFY_INFORMATION)((char*)pNotify+pNotify->NextEntryOffset); memset( tmp, 0, sizeof(tmp) ); WideCharToMultiByte( CP_ACP,0,p->FileName,p->FileNameLength/2,tmp,99,NULL,NULL ); strcpy( str2, tmp ); } switch(pNotify->Action) { case FILE_ACTION_ADDED: if(obj->m_bAddNew0) { CTime tt=CTime::GetCurrentTime(); CString strTT; strTT.Format("%d:%d:%d",tt.GetHour(),tt.GetMinute(),tt.GetSecond()); obj->m_list.InsertItem(0,obj->m_szi); obj->m_list.SetItemText(0,2,"添加了新文件"); obj->m_list.SetItemText(0,3,str1); obj->m_list.SetItemText(0,1,strTT); // PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT); } break; case FILE_ACTION_REMOVED: if(obj->m_bDel0) { CTime tt=CTime::GetCurrentTime(); CString strTT; strTT.Format("%d:%d:%d",tt.GetHour(),tt.GetMinute(),tt.GetSecond()); obj->m_list.InsertItem(0,obj->m_szi); obj->m_list.SetItemText(0,2,"删除了文件"); obj->m_list.SetItemText(0,3,str1); obj->m_list.SetItemText(0,1,strTT); // PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT); } break; case FILE_ACTION_RENAMED_NEW_NAME: if(obj->m_bRename0) { CTime tt=CTime::GetCurrentTime(); CString strTT; strTT.Format("%d:%d:%d",tt.GetHour(),tt.GetMinute(),tt.GetSecond()); obj->m_list.InsertItem(0,obj->m_szi); obj->m_list.SetItemText(0,2,"重命名了文件"); strcat(str1,"->"); obj->m_list.SetItemText(0,3,strcat(str1,str2)); obj->m_list.SetItemText(0,1,strTT); // PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT); } break; case FILE_ACTION_RENAMED_OLD_NAME: if(obj->m_bRename0) { CTime tt=CTime::GetCurrentTime(); CString strTT; strTT.Format("%d:%d:%d",tt.GetHour(),tt.GetMinute(),tt.GetSecond()); obj->m_list.InsertItem(0,obj->m_szi); obj->m_list.SetItemText(0,2,"重命名了文件"); strcat(str1," 改名为 "); obj->m_list.SetItemText(0,3,strcat(str1,str2)); obj->m_list.SetItemText(0,1,strTT); // PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT); } break; case FILE_ACTION_MODIFIED: if(obj->m_bModify0) { CTime tt=CTime::GetCurrentTime(); CString strTT; strTT.Format("%d:%d:%d",tt.GetHour(),tt.GetMinute(),tt.GetSecond()); obj->m_list.InsertItem(0,obj->m_szi); obj->m_list.SetItemText(0,2,"修改了文件"); obj->m_list.SetItemText(0,3,str1); obj->m_list.SetItemText(0,1,strTT); // PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT); } break; default: if(obj->m_bOther0) { CTime tt=CTime::GetCurrentTime(); CString strTT; strTT.Format("%d:%d:%d",tt.GetHour(),tt.GetMinute(),tt.GetSecond()); obj->m_list.InsertItem(0,obj->m_szi); obj->m_list.SetItemText(0,2,"未知变化"); obj->m_list.SetItemText(0,3,""); obj->m_list.SetItemText(0,1,strTT); // PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT); } break; } obj->m_i++; itoa(obj->m_i,obj->m_szi,10); //AfxBeginThread(SoundThread,0); } else break; } return 0; }
【文件预览】:
VIP会员.htm
查看帮助.txt
桌面.jpg
200641016561469
----目录监视程序()
--------FaderWnd.h(1KB)
--------StdAfx.cpp(203B)
--------BrowseFolder.h(548B)
--------LogoDlg.cpp(1KB)
--------d.dsw(527B)
--------d.opt(53KB)
--------d.exe(324KB)
--------d.cpp(3KB)
--------d.dsp(4KB)
--------dDlg.cpp(19KB)
--------Alert.WAV(2KB)
--------d.ncb(57KB)
--------BrowseFolder.cpp(1KB)
--------d.h(1KB)
--------SelectDlg.h(1KB)
--------SelectDlg.cpp(3KB)
--------ReadMe.txt(3KB)
--------StdAfx.h(1KB)
--------d.clw(3KB)
--------ClassXP.dll(48KB)
--------d.plg(2KB)
--------Resource.h(2KB)
--------FileWatcher.h(3KB)
--------res()
--------dDlg.h(2KB)
--------FaderWnd.cpp(5KB)
--------LogoDlg.h(1KB)
--------Settings.ini(114B)
--------d.rc(10KB)
--------使用方法.txt(1KB)
--------d.aps(330KB)
安全中国anqn.com.txt
会员服务.txt