main.cpp
上传用户:aorui801
上传日期:2022-07-20
资源大小:201k
文件大小:6k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "main.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmMain *frmMain;
- //---------------------------------------------------------------------------
- AnsiString __fastcall TfrmMain::SHEventName(AnsiString strPath1,AnsiString strPath2,DWORD lParam)
- {
- AnsiString sEvent;
-
- switch(lParam)//根据参数设置提示消息
- {
- case SHCNE_RENAMEITEM: sEvent = "重命名文件 ["+strPath1 + "] 为 [" + strPath2 + "]"; break;
- case SHCNE_CREATE: sEvent = "建立文件 ["+strPath1 + "]";break;
- case SHCNE_DELETE: sEvent = "删除文件 ["+strPath1 + "]";break;
- case SHCNE_MKDIR: sEvent = "新建目录 ["+strPath1 + "]";break;
- case SHCNE_RMDIR: sEvent = "删除目录 ["+strPath1 + "]";break;
- case SHCNE_MEDIAINSERTED: sEvent = "[" + strPath1+"] 中插入可移动存储介质";break;
- case SHCNE_MEDIAREMOVED: sEvent = "[" + strPath1+"] 中移去可移动存储介质"+strPath1+" "+strPath2;break;
- case SHCNE_DRIVEREMOVED: sEvent = "移去驱动器 ["+strPath1+ "]";break;
- case SHCNE_DRIVEADD: sEvent = "添加驱动器 ["+strPath1+ "]";break;
- case SHCNE_NETSHARE: sEvent = "设置目录 ["+strPath1+"] 为共享";break;
- case SHCNE_NETUNSHARE: sEvent = "取消目录 ["+strPath1+"] 的共享"; break;
- case SHCNE_ATTRIBUTES: sEvent = "改变文件目录属性 ["+strPath1+ "]";break;
- case SHCNE_UPDATEDIR: sEvent = "更新目录 ["+strPath1+ "]";break;
- case SHCNE_UPDATEITEM: sEvent = "更新文件 ["+strPath1+ "]";break;
- case SHCNE_SERVERDISCONNECT: sEvent = "断开与服务器的连接 ["+strPath1+"] ["+strPath2+ "]";break;
- case SHCNE_UPDATEIMAGE: sEvent = "执行:SHCNE_UPDATEIMAGE 操作";break;
- case SHCNE_DRIVEADDGUI: sEvent = "执行:SHCNE_DRIVEADDGUI 操作";break;
- case SHCNE_RENAMEFOLDER: sEvent = "重命名文件夹 ["+strPath1+"] 为 ["+strPath2+ "]";break;
- case SHCNE_FREESPACE: sEvent = "磁盘空间大小改变 ";break;
- case SHCNE_ASSOCCHANGED: sEvent = "改变文件关联";break;
- case SHCNE_EXTENDED_EVENT:sEvent = "此目录有变化 [" + strPath2 + "]"; break;
- default: sEvent = "未知操作 ["+IntToStr(lParam)+ "]";break;
- }
- return sEvent;
- }
- bool __fastcall TfrmMain::SHNotify_Register(HWND hWnd)
- {
- IDLSTRUCT ps;
- if( m_hSHNotify != NULL) return False;
-
- if( SHGetSpecialFolderLocation == NULL) return;
- if( SHGetSpecialFolderLocation(0,CSIDL_DESKTOP,&m_pidlDesktop) == NOERROR)
- {
- if( m_pidlDesktop )
- {
- ps.pidl = m_pidlDesktop;
- ps.bWatchSubFolders = 1;
- m_hSHNotify = SHChangeNotifyRegister(hWnd,
- SHCNF_TYPE | SHCNF_IDLIST,
- SHCNE_ALLEVENTS | SHCNE_INTERRUPT,
- WM_SHNOTIFY,1,&ps);
- return True;
- }
- else
- {
- CoTaskMemFree(m_pidlDesktop);
- }
- }
- return False;
- }
- bool __fastcall TfrmMain::SHNotify_UnRegister()
- {
- if( m_hSHNotify == NULL) return False;
- if( SHChangeNotifyDeregister == NULL) return False;
- if( SHChangeNotifyDeregister(m_hSHNotify) )
- {
- m_hSHNotify = NULL;
- CoTaskMemFree(m_pidlDesktop);
- return True;
- }
- return False;
- }
- __fastcall TfrmMain::TfrmMain(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::WMShellReg(TMessage & Message)
- {
- //TODO: Add your source code here
- AnsiString strPath1;
- AnsiString strPath2;
- char strPath[256];
- AnsiString sTmp;
- PSHNOTIFYSTRUCT pidlItem;
- pidlItem = (PSHNOTIFYSTRUCT)Message.WParam;
- SHGetPathFromIDList(pidlItem->dwItem1,strPath);
- strPath1 = strPath;
- SHGetPathFromIDList(pidlItem->dwItem2,strPath);
- strPath2 = strPath;
- sTmp = FormatDateTime("[yyyy-mm-dd hh:mm:ss]:",Now()) + SHEventName(strPath1,strPath2,Message.LParam);
-
- Memo1->Lines->Add(sTmp);
- }
- void __fastcall TfrmMain::WMKeyLog(TMessage & Message)
- {
- //TODO: Add your source code here
- Memo1->Lines->AddStrings(HookList);
- HookList->Clear();
- }
- void __fastcall TfrmMain::FormCreate(TObject *Sender)
- {
- m_hSHNotify = NULL;
- HMODULE DLLHandle = LoadLibrary("SHELL32.DLL");
- if( DLLHandle )
- {
- SHChangeNotifyRegister = (SHNRegister)GetProcAddress(DLLHandle,(LPCSTR)2);
- SHChangeNotifyDeregister = (SHNUnRegister)GetProcAddress(DLLHandle,(LPCSTR)4);
- }
- FreeLibrary(DLLHandle);
-
- SHNotify_Register(Handle);
- InstallHook(Handle);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::FormClose(TObject *Sender, TCloseAction &Action)
- {
- SHNotify_UnRegister();
- UnInstallHook();
- }
- //---------------------------------------------------------------------------