CAD进入选择状态前后对话框隐藏与显示(对话框发消息)

CAD进入选择状态前后对话框隐藏与显示(对话框发消息)

1、通过ObjectArx 的 BeginEditorCommand() 及CompleteEditorCommand()


void CModalessDlg::OnClickedButtonPickEnt()
{
	BeginEditorCommand();//隐藏对话框把控制权交给AUTOCAD
	ads_point pt;
	if (acedGetPoint(NULL, TEXT("\n输入一个点:"), pt) == RTNORM)
	{
		CompleteEditorCommand();
		m_strEnX.Format(TEXT("%.2f"), pt[X]);
		m_strEnY.Format(TEXT("%.2f"), pt[Y]);
		m_strEnZ.Format(TEXT("%.2f"), pt[Z]);
	}
    else
    {
        CancelEditorCommand();//要取消命令
    }
    //成员变量的值来更新文本框显示的内容
    UpdateData(FALSE);
}

以下代码参考BeginEditorCommand()实现原理,实现(模态对话框点击按钮->进入CAD操作->结束后返回->模态对话框)

BeginEditorCommand() is actually kinda a macro used to take care of hiding your dialog and giving focus to ACAD main window. you can use the following codes to achieve the same effect:

void SetLayerDocDlg::OnBnClickedButtonPickent()
{
	CString element;
	m_CurrentSelectedLayerName.GetWindowTextW(element);
	if (element.GetLength() == 0)
	{
		MessageBox(L"请先选择构件!");return;
	}
	CWnd* pCadWnd = CWnd::FromHandle(adsw_acadMainWnd());// AcUiMainWindow(); or use acedGet... to retrieve a handle to the main CAD window
	pCadWnd->EnableWindow(TRUE);
	this->ShowWindow(SW_HIDE); // 隐藏当前对话框
	pCadWnd->SetFocus();
	BOOL bSucceed = GetEntLayerAddToJson(element);
	pCadWnd->EnableWindow(FALSE);
	this->ShowWindow(SW_SHOW);// 弹出对话框
	this->EnableWindow(TRUE);
	this->SetFocus();

	if (bSucceed)
	{
		m_layerGrid.RemoveAll(); JsonLayerNames.clear();
		BOOL bRet = ReadLayerDoc(element);
		if (bRet) AddGridItemFromJson();
	}
}

2、通过SHOWWINDOW消息

在消息映射中定义

ON_WM_SHOWWINDOW()

实现消息函数

afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
void CCableNodeMarkDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
  __super::OnShowWindow(bShow, nStatus);
  Acad::ErrorStatus es;
  if (bShow)
    es = acDocManager->disableDocumentActivation();
  else
    es = acDocManager->enableDocumentActivation();
}

3、自定义消息

假如对话框A中调用并弹出对话框B
两个对话框都定义:

#define WM_DLG_HIDE (WM_USER + 10001)
#define WM_DLG_SHOW (WM_USER + 10002)

A对话框中定义和实现消息函数

//消息映射中定义
ONMESSAGE(WM_DLG_HIDE,OnDlgHide)
ONMESSAGE(WM_DLG_HIDE,OnDlgShow)
//头文件中声明
afx_msg LRESULT OnDlgHide(WPARAM wp,LPARAM lp);
afx_msg LRESULT OnDlgShow(WPARAM wp,LPARAM lp);
hwndParent代表A对话框指针
//隐藏
通过MoveWindows最小化隐藏B对话框
通过BeginEditorCommand()进入选择状态
::SendMessage(hwndParent,WM_DLG_HIDE ,NULL,NULL);

//显示
通过MoveWindows最大化隐藏B对话框
通过CompleteEditorCommand()结束选择状态
::SendMessage(hwndParent,WM_DLG_HIDE ,NULL,NULL);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值