MFC程序(c++)之搜索所有文件和文件夹

本文档介绍了如何使用C++及MFC框架实现搜索计算机中所有文件和文件夹的功能。通过创建对话框类MySearchDlg,实现了用户界面交互,允许用户指定搜索路径并执行查找操作。
摘要由CSDN通过智能技术生成

效果图



//MySearchDlg.h

// MySearchDlg.h : 头文件
//

#pragma once


// CMySearchDlg 对话框
class CMySearchDlg : public CDialogEx
{
// 构造
public:
	CMySearchDlg(CWnd* pParent = NULL);	// 标准构造函数

// 对话框数据
	enum { IDD = IDD_MYSEARCH_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持

	void OnOK();
// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnDropFiles(HDROP hDropInfo);
	afx_msg void OnDblclkListbox();
	afx_msg void OnEnChangeEdit1();
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedCancel();
	afx_msg void OnLbnSelchangeList1();
	afx_msg void OnBnClickedOk2();
};

MySearchDlg.cpp

// MySearchDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "MySearch.h"
#include "MySearchDlg.h"
#include "afxdialogex.h"
//#include <sys/stat.h>
//#include <direct.h>
//#include <iostream>  
#include<fstream>  
//#include <shlwapi.h>
//#pragma comment(lib,"Shlwapi.lib") //如果没有这行,会出现link错误
using namespace std;  

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

int findCount = 0;
CListBox *list = NULL;
bool isContent = true;

char *wtoc(wchar_t *wText);
wchar_t *ctow(char *sText);
char *cstoc(CString cs);

//bool isDir(const char* path);  
unsigned myFind(const string& filename, const string& tofind);  
void findInDir(const char *path, const string& tofind);  
//void findInDir(const char *path, const string& tofind, int recursive);

char *wtoc(wchar_t *wText)
{
	DWORD dwNum = WideCharToMultiByte(CP_ACP, NULL, wText, -1,NULL, 0, NULL, FALSE);//把第五个参数设成NULL的到宽字符串的长度包括结尾符
	char *psText = NULL;
	psText = new char[dwNum];
	if(!psText)
	{
		delete []psText;
		psText = NULL;
	}
	WideCharToMultiByte (CP_ACP, NULL, wText, -1,psText, dwNum, NULL, FALSE);
	return psText;
}
wchar_t *ctow(char *sText)
{
	DWORD dwNum = MultiByteToWideChar (CP_ACP,  0, sText, -1, NULL,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值