www.mxdraw.com
|
向控件发送一个命令,并执行该命令
virtual Mcad::ErrorStatus sendStringToExecute(McApDocument* pAcTargetDocument, LPCTSTR pszExecute, bool bActivate = true, bool bWrapUpInactiveDoc = false, bool bEchoString = true, struct resbuf* pParam = NULL, bool bFunCall = false) = 0;
参数 |
说明 |
McApDocument* pAcTargetDocument |
执行命令的对象 |
LPCTSTR pszExecute |
命令字符串,如打开dwg文件命令为OpenDwg |
bool bActivate = true |
暂没有使用 |
bool bWrapUpInactiveDoc = false |
暂没有使用 |
bool bEchoString = true |
暂没有使用 |
struct resbuf* pParam = NULL |
执行命令时,可以带参数执行,用户不需要负责它的内存释放,将由sendStringToExecute函数自动释放 |
如果成功返回Mcad::eOk,如果传递的数据非法则返回Mcad::eInvalidInput
例如:执行打开文件命令
acDocManager->sendStringToExecute(MxDraw::GetDatabase(m_hDrawOcx)->GetDocument() ,_T("OpenDwg") );
实现一个带参数的命令,并调用
// 命令函数定义. static void MXOCXSYS_ImpMxDrawXCommand(); // 命令函数实现 void CMxDrawXCommand::MXOCXSYS_ImpMxDrawXCommand() { // 得到命令参数 struct resbuf* pRb = Mx::mcedGetArgs(); if(pRb == NULL || pRb->restype != RTSHORT || pRb->rbnext == NULL || pRb->rbnext->restype != RTLONG ) return; int iCommandId = pRb->resval.rint; CMxDrawXCtrl* pOcx = (CMxDrawXCtrl*)(DWORD_PTR)(pRb->rbnext->resval.rlong); ASSERT(pOcx->GetOcxHandle() == MxDraw::GetCurOcxHandle() ); pOcx->m_pImpCommand->m_isRuningCommand = true; pOcx->ImplementCommandEvent(iCommandId); pOcx->m_pImpCommand->m_isRuningCommand = false; } // 注册命令 void CMxDrawXCommand::RegisterCommand() { acedRegCmds->addCommand(_T("SysCmd"), _T("MXOCXSYS_ImpMxDrawXCommand"), _T("MXOCXSYS_ImpMxDrawXCommand"), 1, MXOCXSYS_ImpMxDrawXCommand); } // 调用命令 void CMxDrawXCommand::DoCommand(CMxDrawXCtrl* pOcx, int iParam /*= 0*/) { // 构建命令参数 struct resbuf* pParam = Mx::mcutBuildList(RTSHORT,iParam,RTLONG, (long)(DWORD_PTR)(pOcx),RTNONE ); acDocManager->sendStringToExecute(MxDraw::GetDatabase(pOcx->GetOcxHandle() )->GetDocument() ,_T("MXOCXSYS_ImpMxDrawXCommand"),true,false,false,pParam); }