badboy518 发表于 2006-2-5 20:19:00

关于模态对话框和非模态对话框的问题

<P>插入块的代码:</P>
<P>AcDbDatabase *pCurDb;<BR>&nbsp;AcDbBlockTable *pBlkTable;<BR>&nbsp;AcDbBlockTableRecord *pBlkTableRecord;<BR>&nbsp;AcDbBlockReference *pInsrtObj;<BR>&nbsp;AcDbObjectId blkId;<BR>&nbsp;pCurDb = acdbHostApplicationServices()-&gt;workingDatabase();</P>
<P>&nbsp;pCurDb-&gt;getBlockTable(pBlkTable, AcDb::kForRead);<BR>&nbsp;if(!pBlkTable-&gt;has(blkName))<BR>&nbsp;{<BR>&nbsp;&nbsp;acutPrintf("\nBlock definition %s not found. ", blkName);<BR>&nbsp;&nbsp;pBlkTable-&gt;close();<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR><BR>&nbsp;pBlkTable-&gt;getAt(blkName, blkId);</P>
<P>//下面的这一行在模态对话框中能很好的执行,但是在非模态对话框中却使CAD出现严重错误。不知怎么回事。请各位能指点一下迷津谢谢。</P>
<P>&nbsp;pBlkTable-&gt;getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);<BR>&nbsp;pBlkTable-&gt;close();<BR></P>
<P>&nbsp;pInsrtObj = new AcDbBlockReference(insPt, blkId);</P>
<P>&nbsp;pBlkTableRecord-&gt;appendAcDbEntity(blkId, pInsrtObj);</P>
<P>&nbsp;pBlkTableRecord-&gt;close();<BR>&nbsp;pInsrtObj-&gt;close();</P>

<P>Modal对话框中 按纽单击事件 以上代码能通过编译、执行</P>
<P>Modeless对话框中 按纽单击事件 以上代码能通过编译,执行时出现错误。</P>
<P>为这个问题都忙活了一天了,不知怎么解决。请一定指点一下!谢谢。</P>

badboy518 发表于 2006-2-5 20:26:00

<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-&gt;curDocument();<BR><BR>Acad::ErrorStatus es = acDocManager-&gt;lockDocument(pDoc);</P>
<P>if(es == Acad::eOk)<BR><BR>{<BR><BR>acedCommand.......<BR><BR>}</P>

badboy518 发表于 2006-2-5 21:13:00

<P>成功了!!哭死,搞了两天这个问题。</P>
<P>总结如下:</P>
<P>窗口要这样创建:</P>
<P>&nbsp;xfhDlg* xD = NULL;<BR>&nbsp;xD=new xfhDlg(acedGetAcadFrame());<BR>&nbsp;xD-&gt;Create(DLG_M);<BR>&nbsp;xD-&gt;ShowWindow(SW_SHOW);<BR>&nbsp;xD-&gt;CenterWindow();</P>
<P>在出错的代码前加上以下:</P>
<P>//非模态对话框要用以下代码:<BR>AcApDocument* pDoc= acDocManager-&gt;curDocument();<BR>Acad::ErrorStatus es = acDocManager-&gt;lockDocument(pDoc);<BR>if(es != Acad::eOk) return;</P>
<P>&nbsp;</P>
<P>在结束处加上以下代码:</P>
<P>//非模态对话框要用以下代码:</P>
<P>acDocManager-&gt;unlockDocument(pDoc);</P>

hyxlei 发表于 2008-10-30 15:43:00

以后多向老兄学习
页: [1]
查看完整版本: 关于模态对话框和非模态对话框的问题