📄 tree.h
字号:
#include "stdafx.h"
////////////////////////////////////////////////////CList define//////////////////////////////////////////////////////////
template<class Type>
class Cvector_10{
protected:
struct CNode{ //list node type
Type elem; //element
CNode* next; //next pointer
};
int nsize;
CNode* head;
CNode* tail;
public:
Cvector_10(){
nsize = 0;
head = NULL;
tail = NULL;
}
~Cvector_10(){
while(this->size()){
this->erase(0);
}
}
//------------------------------------------------------------------------------------------------------------------------
void push_back(const Type& elem){
CNode* p = new CNode; //create a home node for the elem
p->elem = elem;
p->next = NULL;
if(tail){ //not empty
tail->next = p; //add to the end of the list, become the new tail
}else{ //empty list
head = p;
}
tail = p;
nsize++;
}
//-------------------------------------------------------------------------------------------------------------------------
void erase(int nindex){
if(nindex>=0 && nindex<nsize){
if(head==tail){ //has only one node
delete head;
head = NULL;
tail = NULL;
}else if(nindex==0){ //delete head node (list have at least two nodes)
CNode* q = head;
head = head->next;
delete q;
}else{
CNode* p = head;
for(int i=0; i<nindex-1; i++){ //find target node which is before p
p = p->next;
}
if(p->next==tail){ //target node is tail
delete tail;
tail = p;
}else{ //target node is between head and tail
CNode* r = p->next;
p->next = p->next->next;
delete r;
}
}
nsize--;
}
}
//-------------------------------------------------------------------------------------------------------------------------
void erase(const Type& elem){
if( head && head->elem==elem){ //delete head node
if(head==tail){ //has only one node
delete head;
head = NULL;
tail = NULL;
}else{ //has at least two nodes
CNode* q = head;
head = head->next;
delete q;
}
nsize--;
return;
}
CNode* p = NULL;
CNode* q = NULL; //record the p's forhead
for(p=head; p!=tail; q=p, p=p->next ){
if(p->elem==elem){ //find the target node
q->next = p->next; //target is between head and tail
delete p;
nsize--;
return;
}
}
if(p && p==tail && p->elem==elem){ //delete tail node
tail = q;
delete p;
nsize--;
}
}
//-------------------------------------------------------------------------------------------------------------------------
int size(){
return nsize;
}
Type& operator[](int i){
if(i>=0 && i<nsize){
CNode* p = NULL;
int j = 0;
for(j=0,p=head; j<i; j++,p=p->next);
return p->elem;
}
}
};
////////////////////////////////////////////////CTreeNode define//////////////////////////////////////////////////////////
class CTreeNode{
public:
void* pData;//无类型指针,可指向任何类型数据,用以保存额外的数据或对象
int nindex;//在兄弟结点中的序号
int id;
char *pcaption;//标题
CTreeNode* pparent;
Cvector_10<CTreeNode*> child_vector;
// vector<CTreeNode*> child_vector;//孩子结点列表
public:
CTreeNode();
CTreeNode* getFirstChild();
CTreeNode* getSibl_forder();
CTreeNode* getNext_forder();
int AppendChildNode(CTreeNode* pchildNode);//加入一个孩子结点,并返回加入的位序
bool operator==(const CTreeNode&)const;
};
////////////////////////////////////////////////CTree define//////////////////////////////////////////////////////////////
class CTree{
protected:
CTreeNode* proot;
public:
CTree(){
proot = NULL;
}
void AppendNode(CTreeNode* pparentNode, CTreeNode* pchildNode );
void DeleteNode(CTreeNode* pNode); //删除pNode为根的子树
//------------------------------------------------------------------------------------------------------------------------
CTreeNode* root(){
return proot;
}
};//class
////////////////////////////////////////////////CWinManager///////////////////////////////////////////////////////////////
class CWinManager:public CTree{
protected:
int nodeNum; //maxnum of active windows
// static CTreeNode* message_map(int x, int y);//暂时设成CWindow*, int,以后改成void, message
public:
Cvector_10<CTreeNode*> activeWinArry;
//------------------------------------------------------------------------------------------------------------------------
CWinManager():CTree(){
nodeNum = 1;
// proot->id = 0;
}
//------------------------------------------------------------------------------------------------------------------------
void AppendNode(CTreeNode* pparentNode, CTreeNode* pchildNode);
void DeleteNode(CTreeNode* pNode);
void renewWinArry(CTreeNode* pNode){
activeWinArry.erase(pNode);
activeWinArry.push_back(pNode);
}
//------------------------------------------------------------------------------------------------------------------------
int getnum(){
return nodeNum;
}
//------------------------------------------------------------------------------------------------------------------------
void winRedraw(){
// for(int i=0; i<activeWinArry.size(); i++);
}
};
class CWindow;
////////////////////////////////////////////////CMessage//////////////////////////////////////////////////////////////////
class CMessage{
public:
int x;
int y;
int mssgtype;
int wparam;
int lparam;
CWindow* hwnd;
public:
CMessage (int x=0, int y=0, int mssgtype=0, int wparam=0, int lparam=0, CWindow* hwnd=NULL){
this->x = x;
this->y = y;
this->mssgtype = mssgtype;
this->wparam = wparam;
this->lparam = lparam;
this->hwnd = hwnd;
}
};
////////////////////////////////////////////////CWindow///////////////////////////////////////////////////////////////////
class CWindow{
private:
CWindow* phwnd; //父窗口句柄
CWindow* hwnd; //窗口句柄
static CWindow* fhwnd; //焦点控件句柄
//private:
public:
static CWinManager* winMnger;//窗口管理器
CTreeNode* phomeNode;//窗口所属树结点
static int winNum;
public:
int x; //起始坐标
int y; //起始坐标
int width; //宽度
int lenth; //长度
char* caption; //标题
int wintype; //窗口类型 0:win,1:text,2:button
void(*OnClick)(CMessage* pmssg);//单击响应函数
void(*OnKeyDown)(CMessage* pmssg);//按键响应函数
public:
//------------------------------------------------------------------------------------------------------------------------
CWindow( int x, int y, int width, int lenth, CWindow* phwndL, char* caption);
//------------------------------------------------------------------------------------------------------------------------
~CWindow(){
delete phomeNode;
winNum--;
if(winNum==0){
delete CWindow::winMnger;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -