效果图
//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,