📄 filedlg.cpp
字号:
// FileDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TipReader.h"
#include "FileDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileDlg dialog
CFileDlg::CFileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileDlg)
m_filetype = _T("");
//}}AFX_DATA_INIT
}
void CFileDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileDlg)
DDX_Control(pDX, IDAPPLY, m_apply);
DDX_Control(pDX, IDC_EDIT1, m_edt);
DDX_Control(pDX, IDC_NUMBER, m_numberctrl);
DDX_Control(pDX, IDC_TREE2, m_Tree);
DDX_Control(pDX, IDC_TAB1, m_Tab);
DDX_Text(pDX, IDC_EDIT1, m_filetype);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileDlg, CDialog)
//{{AFX_MSG_MAP(CFileDlg)
ON_BN_CLICKED(IDAPPLY, OnApply)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE2, OnSelchangedTree2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileDlg message handlers
BOOL CFileDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rect;
this->GetClientRect(&rect);
this->m_Tab.SetWindowPos(&wndTop,0,0,rect.Width(),rect.Height()-40,SWP_NOACTIVATE);
this->m_Tab.InsertItem(0,"目录文件管理");
this->GetDlgItem(IDC_EDIT1)->SetWindowText(".*");
this->SetTree(".*");
this->m_Tab.UpdateWindow();
this->m_selfilepath="";
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFileDlg::SetTree(CString file_ext)
{
/////////对目录内的所有文本文件进行读取和定出//////////
HTREEITEM temp;
HANDLE filehandle;
WIN32_FIND_DATA finddata;
CString Temp_FileName;
CString Pathstr;
///////////以下为其目录//////////
Pathstr=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;
//////////对树进行预处理,删除所有树支////////
if(this->m_Tree.GetCount()>0)
this->m_Tree.DeleteAllItems();
Pathstr+="*";
Pathstr+=file_ext;
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;
if(file_ext!=".*")
{
Temp_FileName.TrimRight(file_ext);
}
temp=this->m_Tree.InsertItem(Temp_FileName,TVI_ROOT,TVI_LAST);
/////////查找所有目录内的文本文件//////////
while((::FindNextFile(filehandle,&finddata))!=0)
{
Temp_FileName=finddata.cFileName;
if(file_ext!=".*")
{
Temp_FileName.TrimRight(file_ext);
}
temp=this->m_Tree.InsertItem(Temp_FileName,TVI_ROOT,TVI_LAST);
this->FileNumbers++;
}
}
this->m_Tree.SortChildren(NULL);
CString tempstr;
tempstr.Format("%d",FileNumbers);
this->m_numberctrl.SetWindowText(tempstr);
this->RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
}
void CFileDlg::OnApply()
{
// TODO: Add your control notification handler code here
CString temp;
this->m_edt.GetWindowText(temp);
this->SetTree(temp);
}
void CFileDlg::OnSelchangedTree2(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
CString Pathstr,temp;
Pathstr=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;
Pathstr+=this->m_Tree.GetItemText(this->m_Tree.GetSelectedItem());
this->m_edt.GetWindowText(temp);
if(temp!=".*")
Pathstr+=temp;
this->m_selfilepath=Pathstr;
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -