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

📄 mytreectrl.cpp

📁 一个集成的文本阅读工具
💻 CPP
字号:
// MyTreeCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "TipReader.h"
#include "MyTreeCtrl.h"
#include "ChildFrm.h"
#include "TipReaderDoc.h"
#include "TipReaderView.h"
#include "MainFrm.h"


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

/////////////////////////////////////////////////////////////////////////////
// CMyTreeCtrl

CMyTreeCtrl::CMyTreeCtrl()
{	
/*
	char temp[50];
	CString tempstr,tempstr2;
	::GetCurrentDirectory(50,temp);
	tempstr=(CString)temp;
	this->CurrentPath=tempstr;

	tempstr=::AfxGetApp()->m_pszHelpFilePath;
	tempstr2=::AfxGetApp()->m_pszExeName;
	tempstr2+=".HLP";
	tempstr=tempstr.Left(tempstr.GetLength()-tempstr2.GetLength());
	this->CurrentPath=tempstr;
	*/
	m_clrText = RGB( 220, 220, 220 );
	m_clrBkgnd = RGB( 0, 0, 0 );
	m_pbrBkgnd=new CBrush();
	m_pbrBkgnd->CreateSolidBrush( m_clrBkgnd );
}

CMyTreeCtrl::~CMyTreeCtrl()
{
}


BEGIN_MESSAGE_MAP(CMyTreeCtrl, CTreeCtrl)
	//{{AFX_MSG_MAP(CMyTreeCtrl)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_WM_CHAR()
	ON_WM_CREATE()
	ON_WM_CTLCOLOR_REFLECT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyTreeCtrl message handlers

void CMyTreeCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{

	CEditView *pEditView;
	//得到所选的项目//
	CString FileName=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;
	FileName+=this->GetItemText(this->GetSelectedItem());
	FileName+=".txt";
	//打开所选文件//
	((CTipReaderApp *)::AfxGetApp())->m_config.m_filename=this->GetItemText(this->GetSelectedItem());
	((CTipReaderApp *)::AfxGetApp())->m_config.m_filename+=".txt";

	CFile file(FileName,CFile::modeRead);
	CArchive ar(&file,CArchive::load,4096,NULL);
	
	pEditView=(CEditView *)((CSplitterWnd *)this->GetParent()->GetParent())->GetPane(0,1);
	pEditView->SerializeRaw(ar);
	((CTipReaderView*)((CSplitterWnd *)this->GetParent()->GetParent())->GetPane(0,0))->GetDocument()->SetTitle(this->GetItemText(this->GetSelectedItem())+".txt");
	*pResult = 0;
}

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

	this->Select(this->HitTest(point,NULL),TVGN_CARET);
}



void CMyTreeCtrl::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CRect rect;
	GetClientRect(rect);
	ClientToScreen(rect);

	point.Offset(5, 5);
	point.x=point.x+rect.left;
	point.y=point.y+rect.top;


	CMenu menu;
	VERIFY(menu.LoadMenu(IDR_TREECTRLMENU));

	CMenu* pPopup = menu.GetSubMenu(0);
	ASSERT(pPopup != NULL);
	CWnd* pWndPopupOwner = this;

	while (pWndPopupOwner->GetStyle() & WS_CHILD)
		pWndPopupOwner = pWndPopupOwner->GetParent();

	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
		pWndPopupOwner);
}



void CMyTreeCtrl::SetNULL()
{
	((CTipReaderView*)((CSplitterWnd *)this->GetParent()->GetParent())->GetPane(0,0))->GetDocument()->SetTitle("没有打开文本文件!");
}

void CMyTreeCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if(nChar==VK_ESCAPE) //如果按的键为Esc键  
	{
		//获取主框架窗口的指针  
		CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;  
		//调用主窗口类的自定义函数 EndFullScreen ,便可退出全屏显示状态  
		pFrame->EndFullScreen();
	}
	else	
	CTreeCtrl::OnChar(nChar, nRepCnt, nFlags);
}

HBRUSH CMyTreeCtrl::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	// TODO: Change any attributes of the DC here
/*	pDC->SetTextColor( m_clrText );    // text
	pDC->SetBkColor( m_clrBkgnd );    // text bkgnd
	pDC->SetBkMode(OPAQUE);
	return *(m_pbrBkgnd);                // ctl bkgnd*/
	return NULL;
}

int CMyTreeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CTreeCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	return 0;
}

⌨️ 快捷键说明

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