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

📄 pathfilendlg.cpp

📁 Wince 下的文本阅读器的源代码,支持TXT文本文件格式,适合PMP下的电子书阅读器.
💻 CPP
字号:
// PathFileNdlg.cpp : implementation file
//

#include "stdafx.h"
#include "ReadTxt.h"
#include "PathFileNdlg.h"

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

#define FILEICON 0
#define DIRICON 1

/////////////////////////////////////////////////////////////////////////////
// PathFileNdlg dialog


PathFileNdlg::PathFileNdlg(CWnd* pParent /*=NULL*/)
	: CDialog(PathFileNdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(PathFileNdlg)
	m_PathFileName = _T("\\*.*");
	//}}AFX_DATA_INIT
}


void PathFileNdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(PathFileNdlg)
	DDX_Control(pDX, IDC_LIST1, m_FileList);
	DDX_Text(pDX, IDC_PATH_EDIT, m_PathFileName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(PathFileNdlg, CDialog)
	//{{AFX_MSG_MAP(PathFileNdlg)
	ON_BN_CLICKED(IDC_PATH_GOUP, OnPathGoup)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	ON_BN_CLICKED(IDC_PATH_CANCEL, OnPathCancel)

	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// PathFileNdlg message handlers

void PathFileNdlg::OnPathOpen() 
{
	// TODO: Add your control notification handler code here
	
}

void PathFileNdlg::OnPathGoup() 
{
	m_szCurDir = m_szCurDir.Left(m_szCurDir.ReverseFind('\\'));
	GetDlgItemText(IDC_PATH_EDIT,m_PathFileName.GetBuffer(0),256);
	m_szExtName=m_PathFileName.Mid(m_PathFileName.ReverseFind('\\')+1,m_PathFileName.GetLength()-(m_PathFileName.ReverseFind('\\')+1));
	m_PathFileName=m_szCurDir+L"\\"+m_szExtName;
		
	FindFile(m_szCurDir+L"\\" ,m_szExtName);	
}

void PathFileNdlg::FindFile(CString pathname,CString ExtName)
{	
	int i = 0;
	CString s;
	m_FileList.DeleteAllItems();
	m_szCurDir = pathname.Left(pathname.ReverseFind('\\'));
        SetDlgItemText(IDC_PATH_EDIT,m_PathFileName);
	// find dir
	hFind = FindFirstFile(m_szCurDir + _T("\\*.*"), &FindFileData);    //注意目录的形式后面要有*.*
	if(hFind == INVALID_HANDLE_VALUE)
 	{
		FindClose(hFind);
		RETAILMSG(TRUE, (L"查找文件函数中,没找到文件!\r\n"));
		return ;
	}
 	else
 	{		
	
		if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ||FindFileData.dwFileAttributes ==272)
		{		
			s = FindFileData.cFileName;
			m_FileList.InsertItem(i,s,DIRICON);
			i++;
		}
		else
		{

		}
		while(FindNextFile(hFind,&FindFileData))
		{
			if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY || FindFileData.dwFileAttributes==272)
			{		
				s = FindFileData.cFileName;
				m_FileList.InsertItem(i,s,DIRICON);
				i++;
			}
		}
	}
 	FindClose(hFind);




	hFind = FindFirstFile(m_szCurDir + _T("\\*.*"), &FindFileData);    //注意目录的形式后面要有*.*
	if(hFind == INVALID_HANDLE_VALUE)
 	{
		FindClose(hFind);
		return;
	}
 	else
 	{
		if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
		{		
			if(ExtName.Compare(L"*.*")==0)
			{
				s = FindFileData.cFileName;
				m_FileList.InsertItem(i,s,FILEICON);
				i++;
			}
			else 
			{
		
				CString FileMname=ExtName.Mid(0,ExtName.ReverseFind('.'));
				CString ExtMname=ExtName.Mid(ExtName.ReverseFind('.')+1,ExtName.GetLength()-(ExtName.ReverseFind('.')+1));
				if(FileMname.Compare(L"*")==0)  //例:*.exe
				{
					s = FindFileData.cFileName;
					CString temp = s.Right(3);
					
					temp.MakeUpper();
					ExtName.MakeUpper();
					CString temp1=ExtName.Right(3);
					if (temp.Compare(temp1.GetBuffer(temp1.GetLength()))==0)
					{
						m_FileList.InsertItem(i,s,FILEICON);
						i++;
					}
				}
				else if(ExtMname.Compare(L"*")==0)  //例:abc.*
				{
					s = FindFileData.cFileName;
					CString temp =s.Mid(0,s.ReverseFind('.')-1);
					temp.MakeUpper();
					ExtMname.MakeUpper();
					CString temp1=ExtName;
					if (temp.Compare(temp1.GetBuffer(temp1.GetLength()))==0)
					{
						m_FileList.InsertItem(i,s,FILEICON);
						i++;
					}
				}
				else				//例:abc.exe
				{
					s = FindFileData.cFileName;
					CString temp = s;
					temp.MakeUpper();
					ExtName.MakeUpper();
					CString temp1=ExtName;
					if (temp.Compare(temp1.GetBuffer(temp1.GetLength()))==0)
					{
						m_FileList.InsertItem(i,s,FILEICON);
						i++;
					}
				}
			}
		}
		while(FindNextFile(hFind,&FindFileData))
		{
			if(ExtName.Compare(L"*.*")==0)
			{
				s = FindFileData.cFileName;
				m_FileList.InsertItem(i,s,FILEICON);
				i++;
			}
			else 
			{

				CString FileMname=ExtName.Mid(0,ExtName.ReverseFind('.'));
				CString ExtMname=ExtName.Mid(ExtName.ReverseFind('.')+1,ExtName.GetLength()-(ExtName.ReverseFind('.')+1));
				if(FileMname.Compare(L"*")==0)  //例:*.exe
				{
					s = FindFileData.cFileName;
					CString temp = s.Right(3);
					
					temp.MakeUpper();
					ExtName.MakeUpper();
					CString temp1=ExtName.Right(3);
					if (temp.Compare(temp1.GetBuffer(temp1.GetLength()))==0)
					{
						m_FileList.InsertItem(i,s,FILEICON);
						i++;
					}
				}
				else if(ExtMname.Compare(L"*")==0)  //例:abc.*
				{
					s = FindFileData.cFileName;
					CString temp =s.Mid(0,s.ReverseFind('.')-1);
					temp.MakeUpper();
					ExtMname.MakeUpper();
					CString temp1=ExtName;
					if (temp.Compare(temp1.GetBuffer(temp1.GetLength()))==0)
					{
						m_FileList.InsertItem(i,s,FILEICON);
						i++;
					}
				}
				else				//例:abc.exe
				{
					s = FindFileData.cFileName;
					CString temp = s;
					temp.MakeUpper();
					ExtName.MakeUpper();
					CString temp1=ExtName;
					if (temp.Compare(temp1.GetBuffer(temp1.GetLength()))==0)
					{
						m_FileList.InsertItem(i,s,FILEICON);
						i++;
					}
				}
			}
		}
	}
 	FindClose(hFind);
 
}

BOOL PathFileNdlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_IconImage.Create(::GetSystemMetrics(SM_CXICON) / 2,
					   ::GetSystemMetrics(SM_CYICON) / 2, TRUE, 10, 10);

	m_IconImage.Add(AfxGetApp()->LoadIcon(IDI_FILE));
	m_IconImage.Add(AfxGetApp()->LoadIcon(IDI_DIR));
	m_FileList.SetImageList(&m_IconImage, LVSIL_SMALL);
	
	GetDlgItemText(IDC_PATH_EDIT,m_PathFileName.GetBuffer(0),256);
	m_szCurDir = m_PathFileName.Left(m_PathFileName.ReverseFind('\\'));
	m_szExtName=m_PathFileName.Mid(m_PathFileName.ReverseFind('\\')+1,m_PathFileName.GetLength()-(m_PathFileName.ReverseFind('\\')+1));
		
	FindFile(m_szCurDir+L"\\" ,m_szExtName);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void PathFileNdlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int index = m_FileList.GetNextItem(-1, LVNI_SELECTED);

	if (index > -1)
	{
		m_szFileName = m_FileList.GetItemText(index, 0);
		m_szPathName = m_szCurDir + "\\" + m_szFileName;
		hFind = FindFirstFile(m_szPathName,&FindFileData);
		if (hFind != INVALID_HANDLE_VALUE)
		{
			FindClose(hFind);
			if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY || FindFileData.dwFileAttributes==272)
			{
				GetDlgItemText(IDC_PATH_EDIT,m_PathFileName.GetBuffer(0),256);
			        char len,len1;
				len=m_PathFileName.ReverseFind('\\')+1;
				len1=wcslen(m_PathFileName);
				len1=len1-len;
				m_szExtName=m_PathFileName.Mid(len,len1);
				
				
				m_szCurDir=m_szPathName;
				m_PathFileName=m_szCurDir+L"\\"+m_szExtName;

				RETAILMSG(TRUE, (L"双击进入查找文件!\r\n"));
				FindFile(m_szCurDir+L"\\" ,m_szExtName);
				
			}
		}
		else
		{
			FindClose(hFind);
			RETAILMSG(TRUE, (L"文件没有找到\r\n"));
		
		}

	}
	*pResult = 0;
}

void PathFileNdlg::OnPathCancel() 
{
 
	CDialog::OnCancel();
}



void PathFileNdlg::OnOK() 
{
	int index = m_FileList.GetNextItem(-1, LVNI_SELECTED);
	if (index > -1)
	{
		CString s;
		s = m_FileList.GetItemText(index, 0);
		m_szPathName = m_szCurDir +_T("\\")+ s;
	}
	else
	{
		m_szPathName = _T("");
	}
	WIN32_FIND_DATA findFileData;
	HANDLE			hFind;		
	hFind = FindFirstFile(m_szPathName, &findFileData);    	
	if(hFind == INVALID_HANDLE_VALUE)
	{
		RETAILMSG(TRUE, (L"OK,查找文件,没有找到!\r\n"));
		return;
	}
	if(findFileData.dwFileAttributes== FILE_ATTRIBUTE_DIRECTORY ||  FindFileData.dwFileAttributes==272)
	{
		RETAILMSG(TRUE, (L"OK,查找文件,找到的是目录!\r\n"));
		return;
	}
	CDialog::OnOK();
}
CString PathFileNdlg::GetFilePath()
{
	return m_szPathName;
}

⌨️ 快捷键说明

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