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

📄 findfiledlg.cpp

📁 操作系统课程设计:对话框式的文件查找
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					m_selftype=save_selftype;
				}
				if(m_choosefolder)
				{
					m_path_temp=m_path;
					ShowFind(m_path_temp,true);
				}
				//if(!m_choosetxt&&!m_chooseexe&&!m_choosecpp&&!m_chooseself)
					//ShowFind(m_path);
			}
		}
		//MessageBox("out1"+m_path);
		if(hidenum==0 || hidepoint==hidenum || num>99)		//不满足条件,跳出循环
			break;
		else
		{
			m_path=m_hide.GetItemText(hidepoint,0);			//得到下一级检索值
			m_path=m_path+"\\";
			hidepoint++;
			//MessageBox("out2"+m_path);
		}
		}/*while( hidepoint!=hidenum && num<100 );*/

		m_path=input_path;
		UpdateData(false);
		if( num!=0 )									//检索结果
			MessageBox(" 检 索 结 束 ! ","检索成功",MB_ICONINFORMATION);
		else
			MessageBox("没有找到相应目录或文件!","检索失败",MB_ICONWARNING);
				
	}
}	

CString CFindFileDlg::MakePath(CString strIn)
{
	if(strIn!=strIn.SpanExcluding("*."))
		return strIn;
	else 
		return  strIn+"*";
}


void CFindFileDlg::ShowFind(CString findpath)
{
	CString stredit;
	CString strtemp;
	HANDLE hFile;
	WIN32_FIND_DATA fileinfo;
	DWORD errorcode = 0;
	if( !isaccess&&m_checkson )											//对文件夹进行记录
	{
		isaccess=true;
		//MessageBox("path"+findpath);
		AddHide(findpath);
		//MessageBox("out");
	}
	hFile=FindFirstFile(findpath,&fileinfo);

	while(hFile!=INVALID_HANDLE_VALUE&&errorcode!=ERROR_NO_MORE_FILES)
	{
		strtemp=fileinfo.cFileName;
		//error:stredit=m_path.SpanExcluding("*")+strtemp;

		int path_index=findpath.ReverseFind( '\\' );
		stredit=findpath.Left(path_index+1)+strtemp;
		
		if((stredit.ReverseFind('\\')+1) !=  stredit.Find('.'))
		{			
			m_showall.InsertItem(num,stredit);
			num++;
			if( stredit==stredit.SpanExcluding(".") )
			{
				m_folder.InsertItem(foldernum,stredit);
				foldernum++;
			}	
			else 
			{
				m_file.InsertItem(filenum,stredit);
				filenum++;
			}
		}	
		FindNextFile(hFile,&fileinfo);
		errorcode=GetLastError();
		
	}   //MessageBox("out while");

	//显示计数
	CString strnum;
	strnum.Format("全部文件及文件夹 个数 = %d 个",num);
	m_allnum.SetWindowText(strnum);
	strnum.Format("文件夹 个数 = %d 个",foldernum);
	m_foldernum.SetWindowText(strnum);
	strnum.Format("文件 个数 = %d 个",filenum);
	m_filenum.SetWindowText(strnum);

/*	if(errorcode==ERROR_NO_MORE_FILES)
		MessageBox("检索结束");
	else
		MessageBox("检索Error");
*/
	CloseHandle(hFile);
}

void CFindFileDlg::ShowFind(CString findpath, BOOL isfolder)
{
	CString stredit;
	CString strtemp;
	HANDLE hFile;
	WIN32_FIND_DATA fileinfo;
	DWORD errorcode = 0;
	if( !isaccess&&m_checkson )											//对文件夹进行记录
	{
		isaccess=true;
		//MessageBox("path"+findpath);
		AddHide(findpath);						
	}
	hFile=FindFirstFile(findpath,&fileinfo);
	
	while(hFile!=INVALID_HANDLE_VALUE&&errorcode!=ERROR_NO_MORE_FILES)
	{
		strtemp=fileinfo.cFileName;
		//error:stredit=m_path.SpanExcluding("*")+strtemp;

		int path_index=findpath.ReverseFind( '\\' );
		stredit=findpath.Left(path_index+1)+strtemp;
		//MessageBox("333"+stredit);
		
		if( isfolder&&(stredit==stredit.SpanExcluding(".")) )	//文件夹
		{
			m_showall.InsertItem(num,stredit);
			num++;

			m_folder.InsertItem(foldernum,stredit);
			foldernum++;
		}
		if( !isfolder&&(stredit!=stredit.SpanExcluding("."))&&  
			((stredit.ReverseFind('\\')+1) !=  stredit.Find('.')) )	//文件
		{
			m_showall.InsertItem(num,stredit);
			num++;

			m_file.InsertItem(filenum,stredit);
			filenum++;
		}		
		FindNextFile(hFile,&fileinfo);
		errorcode=GetLastError();
	}

	//显示计数
	CString strnum;
	strnum.Format("全部文件及文件夹 个数 = %d 个",num);
	m_allnum.SetWindowText(strnum);
	strnum.Format("文件夹 个数 = %d 个",foldernum);
	m_foldernum.SetWindowText(strnum);
	strnum.Format("文件 个数 = %d 个",filenum);
	m_filenum.SetWindowText(strnum);

/*	if(errorcode==ERROR_NO_MORE_FILES)
		MessageBox("检索结束");
	else
		MessageBox("检索Error");
*/
	CloseHandle(hFile);
}

void CFindFileDlg::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	m_choosecpp=FALSE;
	m_chooseexe=FALSE;
	m_chooseself=FALSE;
	m_choosetxt=FALSE;
	m_choosefolder=FALSE;
	m_chooseall=FALSE;
	m_radio=0;
	UpdateData(false);
}

int SelectPath(char path[MAX_PATH], char *title = "请选择一个文件夹 ...") 
{
	BROWSEINFO bi;
	ITEMIDLIST *pidl;

	bi.hwndOwner = NULL;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = path;
	bi.lpszTitle = title;
	bi.ulFlags = BIF_EDITBOX;
	bi.lpfn = NULL;
	bi.lParam = 0;
	bi.iImage = 0;

	pidl = SHBrowseForFolder(&bi);
	return (pidl && SHGetPathFromIDList(pidl, path));
}

void CFindFileDlg::OnButtonselect() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	char buf[MAX_PATH] = {0};
	if (SelectPath(buf))
	{
		m_path = buf;
		m_path = m_path+"\\";
		UpdateData(FALSE);
	}
}

void CFindFileDlg::AddHide(CString findpath)
{
	CString stredit;
	CString strtemp;
	HANDLE hFile;
	WIN32_FIND_DATA fileinfo;
	DWORD errorcode = 0;
	int aaa=findpath.ReverseFind( '\\' );
	CString findpath_temp=findpath.Left(aaa+1)+"*";
	//MessageBox("addhide"+findpath);

	hFile=FindFirstFile(findpath_temp,&fileinfo);
	
	while(hFile!=INVALID_HANDLE_VALUE&&errorcode!=ERROR_NO_MORE_FILES)
	{
		strtemp=fileinfo.cFileName;
		//error:stredit=m_path.SpanExcluding("*")+strtemp;

		int path_index=findpath.ReverseFind( '\\' );
		stredit=findpath.Left(path_index+1)+strtemp;
		//MessageBox("333"+stredit);
		
		if( stredit==stredit.SpanExcluding(".") )	//文件夹
		{	//MessageBox("hide"+stredit);	
			m_hide.InsertItem(hidenum,stredit);
			hidenum++;
		}		
		FindNextFile(hFile,&fileinfo);
		errorcode=GetLastError();
	}
	CloseHandle(hFile);
}

void CFindFileDlg::OnClickListall(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    if(pNMListView->iItem != -1)
    {
		/*CString strtemp;
		strtemp.Format("单击的是第%d行第%d列",pNMListView->iItem, pNMListView->iSubItem);
		AfxMessageBox(strtemp);*/
		CString strtemp=m_showall.GetItemText(pNMListView->iItem,pNMListView->iSubItem);
		m_static=strtemp;
		UpdateData(FALSE);
    }

	*pResult = 0;
}

void CFindFileDlg::OnClickListfolder(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    if(pNMListView->iItem != -1)
    {
		CString strtemp=m_folder.GetItemText(pNMListView->iItem,pNMListView->iSubItem);
		m_static=strtemp;
		UpdateData(FALSE);
    }
	*pResult = 0;
}

void CFindFileDlg::OnClickListfile(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    if(pNMListView->iItem != -1)
    {
		CString strtemp=m_file.GetItemText(pNMListView->iItem,pNMListView->iSubItem);
		m_static=strtemp;
		UpdateData(FALSE);
    }

	*pResult = 0;
}

int CFindFileDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CSplashWnd::ShowSplashScreen(this); //显示启动画面 
	//this->MoveWindow(0,0,0,0);
	//this->SetTimer(1,900,NULL);

	return 0;
}

void CFindFileDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	//if(nIDEvent==1)
		//this->MoveWindow(200,160,640,480);
	/*else 
	{
		stopwhile=true;
		MessageBox("111111");
	}*/
	CDialog::OnTimer(nIDEvent);
}

void CFindFileDlg::OnClear() 
{
	// TODO: Add your control notification handler code here
	m_showall.DeleteAllItems();
	m_folder.DeleteAllItems();
	m_file.DeleteAllItems();
	m_hide.DeleteAllItems();
	m_path.Empty();
	UpdateData(FALSE);
}

BOOL CFindFileDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN) 
	{
		if(pMsg->wParam==VK_F2)
		{
			SendMessage(WM_TIMER);
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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