-
Notifications
You must be signed in to change notification settings - Fork 2
/
TreeList.cpp
220 lines (179 loc) · 5.25 KB
/
TreeList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// TreeList.cpp : implementation file
//
#include "stdafx.h"
#include "HustBaseDoc.h"
#include "HustBase.h"
#include "TreeList.h"
#include "TableList.h"
#include "EditArea.h"
#include "str.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTreeList
class HustBase;
IMPLEMENT_DYNCREATE(CTreeList, CTreeView)
CTreeList::CTreeList()
{
}
CTreeList::~CTreeList()
{
}
bool CTreeList::openorNot=true;
BEGIN_MESSAGE_MAP(CTreeList, CTreeView)
//{{AFX_MSG_MAP(CTreeList)
ON_WM_CREATE()
ON_WM_SIZE()
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
// ON_COMMAND(ID_OPENDB, OnOpenDB)
// ON_UPDATE_COMMAND_UI(ID_OPENDB, OnUpdateDB)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CTreeList::OnCreate(LPCREATESTRUCT lpcs)
{
if (CTreeView::OnCreate(lpcs)==-1)
{
return -1;
}
GetDocument()->m_pTreeView = this;
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CTreeList drawing
void CTreeList::OnDraw(CDC* pDC)
{
CHustBaseDoc* pDoc = GetDocument();
ASSERT(pDoc);
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CTreeList diagnostics
#ifdef _DEBUG
void CTreeList::AssertValid() const
{
CTreeView::AssertValid();
}
void CTreeList::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CHustBaseDoc* CTreeList::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHustBaseDoc)));
return (CHustBaseDoc*)m_pDocument;
}
#endif //_DEBUG
void CTreeList::OnSize(UINT nType, int cx, int cy)
{
this->ShowWindow(SW_MAXIMIZE);
CWnd *pChild = this->GetWindow(GW_CHILD);
if (pChild!=NULL)
{
CRect rect;
this->GetWindowRect(&rect);
pChild->ScreenToClient(&rect);
pChild->SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(),
SWP_NOACTIVATE | SWP_NOZORDER);
}
}
/////////////////////////////////////////////////////////////////////////////
// CTreeList message handlers
void CTreeList::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
GetTreeCtrl().ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
// TODO: Add your specialized code here and/or call the base class
}
void CTreeList::InsertDBNodes()
{
// _dic_type dicStruct;
HTREEITEM hItem, hsubItem, hCItem;
hsubItem = NULL;
char tabname[20][20];
char colname[20][20][20];
AttrType coltype[20][20];
int tabnum,colnum[20];
int collength[20][20];
int coloffset[20][20];
int iscolix[20][20];
//**************************小图标
CImageList *m_pImageList = new CImageList();
m_pImageList->Create(IDB_BITMAP1,15,3,RGB(0,0,0));
bm.LoadBitmap(IDB_BITMAP2); //表
m_pImageList->Add(&bm, RGB(0, 0, 0));
bm.DeleteObject();
bm.LoadBitmap(IDB_BITMAP3); //列
m_pImageList->Add(&bm, RGB(0, 0, 0));
bm.DeleteObject();
bm.LoadBitmap(IDB_BITMAP4); //文件
m_pImageList->Add(&bm, RGB(0, 0, 0));
bm.DeleteObject();
GetTreeCtrl().SetImageList(m_pImageList,TVSIL_NORMAL);
//**************************小图标
GetDocument()->m_pEditView->iReadDictstruct(tabname,&tabnum,colname,colnum,coltype,collength,coloffset,iscolix);
for (int i=0; i<tabnum; i++)
{
hItem = GetTreeCtrl().InsertItem(tabname[i],1,1, TVI_ROOT);
hCItem = GetTreeCtrl().InsertItem("列", 3, 3, hItem);
for (int j=0; j < colnum[i]; j++)
{
if(iscolix[i][j]==0)
hsubItem = GetTreeCtrl().InsertItem(colname[i][j],2,2,hCItem,hsubItem);//无索引时的图标
else
hsubItem = GetTreeCtrl().InsertItem(colname[i][j],0,0,hCItem,hsubItem);//有索引时的图标
}
hsubItem = NULL;
}
}
HTREEITEM CTreeList::InsertNode(const HTREEITEM ParentNode, const CString &str, const DWORD itemData)
{
CTreeCtrl &treeCtrl = GetTreeCtrl();
HTREEITEM node;
node = treeCtrl.InsertItem(str, ParentNode, TVI_SORT);
treeCtrl.SetItemData(node, itemData);
return node;
}
void CTreeList::PopulateTree()
{
GetTreeCtrl().DeleteAllItems();
GetDocument()->m_pListView->ClearList(); //等待修改
openorNot=true;
InsertDBNodes();
}
void CTreeList::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
// if (GetDocument()->isEdit)
// {
// InsertNode(TVI_ROOT, GetDocument()->get_text, 0);
// }
}
void CTreeList::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) //选中某个选项,显示其信息,Tree和List的一个桥梁函数
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;
CString ItemText;
CHustBaseDoc * pDoc = GetDocument();
// Obtain a reference to the CTreeControl object that is
// embedded in this view class.
CTreeCtrl & ctlTree = GetTreeCtrl();
// Determining which item the user has selected is a 2-step
// process. You first obtain the handle to the selected item.
HTREEITEM selectedNode = ctlTree.GetSelectedItem();
// In the second step, you call a specific function
// (GetItemText, GetItemData, GetItemState or GetItemImage)
// to obtain a specific piece of information from the selected item,
if(ctlTree.ItemHasChildren(selectedNode)==1)//点击的节点存在子项则做进一步处理,不存在子项即点击的项目为列名,不做处理
{
ItemText = ctlTree.GetItemText(selectedNode);
// For root nodes, the list will iterate over the selected
// item and display all the types it contains.
if (openorNot)
{
pDoc->m_pListView->displayTabInfo(ItemText);
}
}
}