注册一个数据库事件反应器,用于监视数据库事件
void addReactor(McDbDatabaseReactor* pReactor) const;
参数 |
说明 |
McDbDatabaseReactor* pReactor |
数据库反应器指针 |
例如:监视数据库的WordDrawBackGround事件,用户自定义控件显示背景
class CCustomDrawGround : public McDbDatabaseReactor { public: CCustomDrawGround(); virtual ~CCustomDrawGround(); virtual void WordDrawBackGround(const McDbDatabase* pDatabase,McGiWorldDraw* wd,McDbObjectId layoutId); }; void CCustomDrawGround::WordDrawBackGround(const McDbDatabase* pDatabase, McGiWorldDraw* wd, McDbObjectId layoutId) { McDbObjectPointer<McDbLayout> spLayout(layoutId,McDb::kForRead); if(spLayout.openStatus() != Mcad::eOk) return; if(!spLayout->IsModelSpace() ) { return ; } wd->subEntityTraits().setColor(9); // 写一个背景文字 McDbText text; text.setHeight(20); text.setTextString(_T("梦想绘图控件,背景文字测试")); text.setPosition(McGePoint3d(0,0,0)); text.setAlignmentPoint(McGePoint3d(0,0,0)); text.worldDraw(wd); return; } CCustomDrawGround* m_pCustomDrawGround; // 创建一个反应器 m_pCustomDrawGround = new CCustomDrawGround; // 注册反应器 MxDraw::GetDatabase(m_hDrawOcx)->addReactor(m_pCustomDrawGround); void CTestDlg::OnDestroy() { // 在退出时,注销反应器 MxDraw::GetDatabase(m_hDrawOcx)->removeReactor(m_pCustomDrawGround); CResizingDialog::OnDestroy(); }