关于模态对话框和非模态对话框的问题
<P>插入块的代码:</P><P>AcDbDatabase *pCurDb;<BR> AcDbBlockTable *pBlkTable;<BR> AcDbBlockTableRecord *pBlkTableRecord;<BR> AcDbBlockReference *pInsrtObj;<BR> AcDbObjectId blkId;<BR> pCurDb = acdbHostApplicationServices()->workingDatabase();</P>
<P> pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);<BR> if(!pBlkTable->has(blkName))<BR> {<BR> acutPrintf("\nBlock definition %s not found. ", blkName);<BR> pBlkTable->close();<BR> return;<BR> }<BR><BR> pBlkTable->getAt(blkName, blkId);</P>
<P>//下面的这一行在模态对话框中能很好的执行,但是在非模态对话框中却使CAD出现严重错误。不知怎么回事。请各位能指点一下迷津谢谢。</P>
<P> pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);<BR> pBlkTable->close();<BR></P>
<P> pInsrtObj = new AcDbBlockReference(insPt, blkId);</P>
<P> pBlkTableRecord->appendAcDbEntity(blkId, pInsrtObj);</P>
<P> pBlkTableRecord->close();<BR> pInsrtObj->close();</P>
<P>Modal对话框中 按纽单击事件 以上代码能通过编译、执行</P>
<P>Modeless对话框中 按纽单击事件 以上代码能通过编译,执行时出现错误。</P>
<P>为这个问题都忙活了一天了,不知怎么解决。请一定指点一下!谢谢。</P> <P>自己在网上找的答案如下:由于E文太差,请各位老大说明一下。</P>
<P>In a modeless dialog you are in application scope and not document scope.<BR>acedCommand only works in document scope. You can try this to see if it<BR>works. It is how I switch to document scope when the user right clicks in<BR>the window, so I do not know if it will work from the modeless dialog, but I<BR>think it should.<BR>AcApDocument* pDoc = acDocManager->curDocument();<BR><BR>Acad::ErrorStatus es = acDocManager->lockDocument(pDoc);</P>
<P>if(es == Acad::eOk)<BR><BR>{<BR><BR>acedCommand.......<BR><BR>}</P> <P>成功了!!哭死,搞了两天这个问题。</P>
<P>总结如下:</P>
<P>窗口要这样创建:</P>
<P> xfhDlg* xD = NULL;<BR> xD=new xfhDlg(acedGetAcadFrame());<BR> xD->Create(DLG_M);<BR> xD->ShowWindow(SW_SHOW);<BR> xD->CenterWindow();</P>
<P>在出错的代码前加上以下:</P>
<P>//非模态对话框要用以下代码:<BR>AcApDocument* pDoc= acDocManager->curDocument();<BR>Acad::ErrorStatus es = acDocManager->lockDocument(pDoc);<BR>if(es != Acad::eOk) return;</P>
<P> </P>
<P>在结束处加上以下代码:</P>
<P>//非模态对话框要用以下代码:</P>
<P>acDocManager->unlockDocument(pDoc);</P> 以后多向老兄学习
页:
[1]