From e22f8064802ecba389bf146d0eea57d7a88df326 Mon Sep 17 00:00:00 2001 From: xiaowei_han Date: Sun, 18 Jun 2017 23:19:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=9A=84TreeCtrl=E6=8E=A7=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp | 36 +++++++++ Src/Edislab/Edislab Pro/CustomTreeCtrl.h | 12 +++ .../Edislab Pro/DlgDataGroupProperty.cpp | 8 +- Src/Edislab/Edislab Pro/DlgDataSetting.cpp | 77 +++++++++++++++++-- Src/Edislab/Edislab Pro/DlgDataSetting.h | 7 +- Src/Edislab/Edislab Pro/Edislab Pro.vcxproj | 2 + .../Edislab Pro/Edislab Pro.vcxproj.filters | 6 ++ .../Edislab Pro/GridColumnGroupManager.cpp | 23 ++++++ .../Edislab Pro/GridColumnGroupManager.h | 3 + Src/Edislab/Edislab Pro/Msg.h | 3 + 10 files changed, 167 insertions(+), 10 deletions(-) create mode 100644 Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp create mode 100644 Src/Edislab/Edislab Pro/CustomTreeCtrl.h diff --git a/Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp b/Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp new file mode 100644 index 0000000..d1ae2ec --- /dev/null +++ b/Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp @@ -0,0 +1,36 @@ +#include "StdAfx.h" +#include "CustomTreeCtrl.h" +#include "Msg.h" +IMPLEMENT_DYNAMIC(CCustomTreeCtrl, CBCGPTreeCtrlEx) + +CCustomTreeCtrl::CCustomTreeCtrl(void) +{ +} + + +CCustomTreeCtrl::~CCustomTreeCtrl(void) +{ +} + +BEGIN_MESSAGE_MAP(CCustomTreeCtrl, CBCGPTreeCtrlEx) + ON_WM_LBUTTONDBLCLK() +END_MESSAGE_MAP() + +void CCustomTreeCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) +{ + // TODO: 在此添加消息处理程序代码和/或调用默认值 + + HTREEITEM hDBClikeItem = HitTest(point); + + if (NULL != hDBClikeItem) + { + CWnd* pWnd = GetParent(); + + if (nullptr != pWnd) + { + pWnd->PostMessage(WM_NOTIFY_TREE_CTRL_DBCLICK,(WPARAM)hDBClikeItem,0); + } + } + + CBCGPTreeCtrlEx::OnLButtonDblClk(nFlags, point); +} diff --git a/Src/Edislab/Edislab Pro/CustomTreeCtrl.h b/Src/Edislab/Edislab Pro/CustomTreeCtrl.h new file mode 100644 index 0000000..14085af --- /dev/null +++ b/Src/Edislab/Edislab Pro/CustomTreeCtrl.h @@ -0,0 +1,12 @@ +#pragma once +class CCustomTreeCtrl : public CBCGPTreeCtrlEx +{ + DECLARE_DYNAMIC(CCustomTreeCtrl) +public: + CCustomTreeCtrl(void); + virtual ~CCustomTreeCtrl(void); + + DECLARE_MESSAGE_MAP() + afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); +}; + diff --git a/Src/Edislab/Edislab Pro/DlgDataGroupProperty.cpp b/Src/Edislab/Edislab Pro/DlgDataGroupProperty.cpp index d4c30c5..deaeaf6 100644 --- a/Src/Edislab/Edislab Pro/DlgDataGroupProperty.cpp +++ b/Src/Edislab/Edislab Pro/DlgDataGroupProperty.cpp @@ -5,7 +5,7 @@ #include "Edislab Pro.h" #include "DlgDataGroupProperty.h" #include "Utility.h" - +#include "GridColumnGroupManager.h" // CDlgDataGroupProperty 对话框 IMPLEMENT_DYNAMIC(CDlgDataGroupProperty, CBaseDialog) @@ -82,8 +82,12 @@ void CDlgDataGroupProperty::OnBnClickedBtnOk() return; } + if (CGridColumnGroupManager::CreateInstance().IsHeaderNameExist(strGroupName)) + { + Utility::AfxBCGPMessageBox(_T("该数据组已经存在,请输入另外一个名字!"),MB_OK | MB_ICONERROR); + return; + } m_strGroupName = strGroupName; - OnOK(); } diff --git a/Src/Edislab/Edislab Pro/DlgDataSetting.cpp b/Src/Edislab/Edislab Pro/DlgDataSetting.cpp index f40fad1..5d3ad41 100644 --- a/Src/Edislab/Edislab Pro/DlgDataSetting.cpp +++ b/Src/Edislab/Edislab Pro/DlgDataSetting.cpp @@ -25,6 +25,10 @@ CDlgDataSetting::CDlgDataSetting(CWnd* pParent /*=NULL*/) m_strDefaultGroupNameArray.clear(); DEFAULT_GROUP_NAME TempGroupName; + + TempGroupName.strName = _T("历史组"); + m_strDefaultGroupNameArray.push_back(TempGroupName); + TempGroupName.strName = _T("历史组_1"); m_strDefaultGroupNameArray.push_back(TempGroupName); @@ -43,8 +47,7 @@ CDlgDataSetting::CDlgDataSetting(CWnd* pParent /*=NULL*/) TempGroupName.strName = _T("历史组_6"); m_strDefaultGroupNameArray.push_back(TempGroupName); - TempGroupName.strName = _T("历史组_7"); - m_strDefaultGroupNameArray.push_back(TempGroupName); + } CDlgDataSetting::~CDlgDataSetting() @@ -64,6 +67,8 @@ BEGIN_MESSAGE_MAP(CDlgDataSetting, CBaseDialog) ON_BN_CLICKED(IDC_BTN_ADD_DATA_GROUP, &CDlgDataSetting::OnBnClickedBtnAddDataGroup) ON_BN_CLICKED(IDC_BTN_ADD_DATA_COLUMN, &CDlgDataSetting::OnBnClickedBtnAddDataColumn) ON_BN_CLICKED(IDC_BTN_OPT, &CDlgDataSetting::OnBnClickedBtnOpt) + ON_WM_LBUTTONDBLCLK() + ON_MESSAGE(WM_NOTIFY_TREE_CTRL_DBCLICK,&CDlgDataSetting::NotifyTreeDBClick) END_MESSAGE_MAP() @@ -329,20 +334,80 @@ void CDlgDataSetting::OnBnClickedBtnOpt() //判断是否是组节点 if (TRUE == m_Tree.ItemHasChildren(hSelectItem)) { - CString strGroupName = m_Tree.GetItemText(hSelectItem); + CString strOldGroupName = m_Tree.GetItemText(hSelectItem); - CDlgDataGroupProperty Dlg(strGroupName); + CDlgDataGroupProperty Dlg(strOldGroupName); if (IDOK == Dlg.DoModal()) { - strGroupName = Dlg.GetGroupName(); + CString strNewGroupName = Dlg.GetGroupName(); - m_Tree.SetItemText(hSelectItem,strGroupName); + m_Tree.SetItemText(hSelectItem,strNewGroupName); m_Tree.AdjustLayout(); //通知Grid组名修改 + CGridColumnGroupManager::CreateInstance().ModifyHeaderInfo(strOldGroupName,strNewGroupName); + + //通知Grid刷新 + CWnd* pWnd = AfxGetMainWnd(); + if (nullptr != pWnd) + { + pWnd->PostMessage(WM_NOTIFY_GRID_GROUP_INFO_CHANGE,0,0); + } } } } + + +void CDlgDataSetting::OnLButtonDblClk(UINT nFlags, CPoint point) +{ + // TODO: 在此添加消息处理程序代码和/或调用默认值 + + CBaseDialog::OnLButtonDblClk(nFlags, point); +} + +LRESULT CDlgDataSetting::NotifyTreeDBClick(WPARAM wp,LPARAM lp) +{ + + HTREEITEM hItem = (HTREEITEM)wp; + + + if (NULL != hItem) + { + + if (TRUE == m_Tree.ItemHasChildren(hItem)) + { + CString strOldGroupName = m_Tree.GetItemText(hItem); + + CDlgDataGroupProperty Dlg(strOldGroupName); + + if (IDOK == Dlg.DoModal()) + { + CString strNewGroupName = Dlg.GetGroupName(); + + m_Tree.SetItemText(hItem,strNewGroupName); + + m_Tree.AdjustLayout(); + + //通知Grid组名修改 + CGridColumnGroupManager::CreateInstance().ModifyHeaderInfo(strOldGroupName,strNewGroupName); + + //通知Grid刷新 + CWnd* pWnd = AfxGetMainWnd(); + if (nullptr != pWnd) + { + pWnd->PostMessage(WM_NOTIFY_GRID_GROUP_INFO_CHANGE,0,0); + } + } + } + else + { + //弹出其他对话框 + } + } + + + return 0L; +} diff --git a/Src/Edislab/Edislab Pro/DlgDataSetting.h b/Src/Edislab/Edislab Pro/DlgDataSetting.h index ed2f215..7791d8f 100644 --- a/Src/Edislab/Edislab Pro/DlgDataSetting.h +++ b/Src/Edislab/Edislab Pro/DlgDataSetting.h @@ -1,7 +1,7 @@ #pragma once #include #include "BaseDialog.h" - +#include "CustomTreeCtrl.h" typedef struct _default_group_name { CString strName; @@ -35,7 +35,7 @@ class CDlgDataSetting : public CBaseDialog void InitDisplay(void); private: - CBCGPTreeCtrlEx m_Tree; + CCustomTreeCtrl m_Tree; CStatic m_TreeRect; public: afx_msg void OnBnClickedBtnQuit(); @@ -49,4 +49,7 @@ class CDlgDataSetting : public CBaseDialog std::vector m_strDefaultGroupNameArray; public: afx_msg void OnBnClickedBtnOpt(); + afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); + + afx_msg LRESULT NotifyTreeDBClick(WPARAM wp,LPARAM lp); }; diff --git a/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj b/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj index 6a6e10c..04eb0a4 100644 --- a/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj +++ b/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj @@ -236,6 +236,7 @@ + @@ -299,6 +300,7 @@ + diff --git a/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj.filters b/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj.filters index 76afdc6..7028722 100644 --- a/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj.filters +++ b/Src/Edislab/Edislab Pro/Edislab Pro.vcxproj.filters @@ -318,6 +318,9 @@ 澶存枃浠 + + 澶存枃浠 + @@ -482,6 +485,9 @@ 婧愭枃浠 + + 婧愭枃浠 + diff --git a/Src/Edislab/Edislab Pro/GridColumnGroupManager.cpp b/Src/Edislab/Edislab Pro/GridColumnGroupManager.cpp index bde18ff..e40cfbe 100644 --- a/Src/Edislab/Edislab Pro/GridColumnGroupManager.cpp +++ b/Src/Edislab/Edislab Pro/GridColumnGroupManager.cpp @@ -336,4 +336,27 @@ void CGridColumnGroupManager::RemoveHeader( const CString& strHeaderName ) } } +void CGridColumnGroupManager::ModifyHeaderInfo(const CString& strOldName,const CString& strNewName) +{ + if (strOldName.IsEmpty() || strNewName.IsEmpty()) + { + return; + } + + //查找行头信息 + auto HeaderPred = [&strOldName](const COLUMN_GROUP_INFO& Info)->bool + { + if (Info.strGroupName == strOldName) + { + return true; + } + return false; + }; + auto HeaderIter = std::find_if(m_HeaderInfoArray.begin(),m_HeaderInfoArray.end(),HeaderPred); + if (HeaderIter != m_HeaderInfoArray.end()) + { + HeaderIter->strGroupName = strNewName; + } +} + CGridColumnGroupManager CGridColumnGroupManager::s_obj; diff --git a/Src/Edislab/Edislab Pro/GridColumnGroupManager.h b/Src/Edislab/Edislab Pro/GridColumnGroupManager.h index 2c1b4ae..b63950a 100644 --- a/Src/Edislab/Edislab Pro/GridColumnGroupManager.h +++ b/Src/Edislab/Edislab Pro/GridColumnGroupManager.h @@ -32,6 +32,9 @@ class CGridColumnGroupManager //移除某一表头 void RemoveHeader(const CString& strHeaderName); + + //修改组名 + void ModifyHeaderInfo(const CString& strOldName,const CString& strNewName); protected: CGridColumnGroupManager(void); ~CGridColumnGroupManager(void); diff --git a/Src/Edislab/Edislab Pro/Msg.h b/Src/Edislab/Edislab Pro/Msg.h index 2a33d0c..99a2ef0 100644 --- a/Src/Edislab/Edislab Pro/Msg.h +++ b/Src/Edislab/Edislab Pro/Msg.h @@ -20,6 +20,9 @@ enum MESSAGE //通知Grid的分组信息改变 WM_NOTIFY_GRID_GROUP_INFO_CHANGE, + //TreeCtrl上双击 + WM_NOTIFY_TREE_CTRL_DBCLICK, + //监测到了新设备 WM_NOTIFY_DETECT_DEVICE,