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

📄 fileview.cpp

📁 一个集成的文本阅读工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// FileView.cpp : implementation file
//

#include "stdafx.h"
#include "TipReader.h"
#include "FileView.h"
#include "ChildFrm.h"
#include "FileDlg.h"
#include "NewTextDlg.h"
#include "NewFolderDlg.h"

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

CString CaCupath(void);
/////////////////////////////////////////////////////////////////////////////
// CFileView

IMPLEMENT_DYNCREATE(CFileView, CView)

CFileView::CFileView()
{
	this->FileNumbers=0;
	this->initview();
	this->m_filetree.m_state=FALSE;
}

CFileView::~CFileView()
{
	CFile file;
	CString tempstr,Pathstr;
	//Pathstr=((CTipReaderApp *)(::AfxGetApp()))->m_config.m_path;
	Pathstr=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;
	tempstr=Pathstr;
	tempstr+="TipConfig.ini";

	if(file.Open(tempstr,CFile::modeWrite,NULL))
	{
		CArchive ar(&file,CArchive::store,4096,NULL);
		int counts;
		counts=this->m_finishtxt.GetSize();
		ar<<counts;
		while(--counts>-1)
		{
			ar<<this->m_finishtxt.GetAt(counts);
		}

	}
}


BEGIN_MESSAGE_MAP(CFileView, CView)
	//{{AFX_MSG_MAP(CFileView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_COMMAND(ID_MARK_ON, OnMarkOn)
	ON_COMMAND(ID_MARK_OFF, OnMarkOff)
	ON_UPDATE_COMMAND_UI(ID_MARK_OFF, OnUpdateMarkOff)
	ON_UPDATE_COMMAND_UI(ID_MARK_ON, OnUpdateMarkOn)
	ON_COMMAND(ID_DELETEFILE, OnDeletefile)
	ON_COMMAND(ID_OPENNOTEPAD, OnNoteopen)
	ON_COMMAND(ID_REFRESHME, OnRefreshme)
	ON_COMMAND(ID_NOTEPAD, OnNotepad)
	ON_COMMAND(ID_NEWFILE, OnNewfile)
	ON_COMMAND(ID_CREATEBEWFOLDER, OnCreatebewfolder)
	ON_COMMAND(ID_REMOVEPATH, OnRemovepath)
	ON_UPDATE_COMMAND_UI(ID_REMOVEPATH, OnUpdateRemovepath)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(ID_BTN, OnClick)
	ON_BN_CLICKED(ID_FILEMANAGE, OnClick2open)
	ON_CBN_SELCHANGE(ID_PATH, OnClick2sel)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileView drawing

void CFileView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
	CString temp="目录文件数:";
	CString temp2;
	temp2.Format("%d",this->FileNumbers);
	temp+=temp2;

	CRect rect;
	CBrush brush;
	brush.CreateSolidBrush(0x00FFFFFF);
	this->GetClientRect(&rect);
	pDC->FillRect(CRect(0,0,rect.Width(),40),&brush);
	pDC->SetBkMode(TRANSPARENT);
	pDC->TextOut(0,25,temp);
}

/////////////////////////////////////////////////////////////////////////////
// CFileView diagnostics

#ifdef _DEBUG
void CFileView::AssertValid() const
{
	CView::AssertValid();
}

void CFileView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFileView message handlers


int CFileView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{

	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here

////////////////////////////初始化控件树////////////////////////////////
	this->m_filetree.Create(TVS_HASBUTTONS|TVS_SHOWSELALWAYS|TVS_SINGLEEXPAND|TVS_HASLINES|WS_VISIBLE,CRect(0,0,100,300),this,ID_FILETREE);
	this->SetTree();
////////////////////////////初始化按扭////////////////////////////////
	this->m_btn.Create("更换路径",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,CRect(0,20,80,40),this,ID_BTN);
	this->m_btn_opennotepad.Create("打开文件...",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,CRect(0,20,80,40),this,ID_FILEMANAGE);
	this->m_combobox.Create(WS_CHILD | WS_VISIBLE|CBS_DROPDOWNLIST|CBS_NOINTEGRALHEIGHT ,CRect(0,0,80,500),this,ID_PATH);
	this->FillComboBox();
	return 0;
}

void CFileView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(cy>=50)
	{
		this->m_filetree.SetWindowPos(&wndBottom,0,40,cx,cy-70,SWP_NOACTIVATE);
		this->m_combobox.SetWindowPos(&wndTop,0,0,cx,19,SWP_NOACTIVATE);
		this->m_btn.SetWindowPos(&wndTop,cx-80,cy-30,80,30,SWP_NOACTIVATE);
		if(this->m_btn_opennotepad.SetWindowPos(&wndTop,0,cy-30,80,30,SWP_NOACTIVATE))
		{
		}


	}
	
}

void CFileView::OnClick(void)
{
	CString temp1,temp2;
	CFileDialog m_filedlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|All Files (*.*)|*.*||",NULL);
	if(m_filedlg.DoModal()==IDOK)
	{
		temp1=m_filedlg.GetPathName();
		temp2=m_filedlg.GetFileName();
		((CTipReaderApp *)::AfxGetApp())->m_config.m_filename=temp2;
///////////////////读取文件///////////////////////////////
		CFile file(temp1,CFile::modeRead);
		CArchive ar(&file,CArchive::load,4096,NULL);
		CEditView *pEditView;

		pEditView=(CEditView *) ((CSplitterWnd *)(this->GetParent()))->GetPane(0,1);
		pEditView->SerializeRaw(ar);
		this->GetDocument()->SetTitle(temp2);
///////////////////设置路径///////////////////////////////
		temp1=temp1.Left(temp1.GetLength()-temp2.GetLength());
		((CTipReaderApp *)::AfxGetApp())->m_config.m_path=temp1;

		if(((CTipReaderApp *)::AfxGetApp())->m_config.InsertPath(temp1)==TRUE)
			this->m_combobox.AddString(temp1);
		this->m_combobox.SetCurSel(this->m_combobox.FindString(-1,temp1));
		this->SetTree();
	}
}

void CFileView::SetTree(void)
{
/////////对目录内的所有文本文件进行读取和定出//////////
	HTREEITEM temp;
	HANDLE filehandle;
	WIN32_FIND_DATA finddata;
	CString Temp_FileName;
	CString Pathstr;
///////////以下为其目录//////////	
Pathstr=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;

//////////对树进行预处理,删除所有树支////////
	if(this->m_filetree.GetCount()>0)
		this->m_filetree.DeleteAllItems();
/////////对树的绑定位图定义/////////////////
	if(!this->m_filetree.m_state)
	{
		this->m_filetree.SetImageList(&(this->m_filetree.m_ImageList),TVSIL_NORMAL);
		this->m_filetree.m_state=TRUE;
	}
////////////////////////////////////////////////////
/////////对已阅文件进行配置定行读取/////////////////
/////文件存在程序目录内,以目录名命名//////////////
////////////////////////////////////////////////////
	CString currentpath,tempstr2;

	this->m_finishtxt.RemoveAll();

/*	currentpath=::AfxGetApp()->m_pszHelpFilePath;
	tempstr2=::AfxGetApp()->m_pszExeName;
	tempstr2+=".HLP";
	currentpath=currentpath.Left(currentpath.GetLength()-tempstr2.GetLength());
	
	tempstr2=currentpath;
	currentpath=Pathstr;
	currentpath.Replace(":","#%");
	currentpath.Replace("\","#@");*/

	tempstr2=Pathstr;
	tempstr2+="TipConfig.ini";

	filehandle=::FindFirstFile(tempstr2,&finddata);
	if(filehandle!=INVALID_HANDLE_VALUE)
	{
		CFile file;
		if(file.Open(tempstr2,CFile::modeRead,NULL))
		{
			CArchive ar(&file,CArchive::load,4096,NULL);
			CString tempstring;
			int counts,i=1;
			ar>>counts;
			while((i++)<=counts)
			{
				ar>>tempstring;
				this->m_finishtxt.Add(tempstring);
			}
		}
	}
	else
	{
		CFile file;
		if(file.Open(tempstr2,CFile::modeCreate,NULL))
			::AfxMessageBox("程序对文件夹建立了配置文件!");
	}

	Pathstr+="*.txt";
	filehandle=::FindFirstFile(Pathstr,&finddata);
	if(filehandle==INVALID_HANDLE_VALUE)
	{
		//::AfxMessageBox("Can't Find any Txt File in the Dictory!");
		this->FileNumbers=0;
	}
	else
	{
	
		this->FileNumbers=1;
		Temp_FileName=finddata.cFileName;
		Temp_FileName.TrimRight(".txt");
		temp=this->m_filetree.InsertItem(Temp_FileName,TVI_ROOT,TVI_LAST);
		if(this->checkstate(Temp_FileName))
			this->m_filetree.SetItemImage(temp,0,0);
		else
			this->m_filetree.SetItemImage(temp,1,1);

		/////////查找所有目录内的文本文件//////////
		while((::FindNextFile(filehandle,&finddata))!=0)
		{
			Temp_FileName=finddata.cFileName;
			Temp_FileName.TrimRight(".txt");
			temp=this->m_filetree.InsertItem(Temp_FileName,TVI_ROOT,TVI_LAST);

			if(this->checkstate(Temp_FileName))
				this->m_filetree.SetItemImage(temp,0,0);
			else
				this->m_filetree.SetItemImage(temp,1,1);

			this->FileNumbers++;	
		}
	}
	this->m_filetree.SortChildren(NULL);
	this->RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);


}

void CFileView::initview()
{
///////////load the bmps///////
	CBitmap temp_map,temp_map1;
	if(this->m_filetree.m_ImageList.Create(12,12,ILC_COLOR,2,0))
	{
		this->m_filetree.m_ImageList.GetImageCount();			
	}

	if(temp_map.LoadBitmap(IDR_BMP_ON))
	{

⌨️ 快捷键说明

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