📄 findfiledlg.cpp
字号:
// FindFileDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FindFile.h"
#include "FindFileDlg.h"
#include "splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFindFileDlg dialog
CFindFileDlg::CFindFileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFindFileDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFindFileDlg)
m_path = _T("");
m_choosecpp = FALSE;
m_chooseexe = FALSE;
m_chooseself = FALSE;
m_selftype = _T("");
m_choosetxt = FALSE;
m_choosefolder = FALSE;
m_chooseall = FALSE;
m_radio = 1;
m_checkson = FALSE;
m_static = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//m_file.SetHorizontalExtent( 50 );
}
void CFindFileDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFindFileDlg)
DDX_Control(pDX, IDC_LISTHIDE, m_hide);
DDX_Control(pDX, IDC_LISTFOLDER, m_folder);
DDX_Control(pDX, IDC_LISTFILE, m_file);
DDX_Control(pDX, IDC_LISTALL, m_showall);
DDX_Control(pDX, IDC_STATIC3, m_filenum);
DDX_Control(pDX, IDC_STATIC2, m_foldernum);
DDX_Control(pDX, IDC_STATIC1, m_allnum);
DDX_Text(pDX, IDC_EDITPATH, m_path);
DDX_Check(pDX, IDC_CHECK_CPP, m_choosecpp);
DDX_Check(pDX, IDC_CHECK_EXE, m_chooseexe);
DDX_Check(pDX, IDC_CHECK_YOUSELF, m_chooseself);
DDX_Text(pDX, IDC_EDIT_FILETYPE, m_selftype);
DDX_Check(pDX, IDC_CHECK_TXT, m_choosetxt);
DDX_Check(pDX, IDC_CHECK_FLOTER, m_choosefolder);
DDX_Check(pDX, IDC_CHECKALL, m_chooseall);
DDX_Radio(pDX, IDC_RADIO4, m_radio);
DDX_Check(pDX, IDC_CHECK_SON, m_checkson);
DDX_Text(pDX, IDC_SHOWSTATIC, m_static);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFindFileDlg, CDialog)
//{{AFX_MSG_MAP(CFindFileDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_BUTTONSELECT, OnButtonselect)
ON_NOTIFY(NM_CLICK, IDC_LISTALL, OnClickListall)
ON_NOTIFY(NM_CLICK, IDC_LISTFOLDER, OnClickListfolder)
ON_NOTIFY(NM_CLICK, IDC_LISTFILE, OnClickListfile)
ON_WM_CREATE()
ON_WM_TIMER()
ON_BN_CLICKED(IDOK, OnClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFindFileDlg message handlers
BOOL CFindFileDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_showall.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_showall.SetTextBkColor(0x00F7C6A2);
m_showall.InsertColumn(0,"文件及文件夹列表",LVCFMT_LEFT,373,0);
m_folder.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_folder.InsertColumn(0,"文件夹列表",LVCFMT_LEFT,179,0);
m_file.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_file.InsertColumn(0,"文件列表",LVCFMT_LEFT,179,0);
m_hide.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_hide.InsertColumn(0,"列 表",LVCFMT_LEFT,20,0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFindFileDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFindFileDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
this->KillTimer(1);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFindFileDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFindFileDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CFindFileDlg::OnFind()
{
hidenum=0;
hidepoint=0;
filenum=0;
foldernum=0;
num=0;
m_showall.DeleteAllItems( ); //清空列表框
m_folder.DeleteAllItems( );
m_file.DeleteAllItems( );
UpdateData(true);
CString input_path=m_path;
if(m_path=="") //输入纠错
MessageBox(" 请输入或选择查找路径! ","输入错误",MB_ICONERROR);
else
{
while(true){
m_path=MakePath(m_path); //转换m_path至系统可读取形式
isaccess=false;
CString m_path_temp;
if(!m_chooseall&&!m_choosetxt&&!m_chooseexe&&!m_choosecpp&&!m_chooseself&&!m_choosefolder)
ShowFind(m_path);
else
{ if(m_chooseall)
{
int path_index=m_path.ReverseFind( '\\' );
m_path_temp=m_path.Left(path_index+1)+"*";
//MessageBox(m_path_temp);
ShowFind(m_path_temp);
}
else
{
if(m_choosetxt)
{ //MessageBox("111"+m_path);
m_path_temp=m_path;
if(m_path!=m_path.SpanExcluding("."))
{
int path_index=m_path.ReverseFind( '.' );
m_path_temp=m_path.Left(path_index+1)+"txt";
}
else
m_path_temp=m_path_temp+".txt";
//MessageBox("222"+m_path_temp);
ShowFind(m_path_temp,false);
}
if(m_chooseexe)
{
m_path_temp=m_path;
if(m_path!=m_path.SpanExcluding("."))
{
int path_index=m_path.ReverseFind( '.' );
m_path_temp=m_path.Left(path_index+1)+"exe";
}
else
m_path_temp=m_path_temp+".exe";
ShowFind(m_path_temp,false);
}
if(m_choosecpp)
{
m_path_temp=m_path;
if(m_path!=m_path.SpanExcluding("."))
{
int path_index=m_path.ReverseFind( '.' );
m_path_temp=m_path.Left(path_index+1)+"cpp";
}
else
m_path_temp=m_path_temp+".cpp";
ShowFind(m_path_temp,false);
}
if(m_chooseself)
{
//m_path_temp=m_path;
//UpdateData(true);
save_selftype=m_selftype;
CString selftype_temp;
int selftype_index;
if( (selftype_index=m_selftype.Find( ',' )) ==-1) //一个扩展名时
selftype_index=m_selftype.GetLength();
else
selftype_index=m_selftype.Find( ',' );
do
{ m_path_temp=m_path;
selftype_temp=m_selftype.Left(selftype_index);
//MessageBox("selftype"+selftype_temp);
int aaa=m_selftype.GetLength()-selftype_index-1;
m_selftype=m_selftype.Right( aaa ); // 依次减去一个扩展名
if(selftype_temp!="txt"&&selftype_temp!="exe"&&selftype_temp!="cpp")
{
if(m_path!=m_path.SpanExcluding("."))
{
int path_index=m_path.ReverseFind( '.' );
m_path_temp=m_path.Left(path_index+1)+selftype_temp;
}
else
m_path_temp=m_path_temp+"."+selftype_temp;
//MessageBox("lujin"+m_path_temp);
ShowFind(m_path_temp,false); //m_path 没有体现!!!!
}
}while( m_selftype!="" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -