派生一个类 // DbReactor.cpp: implementation of the CDbReactor class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "resource.h" #include "DbReactor.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CDbReactor::CDbReactor() { } CDbReactor::~CDbReactor() { } void CDbReactor::objectAppended(const AcDbDatabase *db,const AcDbObject *pObj) { ads_alert("APPEND"); } void CDbReactor::objectModified(const AcDbDatabase *db,const AcDbObject *pObj) { ads_alert("MODIFY"); } void CDbReactor::objectErased(const AcDbDatabase *db,const AcDbObject *pObj,Adesk::Boolean pErased) { if(pErased) ads_alert("DELETE"); } // DbReactor.h: interface for the CDbReactor class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_DBREACTOR_H__ED11D52E_E8ED_43A0_90CE_8BB65D78A51A__INCLUDED_) #define AFX_DBREACTOR_H__ED11D52E_E8ED_43A0_90CE_8BB65D78A51A__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CDbReactor : public AcDbDatabaseReactor { public: CDbReactor(); virtual ~CDbReactor(); void objectAppended(const AcDbDatabase *db,const AcDbObject *pObj); void objectModified(const AcDbDatabase *db,const AcDbObject *pObj); void objectErased(const AcDbDatabase *db,const AcDbObject *pObj,Adesk::Boolean pErased); }; #endif // !defined(AFX_DBREACTOR_H__ED11D52E_E8ED_43A0_90CE_8BB65D78A51A__INCLUDED_) 增加监控函数
void WatchDb() { if(gpDbr==NULL) gpDbr = new CDbReactor(); AcDbDatabase *pCur=acdbHostApplicationServices()->workingDatabase(); pCur->addReactor(gpDbr); } //清除监控函数 void ClearReactors() { AcDbDatabase *pCur=acdbHostApplicationServices()->workingDatabase(); if(pCur!=NULL) pCur->removeReactor(gpDbr); delete gpDbr; gpDbr=NULL; } 在初始化时增加监控 void InitApplication() { // TODO: add your initialization functions WatchDb(); } // Unload this application. Unregister all objects // registered in InitApplication. //在退出时清除监控 void UnloadApplication() { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_EXIT //}}AFX_ARX_EXIT
ClearReactors(); //deleteAcRxClass(CPersistentReactor::desc()); // TODO: clean up your application }
|