【求助】鼠标双击块时进行块删除操作,程序崩溃
写了一个arx,其中需要在鼠标双击中特定名为SIGN的块时将该块删除掉。写了一个类ESEditor继承自AcEditorReactor,并重载鼠标双击事件函数,在该函数中进行块的判断和删除操作。开发的版本是AutoCAD2007 + VS2005,加载插件测试时发现大部分时候都会导致程序崩溃。但是插件在AutoCAD2010中测试时没问题。跟踪不到原因。代码如下,麻烦大家帮我看看有啥问题?void ESEditor::beginDoubleClick(const AcGePoint3d& clickPoint)
{
int index= ptInBlock(clickPoint);
if(index >= 0)
deleteBlock(index);
}
void ESEditor::deleteBlock(int blockIndex)
{
ErrorStatuses;
AcDbDatabase* pDataBase;
AcDbBlockTable* pBlkTbl;
AcDbBlockReference* pBlkRef;
AcDbBlockTableRecord* pBlkTblRec;
AcRxClass* rcClass;
AcDbEntity* pEntity;
AcDbObjectIdArray ids;
AcDbObjectId objId, objRecId;
long len;
ACHAR sel, signName;
if((es = acDocManager->lockDocument( acDocManager->curDocument(), AcAp::kWrite,NULL,NULL,true)) == Acad::eOk)
{
if((pDataBase = acdbHostApplicationServices()->workingDatabase()) != NULL)
{
if((es = pDataBase->getBlockTable(pBlkTbl, kForWrite)) == Acad::eOk)
{
wsprintf(signName, _T("%s"), _T("HanvonHandWritten_"));
wsprintf(sel, _T("%d"), blockIndex);
wcscat(signName, sel);
if((es = pBlkTbl->getAt(signName, pBlkTblRec, kForWrite)) == Acad::eOk)
{
if((es = pBlkTblRec->getBlockReferenceIds(ids)) == Acad::eOk)
{
len = ids.length();
for (int k = 0; k < len; k++)
{
if ((es = acdbOpenAcDbEntity(pEntity, ids, kForWrite))== Acad::eOk)
{
rcClass = pEntity->isA();
if (rcClass == NULL)
continue;
if((pBlkRef = AcDbBlockReference::cast(pEntity)) != NULL)
{
pBlkRef->erase();
pBlkRef->close();
}
pEntity->close();
}
}
}
pBlkTblRec->erase();
pBlkTblRec->close();
}
pBlkTbl->close();
}
}
acDocManager->unlockDocument( acDocManager->curDocument());
}
}
还有就是,我测试了下,如果鼠标双击的位置不在名为SIGN的块上,此时执行删除操作插件可以正常运行。
我也试着写了个HOOK来截获鼠标双击消息并进行删除块操作,现象同上。
页:
[1]