⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.h

📁 自己实现的一个好用的嵌入式GUI
💻 H
📖 第 1 页 / 共 2 页
字号:
		}
	}	
	void getfocus();
	virtual void freefocus(){};
//------------------------------------------------------------------------------------------------------------------------
	bool capture(int x, int y){
		return (x>this->x && x<this->x+width 
			&& y>this->y && y<this->y+lenth);
	}
	virtual void drawin(){}  //draw this win
	virtual void closewin(){} //close a win with some resource ,like CText
	void drawindow();
	void showindow();
	virtual void closewindow(){};
	CWindow* get_hwnd(){return hwnd;}
    CWindow* get_phwnd(){return phwnd;}
 	void set_phwnd(CWindow* phwnd);
	virtual void winProc(CMessage* pmssg);
    static CWindow* get_fhwnd(){return fhwnd;};
};//class CWindow

////////////////////////////////////////////////CButton///////////////////////////////////////////////////////////////////
class CButtn:public CWindow{
public:
	CButtn(int x=0, int y=0, int width=0, int lenth=0, CWindow* phwnd=NULL, char* caption="myButton")
		:CWindow(x, y, width, lenth, phwnd, caption){
		wintype = 2;        //button
	}
	void drawin(){
		CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
        pDC->Rectangle(CRect(x, y+10, x+width, y+lenth));
		pDC->TextOut(x+15, y+20, caption); 
	}
};



////////////////////////////////////////////////CClsButton///////////////////////////////////////////////////////////////////

class CClsButtn:public CButtn{
public:
	CClsButtn(int x=0, int y=0, int width=0, int lenth=0, CWindow* phwnd=NULL, char* caption="X")
		:CButtn(x, y, width, lenth, phwnd, caption){};
private:	
	void winProc(CMessage* pmssg){
		CButtn::winProc(pmssg);
		switch(pmssg->mssgtype){
		default:
			if(this->phomeNode->pparent){
				CWindow* pwin = (CWindow*)this->phomeNode->pparent->pData;
				pwin->closewindow();
			}
		}
	}
};

////////////////////////////////////////////////CPagdwnButton///////////////////////////////////////////////////////////////////
class CText;

////////////////////////////////////////////////CText//////////////////////////////////////////////////////////////////////
//#define buffsize 500
static const int buttnsize = 30;
static const int buffsize = 500;
class CText:public CWindow{
public:
   
    int font_x;    //字体尺寸
    int font_y;
private:
	char text[buffsize];//字符缓冲区
    int curpos;    //光标位置
    int endpos;    //结束字符位置
    int curline;   //光标在的行数
    int curcol;    //光标在的列数
    int endline;   //结束字符在的行数
    int endcol;    //结束字符在的列数
    int linegap;   //行距(font_y的倍数)
	int dspstartline; //显示起始行
//	int dspendline;//显示结束行
	int cperline;   //一行最大字符数
	int cpercol;    //一例最大字符数
public:
	CText(int x=0, int y=0, int width=0, int lenth=0, CWindow* phwnd=NULL, char* caption= "myText")
		:CWindow(x, y, width, lenth, phwnd, caption){
		wintype = 1;        //text
		text[0] = '\0';
        font_x = 8;
        font_y = 16;
        curpos = 0;
        endpos = 0;
        endline = 0;
        endcol = 0;
		dspstartline = 0;
        linegap = 1.2*font_y;
	    cperline = (width)/font_x;
	    cpercol = lenth/linegap;
	}
//------------------------------------------------------------------------------------------------------------------------
	void winProc(CMessage* pmssg);
	void input(char c);
//------------------------------------------------------------------------------------------------------------------------
	void clearscrn(int x0, int y0, int x1, int y1 ){
		CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
		pDC->Rectangle(CRect(x0, y0, x1, y1));
	}
//------------------------------------------------------------------------------------------------------------------------
   void textout();
   void drawin();

   void closewin(){
		text[0] = '\0';
		curpos = 0;
        endpos = 0;
        endline = 0;
        endcol = 0;
		dspstartline = 0;
   }
//------------------------------------------------------------------------------------------------------------------------
	void linedown(){
		if(dspstartline<endline-1){
			dspstartline++;
		}
	}
//------------------------------------------------------------------------------------------------------------------------
    void pagedown(){
		if(dspstartline+cpercol-2>endline){
			dspstartline = endline;
			}else{
				dspstartline += (cpercol-2);
			}
	}
//------------------------------------------------------------------------------------------------------------------------
	void pageup(){
		if(dspstartline-(cpercol-2)<0){
			dspstartline = 0;
		}else{
			dspstartline -= (cpercol-2);
		}
	}
//------------------------------------------------------------------------------------------------------------------------
 
	void delet(){
		int cperline = width/font_x;
		if(endpos>0){
		
			for(int i=curpos; i<=endpos; i++){
				text[i-1] = text[i];
			} 
			curpos--;
			endpos--;
			endcol = endpos%cperline; 
			endline = endpos/cperline;
			curcol = (curpos)%cperline;
			curline = (curpos)/cperline;
			
		}
	}
//------------------------------------------------------------------------------------------------------------------------
 
	void moveleft(){
		if(curpos>0){
			curpos--;
			curcol = curpos%cperline;
			curline = curpos/cperline;
		}
	}
//------------------------------------------------------------------------------------------------------------------------
 
	void moveright(){
		if(curpos<endpos){
			curpos++;
            curcol = curpos%cperline;
			curline = curpos/cperline;
		}
	}
//------------------------------------------------------------------------------------------------------------------------
 
	void enter(){
//		for(int i=0; i<cperline-curcol; i++){
//			input(32) ;//空格
//		}
	}
//------------------------------------------------------------------------------------------------------------------------
 
	void freefocus(){
		//erase the cursor
		CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
		pDC->TextOut(this->x+curcol*font_x+4, this->y+12+(curline-dspstartline)*linegap, " ");//erase the cursor
	}
	

};

////////////////////////////////////////////////CWin//////////////////////////////////////////////////////////////////////
//void closewin (CMessage* pmssg){CWin::closewindow();};
class CWin: public CWindow{
private:
	CClsButtn* pclsBtn; 
//	void closeWin(CMessage* pmssg){closeWindow();};//单击响应函数
public:
	CWin(int x=0, int y=0, int width=0, int lenth=0, CWindow* phwnd=NULL, char* caption="myWindow")
		:CWindow(x, y, width, lenth, phwnd, caption){
		//add close button on the right-top conner
		
		if(winNum!=0){//desktop need not closebutton
			pclsBtn = new CClsButtn(x+width-30, y-10, 30, 40, this, "X");
		}
	};
	
	~CWin(){
			delete pclsBtn;
	}
	void drawin(){
		CDC *pDC = (AfxGetApp()->m_pMainWnd)->GetDC();
		pDC->Rectangle(CRect(x, y, x+width, y+lenth));
		pDC->Rectangle(CRect(x, y, x+width, y+30));
		pDC->TextOut(x+5, y+5, caption); 
	}

    void closewindow(){
		CWindow* pwin = NULL;
		Cvector_10<CTreeNode*>& theArry = CWindow::winMnger->activeWinArry;

        //hide the win and clear the buffer
		theArry.erase(this->phomeNode);
		Cvector_10<CTreeNode*>& thechildArry = this->phomeNode->child_vector;
		for(int j=0; j<thechildArry.size(); j++){
			pwin = (CWindow*)thechildArry[j]->pData;
			pwin->closewin();                 //release char in the text
		}
        //fresh the desktop
		pwin = (CWindow*)CWindow::winMnger->root()->pData;
		pwin->drawin(); 
		for(int i=1; i<theArry.size(); i++){//遍历活动窗口栈,note: activeArry[0]is root node
			pwin = (CWindow*)theArry[i]->pData;
			pwin->drawindow();//画出所有活动窗口(及所有子窗口),and pushu the main win to theArry                                                             子窗口)
		}
	}

};



////////////////////////////////////////////////globe fuctiion////////////////////////////////////////////////////////////

void message_map(CMessage* pmssg);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -