BOOL CIfExpressEditorDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	ASSERT(pMsg != NULL);
	if (pMsg->message==WM_LBUTTONDOWN)
	{
		ZTools::WriteZToolsFormatLog("WM_LBUTTONDOWN");
		if (m_wndTreeDropDown.IsWindowVisible())
		{
			m_wndTreeDropDown.ShowWindow(SW_HIDE);
			ZTools::WriteZToolsFormatLog("鼠标点击隐藏树,失去焦点后");
			return TRUE; // 本次点击只隐藏树
		}
		int iTickTime = GetTickCount();
		int iGapTime  = iTickTime - m_iTickCountTreeLeaveFocus;
		if (CPoint(pMsg->pt) == m_PointTreeLeaveFocus && iGapTime < 100)
		{
			ZTools::WriteZToolsFormatLog("鼠标点击使得树失去焦点而隐藏,失去焦点前");
			return TRUE; //屏蔽隐藏树前的点击事件
		}

		CRect rect;
		bool bShowTree = FALSE;
		CCxStructTreeNode *pNodeCur = NULL;
		CString strArrID;
		CString strTextArry;
		if ( pMsg->hwnd == m_EditLeft.GetSafeHwnd())
		{
			bShowTree = TRUE;
			m_EditLeft.GetWindowRect(&rect);
			pNodeCur = m_pNodeLeft;
			if (!m_Express.m_LeftParam.strArry.IsEmpty())
			{
				strArrID = m_Express.m_LeftParam.strID;
				m_EditLeftArry.GetWindowText(strTextArry);
			}
			m_iFocusEidtPCtrlID = IDC_EDIT_LEFT;
		}
		else if (pMsg->hwnd == m_EditRight.GetSafeHwnd())
		{
			if (pMsg->hwnd == m_EditRight.GetSafeHwnd() && m_ComboRightType.GetCurSel()==TP_CONST)
				bShowTree = FALSE;
			else
			{
				bShowTree = TRUE;
				m_EditRight.GetWindowRect(&rect);
				pNodeCur = m_pNodeRight;
				if (!m_Express.m_RightParam.strArry.IsEmpty())
				{
					strArrID = m_Express.m_RightParam.strID;
					m_EditRightArry.GetWindowText(strTextArry);
				}
			}
			m_iFocusEidtPCtrlID = IDC_EDIT_RIGHT;
		}
	
		if (bShowTree)
		{
			if (pNodeCur)
			{
				if (!strTextArry.IsEmpty())
				{
					CCxStructTreeNode *pDefaultSel = FindArryElementNode(strArrID,strTextArry);
					if (pDefaultSel)
					 pNodeCur = pDefaultSel;
				}

				CBCGPGridRow* pSel = m_wndTreeDropDown.m_IfEditTree.FindRowByData((DWORD_PTR)pNodeCur);
				m_wndTreeDropDown.m_IfEditTree.SetCurSel(pSel);
				m_wndTreeDropDown.m_IfEditTree.UpdateSelToParamName(); //选中树的第一列
				if (pSel)
				{
					ASSERT_VALID (pSel);
					CBCGPGridRow* pParent = pSel;
					while ((pParent = pParent->GetParent ())!= NULL &&pParent->GetSubItemsCount()>0)
					{
						ASSERT_VALID (pParent);
						pParent->Expand (TRUE);
					}
					m_wndTreeDropDown.m_IfEditTree.EnsureVisible (pSel, TRUE); // 保证当前选中行可见
				}
			}
			else
			{
				m_wndTreeDropDown.m_IfEditTree.SelectRow(-1);
				m_wndTreeDropDown.m_IfEditTree.ExpandAll(FALSE);
			}
			m_wndTreeDropDown.SetWindowPos(&wndTopMost,rect.left,rect.bottom,0,0,SWP_NOSIZE|SWP_SHOWWINDOW);
			m_wndTreeDropDown.m_IfEditTree.SetFocus();
			return TRUE;
		}
	}
	return CCxBCGPDialog::PreTranslateMessage(pMsg);
}