// Search.cpp : implementation file
//
#include "stdafx.h"
#include "WinCEJob.h"
#include "Search.h"
#include "inireader.h"
#include "rtext.h"
#include "FileLoader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSearch dialog
CSearch::CSearch(CWnd* pParent /*=NULL*/)
: CDialog(CSearch::IDD, pParent)
{
//{{AFX_DATA_INIT(CSearch)
m_searchfile = _T("");
m_result = _T("");
//}}AFX_DATA_INIT
}
void CSearch::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSearch)
DDX_Text(pDX, IDC_EDIT1, m_searchfile);
DDX_Text(pDX, IDC_EDIT2, m_result);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSearch, CDialog)
//{{AFX_MSG_MAP(CSearch)
ON_BN_CLICKED(IDC_BUTTON1, OnOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSearch message handlers
//cemgrc.exe
void CSearch::OnOK()
{
UpdateData(true);
DoSearch(m_searchfile);
}
void CSearch::OnOpen()
{
// CIniReader Reader(m_result);
// Reader.Probe();
/* int a,b;
CString ca,cb;
FileLoader tmp(m_result);
ca.operator =("line 20");
tmp.SetBookmark(20,ca);
ca.operator =("line 40");
tmp.SetBookmark(40,ca);
ca.operator =("line 60");
tmp.SetBookmark(60,ca);
ca.operator =("line 70");
tmp.SetBookmark(70,ca);
ca.operator =("line 80");
tmp.SetBookmark(80,ca);
ca.operator =("line 90");
tmp.SetBookmark(90,ca);
b = tmp.GetMarkCount();
a = tmp.GetMarkLine(1);
b = tmp.GetMarkLine(5);
a = tmp.GetMarkLine(0);
ca.operator =(tmp.GetMarkName(0));
ca.operator =(tmp.GetMarkName(1));
ca.operator =(tmp.GetMarkName(5));
tmp.DelMark(1);
b = tmp.GetMarkCount();
a = tmp.GetMarkLine(1);
b = tmp.GetMarkLine(5);
a = tmp.GetMarkLine(0);
ca.operator =(tmp.GetMarkName(0));
ca.operator =(tmp.GetMarkName(1));
ca.operator =(tmp.GetMarkName(4));
a = tmp.GetMarkLine(0);
if(m_result.Right(3)!=L"txt" && m_result.Right(3) !=L"ini"&& m_result.Right(3) !=L"INI" && m_result.Right(3) !=L"EXE")
{
Reader.m_fileattr = 1;
}
if(Reader.m_fileattr == 0)
{
if(Reader.Load() == 1)
{
CRText ct;
ct.m_filetext = Reader.m_Buffer;
ct.DoModal();
}
else
{
MessageBox(L"指定文件不可读!");
}
return ;
}*/
}
void CSearch::DoSearch(CString str)
{
CString search[6];
search[0].Format(L"\\profiles\\%s", str);
search[1].Format(L"\\Program Files\\%s", str);
search[2].Format(L"\\Temp\\%s", str);
search[3].Format(L"\\My Documents\\%s", str);
search[4].Format(L"\\ConnMgr\\%s", str);
search[5].Format(L"\\windows\\%s", str);
HANDLE hFile;
for(int i=0; i {
hFile = CreateFile(
search[i],
GENERIC_READ,
FILE_SHARE_READ,
NULL, //security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if( hFile == INVALID_HANDLE_VALUE)
{
}
else
{
HWND hwnd;
this->GetDlgItem(IDC_EDIT2, &hwnd);
::ShowWindow(hwnd, SW_SHOW);
this->GetDlgItem(IDC_BUTTON1, &hwnd);
::ShowWindow(hwnd, SW_SHOW);
m_result = search[i];
this->SetDlgItemText(IDC_STATIC1, L"文件所在目录:");
UpdateData(false);
return ;
}
}
HWND hwnd;
this->GetDlgItem(IDC_EDIT2, &hwnd);
::ShowWindow(hwnd, SW_SHOW);
this->GetDlgItem(IDC_STATIC1, &hwnd);
::ShowWindow(hwnd, SW_SHOW);
this->GetDlgItem(IDC_BUTTON1, &hwnd);
::ShowWindow(hwnd, SW_SHOW);
m_result = L"Sorry, No find!!";
UpdateData(false);
}
/* m_store.Format(L"%s\\%s", m_store, str);
WIN32_FIND_DATA wfd;
// UpdateData(true);
HANDLE hand = FindFirstFile(L"*", &wfd);
if(wfd.cFileName == m_searchfile)
{
if(m_store == L"\\")
{
m_result.Format(L"\\%s", m_searchfile);
}
else
{
m_result.Format(L"\\%s\\%s", m_store, m_searchfile);
}
}
while(FindNextFile(hand, &wfd))
{
if(wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
DoSearch(wfd.cFileName);
}
else
{
if(wfd.cFileName == m_searchfile)
{
m_result.Format(L"\\%s", m_searchfile);
}
}
}
return;
*/