Skip to content

Commit

Permalink
上传自定义的TreeCtrl控件。
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweihan committed Jun 18, 2017
1 parent eaa9e5e commit e22f806
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 10 deletions.
36 changes: 36 additions & 0 deletions Src/Edislab/Edislab Pro/CustomTreeCtrl.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
12 changes: 12 additions & 0 deletions Src/Edislab/Edislab Pro/CustomTreeCtrl.h
Original file line number Diff line number Diff line change
@@ -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);
};

8 changes: 6 additions & 2 deletions Src/Edislab/Edislab Pro/DlgDataGroupProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Edislab Pro.h"
#include "DlgDataGroupProperty.h"
#include "Utility.h"

#include "GridColumnGroupManager.h"
// CDlgDataGroupProperty 对话框

IMPLEMENT_DYNAMIC(CDlgDataGroupProperty, CBaseDialog)
Expand Down Expand Up @@ -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();
}

Expand Down
77 changes: 71 additions & 6 deletions Src/Edislab/Edislab Pro/DlgDataSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()
Expand All @@ -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()


Expand Down Expand Up @@ -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;
}
7 changes: 5 additions & 2 deletions Src/Edislab/Edislab Pro/DlgDataSetting.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include "BaseDialog.h"

#include "CustomTreeCtrl.h"
typedef struct _default_group_name
{
CString strName;
Expand Down Expand Up @@ -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();
Expand All @@ -49,4 +49,7 @@ class CDlgDataSetting : public CBaseDialog
std::vector<DEFAULT_GROUP_NAME> m_strDefaultGroupNameArray;
public:
afx_msg void OnBnClickedBtnOpt();
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);

afx_msg LRESULT NotifyTreeDBClick(WPARAM wp,LPARAM lp);
};
2 changes: 2 additions & 0 deletions Src/Edislab/Edislab Pro/Edislab Pro.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<ClInclude Include="CParagraphFormat.h" />
<ClInclude Include="CSelection.h" />
<ClInclude Include="CustomGrid.h" />
<ClInclude Include="CustomTreeCtrl.h" />
<ClInclude Include="DataDefine.h" />
<ClInclude Include="DlgAcquirationPara.h" />
<ClInclude Include="DlgAddPage.h" />
Expand Down Expand Up @@ -299,6 +300,7 @@
<ClCompile Include="ConcreteTabWnd.cpp" />
<ClCompile Include="ConverEncode.cpp" />
<ClCompile Include="CustomGrid.cpp" />
<ClCompile Include="CustomTreeCtrl.cpp" />
<ClCompile Include="DlgAcquirationPara.cpp" />
<ClCompile Include="DlgAddPage.cpp" />
<ClCompile Include="DlgChartSet.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Src/Edislab/Edislab Pro/Edislab Pro.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@
<ClInclude Include="DlgDataGroupProperty.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CustomTreeCtrl.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Edislab Pro.cpp">
Expand Down Expand Up @@ -482,6 +485,9 @@
<ClCompile Include="DlgDataGroupProperty.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CustomTreeCtrl.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Edislab Pro.rc">
Expand Down
23 changes: 23 additions & 0 deletions Src/Edislab/Edislab Pro/GridColumnGroupManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions Src/Edislab/Edislab Pro/GridColumnGroupManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class CGridColumnGroupManager

//移除某一表头
void RemoveHeader(const CString& strHeaderName);

//修改组名
void ModifyHeaderInfo(const CString& strOldName,const CString& strNewName);
protected:
CGridColumnGroupManager(void);
~CGridColumnGroupManager(void);
Expand Down
3 changes: 3 additions & 0 deletions Src/Edislab/Edislab Pro/Msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ enum MESSAGE
//通知Grid的分组信息改变
WM_NOTIFY_GRID_GROUP_INFO_CHANGE,

//TreeCtrl上双击
WM_NOTIFY_TREE_CTRL_DBCLICK,

//监测到了新设备
WM_NOTIFY_DETECT_DEVICE,

Expand Down

0 comments on commit e22f806

Please sign in to comment.