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

📄 tabclassview.cpp

📁 类似vc的集成开发环境
💻 CPP
字号:
// TabClassView.cpp : implementation of the CTabClassView class
//

#include "stdafx.h"
#include "C02IDE.h"

#include "TabClassDoc.h"
#include "TabClassView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTabClassView

IMPLEMENT_DYNCREATE(CTabClassView, CTreeView)

BEGIN_MESSAGE_MAP(CTabClassView, CTreeView)
	//{{AFX_MSG_MAP(CTabClassView)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTabClassView construction/destruction

CTabClassView::CTabClassView()
{
	// TODO: add construction code here
	m_pTreeCtrlcompile = NULL;
}

CTabClassView::~CTabClassView()
{
}

BOOL CTabClassView::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CTreeView::PreCreateWindow( cs ))
		return FALSE;

	// set the style for the tree control.
	cs.style |= TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CTabClassView drawing

void CTabClassView::OnDraw(CDC* pDC)
{
	CTabClassDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void CTabClassView::OnInitialUpdate()
{
	CTreeView::OnInitialUpdate();

	
	if(!m_pTreeCtrlcompile)
	{
		m_pTreeCtrlcompile = &GetTreeCtrl();

//		m_pTreeCtrlcompile->Create(
		// Create the image list for the tree control
		m_ImageList.Create (IDB_IL_CLASS, 16, 1, RGB(0,255,0));
		m_pTreeCtrlcompile->SetImageList (&m_ImageList, TVSIL_NORMAL);
	}
	// TODO: You may populate your TreeView with items by directly accessing
	//  its tree control through a call to GetTreeCtrl().
}

/////////////////////////////////////////////////////////////////////////////
// CTabClassView printing

BOOL CTabClassView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTabClassView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTabClassView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTabClassView diagnostics

#ifdef _DEBUG
void CTabClassView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CTabClassView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}

CTabClassDoc* CTabClassView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabClassDoc)));
	return (CTabClassDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTabClassView message handlers

void CTabClassView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class

}

void CTabClassView::UpdateView()
{
	//如果树形控件不存在
	if(!m_pTreeCtrlcompile)
		//初始化树形控件
		OnInitialUpdate();

	//树形控件存在,取得控件指针
    if( m_pTreeCtrlcompile && m_pTreeCtrlcompile->GetSafeHwnd( ))
	{
		//禁止在一个窗口中的绘图功能
		m_pTreeCtrlcompile->LockWindowUpdate();
        //项目数目
		int npro=projectinfo.GetSize();
		//当前项目指针
		struct ProjectList * curpro=NULL;
        curpro=new ProjectList;
        curpro=(ProjectList *)projectinfo.GetAt(0);
		//项目名称
		CString proname="";
		proname=curpro->str_projectname;

        //初始化树形项变量
		HTREEITEM hticurpro=NULL;
		//树形节点数目为 0
		if(m_pTreeCtrlcompile->GetCount()==0)
		{
			//插入节点
			hticurpro = m_pTreeCtrlcompile->InsertItem (proname);
		}
        else
		{
			  //获得根节点
		   hticurpro=m_pTreeCtrlcompile->GetRootItem();

		}
		//项目中的文件数目
		int nfile=curpro->proinfstru.GetSize();
		if(nfile>0)
		{
		int fileno=nfile-1;
		//文件信息结构的指针变量
		FileList * m_pcurfile;
		m_pcurfile=new FileList;
           
	    CString str_curfilename=_T("");

		 //获得项目中最后一个文件信息
		m_pcurfile=(FileList *)curpro->proinfstru.GetAt(nfile-1);
		//获得文件名
		str_curfilename=m_pcurfile->str_filename;
		//初始化树形项变量
		HTREEITEM hticurfile; // child item
		//插入节点
	   	hticurfile= m_pTreeCtrlcompile->InsertItem (str_curfilename, 1, 1, hticurpro, TVI_LAST);
	   	//将节点存入项目信息
		m_pcurfile->t_fileitem=hticurfile;

		//主窗口
//		CMDIFrameWnd *nowframe = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
		//活动子窗口
//		CMDIChildWnd *nowchild = nowframe->MDIGetActive();

		//在新加节点处展开
		m_pTreeCtrlcompile->Expand (hticurfile , TVE_EXPAND);


		//激活在一个窗口中的绘图功能
        m_pTreeCtrlcompile->UnlockWindowUpdate();
		}
	}  
	
	
}


void CTabClassView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default


	//定义树形项变量
	HTREEITEM hti,hParent,fti;
    //获得根节点
    hParent=m_pTreeCtrlcompile->GetRootItem();
	//获得根节点的第一个子节点
	fti=m_pTreeCtrlcompile->GetChildItem(hParent);
    //获得双击节点
	hti=m_pTreeCtrlcompile->GetSelectedItem();
    //获得当前项目指针
	struct ProjectList * curtpro=NULL;         
	curtpro=new ProjectList;
	curtpro=(ProjectList *)projectinfo.GetAt(0);
	//如果项目为空
	if(curtpro==NULL||projectinfo.GetSize()==0||curtpro->proinfstru.GetSize()==0)
		return;
	//子窗口指针变量
	CMDIChildWnd * m_ptestwnd=NULL;
	m_ptestwnd=new CMDIChildWnd ;

	//文件信息指针变量
	FileList * m_ptfile=NULL;
	m_ptfile=new FileList;

	//项目中的文件数目
    int n_filenum=curtpro->proinfstru.GetSize();
	//如果双击的是文件节点
	if(m_pTreeCtrlcompile->GetParentItem(hti)==hParent)
	{
		//搜索每一个文件信息
		for(int i=0;i<=n_filenum-1;i++)
		{
			//如果这个节点是双击节点
	       if(fti==hti)
		   {
			   // m_ptestwnd=(CMDIChildWnd *)a_filelist.GetAt(i);
			   //取双击节点对应的窗口指针
			   m_ptestwnd=fileitemarray[i].m_pchildf;
			   break;			  
		   }
		   //取节点
		   fti=m_pTreeCtrlcompile->GetNextSiblingItem(fti);
		}
		//子窗口不存在,返回
		if(NULL==m_ptestwnd)
			return;
		//子窗口激活
		m_ptestwnd->MDIActivate(); 
        //子窗口设置为最前
		m_ptestwnd->BringWindowToTop();
		//子窗口设置为焦点
		m_ptestwnd->SetFocus();
	}
	else
	{
		//如果双击节点是断点
		if(hti!=hParent)
		{
			//定位断点
			
			GotoBreak();
		}
	}
	//默认的双击处理
	CTreeView::OnLButtonDblClk(nFlags, point);
	return;
}


void CTabClassView::GotoBreak()
{
	//定义树形项变量
	HTREEITEM hti,hParent,fti,troot;
	CString gotobreakname;//,str1,str2;	
	//根节点
	troot=m_pTreeCtrlcompile->GetRootItem();
	//根节点的第一个子节点
	fti=m_pTreeCtrlcompile->GetChildItem(troot);
    //当前选择节点
	hti=m_pTreeCtrlcompile->GetSelectedItem();
	//当前选择节点的父节点
	hParent = m_pTreeCtrlcompile->GetParentItem(hti);
	//
	gotobreakname=m_pTreeCtrlcompile->GetItemText(hti);
	//当前项目指针
	struct ProjectList * curgotopro=NULL;         
	curgotopro=new ProjectList;
	curgotopro=(ProjectList *)projectinfo.GetAt(0);	

	//项目不存在
	if(curgotopro==NULL||projectinfo.GetSize()==0||curgotopro->proinfstru.GetSize()==0)
		return;
	//断点所在文件的索引
	int n_gotofile=0;
	//项目中的文件数目
	int n_filenum=curgotopro->proinfstru.GetSize();
	//子窗口指针
	CMDIChildWnd *m_pgotochildf=NULL;
    //访问每个文件信息
	for(int j=0;j<=n_filenum-1;j++)
	{
		//如果fti是当前选择节点的父节点
	    if(hParent==fti)
		{		
			// m_ptestwnd=(CMDIChildWnd *)a_filelist.GetAt(i);
			//断点所在子窗口指针 
			m_pgotochildf=fileitemarray[j].m_pchildf;
		    //所在文件的索引
			n_gotofile=j;
		    break;
		 }
		//取下一个子节点  
		fti=m_pTreeCtrlcompile->GetNextSiblingItem(fti);	
	}
	if(j>=n_filenum)
		return;

	//文件信息结构指针
	FileList * m_pgotofile=NULL;
	m_pgotofile=new FileList;
    //获得断点所在文件对应的文件信息指针
	m_pgotofile=(FileList * )curgotopro->proinfstru.GetAt(n_gotofile);
	//获得断点所在文件对应的子窗口指针
	m_pgotochildf=fileitemarray[n_gotofile].m_pchildf;
	//断点信息结构的指针变量
	struct CompStruct * m_ptestbreak;
	m_ptestbreak=new	CompStruct;
    CString currentname; 
	//断点数目
	int breaksize=m_pgotofile->compileinfstru.GetSize();
	//访问每个断点		
    for(int i=0;i<breaksize;i++)
	{
		//获得第i个断点
		m_ptestbreak=(CompStruct *)m_pgotofile->compileinfstru.GetAt(i);
		//断点名称
        currentname=m_ptestbreak->str_breakname;
        //如果第i个断点是选择的断点
        if((currentname.Compare(gotobreakname))==0)
		{
			//断点所在行
		    gotoline=m_ptestbreak->n_breakline;
		 }
   
	}
	//子窗口激活
	m_pgotochildf->MDIActivate(); 
    //子窗口设置为最前
	m_pgotochildf->BringWindowToTop();
     //子窗口设置为焦点
	m_pgotochildf->SetFocus();
  	CC02IDEView* m_pView=(CC02IDEView*)m_pgotochildf->GetActiveView();
	m_pView->GotoLine(gotoline);
    
}

void CTabClassView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	//默认的左键处理函数
	CTreeView::OnLButtonDown(nFlags, point);
	//定义树形项变量
	HTREEITEM hti,hParent;//,fti;
	//根节点
    hParent=m_pTreeCtrlcompile->GetRootItem();
	//当前选择节点
	hti=m_pTreeCtrlcompile->GetSelectedItem();
/*	//根节点的第一个子节点
	fti=m_pTreeCtrlcompile->GetChildItem(hParent);

	//子窗口指针
	CMDIChildWnd * m_ptestwnd=NULL;
	m_ptestwnd=new CMDIChildWnd ;
	//文件信息结构指针
	FileList * m_ptopfile=NULL;
	m_ptopfile=new FileList;

	//当前项目指针 
	struct ProjectList * m_ptestpro=NULL;
	m_ptestpro=new ProjectList;
	m_ptestpro=(ProjectList *)projectinfo.GetAt(0);
	//项目不存在
	if(m_ptestpro==NULL)
		return;
	//项目中的文件数目
    int n_filenum=m_ptestpro->proinfstru.GetSize();
*/
    //如果当前选择节点是根节点
	if(hti==hParent)
	{			
		//展开所有节点
		ExpandAll();				
	}
    //默认的处理
//	CTreeView::OnLButtonDown(nFlags, point);
	
}

void CTabClassView::ExpandAll()
{

	//树控件不存在
	if(!m_pTreeCtrlcompile)
		//初始化树控件
		OnInitialUpdate();
	//树形控件存在,取得控件指针
    if( m_pTreeCtrlcompile && m_pTreeCtrlcompile->GetSafeHwnd( ))
	{
		//删除树控件的所有项
		m_pTreeCtrlcompile->DeleteAllItems();
	    //禁止对树控件的重画
		m_pTreeCtrlcompile->LockWindowUpdate();
		//
//		int npro=projectinfo.GetSize();
		//当前项目指针
		struct ProjectList * curpro=NULL;
        curpro=new ProjectList;  
		curpro=(ProjectList *)projectinfo.GetAt(0);
		CString proname=_T("");
		proname=curpro->str_projectname;
		//将项目名作为根节点
		HTREEITEM hticurpro = m_pTreeCtrlcompile->InsertItem (proname);//GetRootItem();//
		//项目中的文件数目
		int nfile=curpro->proinfstru.GetSize();
		//文件信息结构指针
		struct FileList * m_pcurfile=NULL;		
		m_pcurfile=new FileList;
           
		CString str_curfilename=_T("");
		//对每一个文件展开
		for (int j=0;j<=nfile-1;j++)
		{		      
			//取项目中的第j个文件信息
			m_pcurfile=(FileList *)curpro->proinfstru.GetAt(j);
			//文件名
			str_curfilename=m_pcurfile->str_filename;
			//添加文件节点
           	HTREEITEM hticurfile; // child item	
			hticurfile= m_pTreeCtrlcompile->InsertItem( str_curfilename,1,1,hticurpro,TVI_LAST);
	        //在新加节点处展开
			m_pTreeCtrlcompile->Expand (hticurpro  , TVE_EXPAND);
			//当前文件中的断点个数
			int n_break=m_pcurfile->compileinfstru.GetSize();
//			CString str_filenm;
//			str_filenm=m_pcurfile->str_filename;
			//断点信息结构的指针变量
			struct CompStruct * m_pcurbreak;
			m_pcurbreak=new	CompStruct;
				
			CString str_curbreak=_T("");
			for(int k=0;k<=n_break-1;k++)
			{
	        	//获得第i个断点
				m_pcurbreak=(CompStruct *)m_pcurfile->compileinfstru.GetAt(k);
	        	//断点名称
				str_curbreak=m_pcurbreak->str_breakname;
                //插入节点
				HTREEITEM hticurfunc; // child item
	        	hticurfunc= m_pTreeCtrlcompile->InsertItem (str_curbreak, 2, 3, hticurfile, TVI_LAST);
				}
			}
		//激活在一个窗口中的绘图功能
        m_pTreeCtrlcompile->UnlockWindowUpdate();
		
	}  

}

⌨️ 快捷键说明

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