// fjhDlg.cpp : implementation file
//
#include "stdafx.h"
#include "fjh.h"
#include "fjhDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
char THIS_FILE[] = __FILE__;
#endif
BOOL fileopenflag=1;
HANDLE m_hListenerThread;
int add=0;
int flag1=0,flag2=0,flag3=0,flag4=0;
/////////////////////////////////////////////////////////////////////////////
// CFjhDlg dialog
CFjhDlg::CFjhDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFjhDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFjhDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFjhDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFjhDlg)
DDX_Control(pDX, IDC_EDIT4, m_e4);
DDX_Control(pDX, IDC_START, m_s);
DDX_Control(pDX, IDC_EDIT3, m_e3);
DDX_Control(pDX, IDC_EDIT2, m_e2);
DDX_Control(pDX, IDC_EDIT1, m_e1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFjhDlg, CDialog)
//{{AFX_MSG_MAP(CFjhDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_MESSAGE(MYWM_NOTIFYICON,OnMyNotifyIcon)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_BN_CLICKED(IDC_START, OnStart)
ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFjhDlg message handlers
BOOL CFjhDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
/*
unsigned long idThread;
m_hListenerThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)findsearchfile,
0,0,&idThread); */
m_s.EnableWindow(FALSE);
LPTSTR lpBuffer=0;
DWORD i,j=500;
lpBuffer=LPTSTR(malloc(j));
i=GetCurrentDirectory(j,lpBuffer);
m_e4.SetWindowText(lpBuffer);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CFjhDlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFjhDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFjhDlg::OnFind()
{
CFjhDlg::GMXTaskBarAddIcon();
ShowWindow(SW_HIDE);
}
BOOL CFjhDlg::findreplacetext(CString filename)
{
DWORD size;
LPBYTE buf;
CFile fp;
int i;
i=fp.Open(filename,CFile::modeRead,NULL);
if(i==1)
{
size=fp.GetLength();
buf=LPBYTE(malloc(size));
//fp.LockRange(0,size);
fp.ReadHuge(buf,size);
//fp.Read(buf,size);
CString datafjh=buf;
CString text;
CString repltext;
m_e2.GetWindowText(text);
m_e3.GetWindowText(repltext);
datafjh.Replace(text,repltext);
/*
int j;
for(j=0;j<=size;j++)
{
buf[j]=datafjh[j];
}*/
buf=LPBYTE(datafjh.GetBuffer(size));
fp.Close();
DeleteFile(filename);
CFile fp1;
fp1.Open(filename,CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite,NULL);
//fp.LockRange(0,size);
fp1.WriteHuge(buf,size);
//fp1.Write(buf,size);
fp1.Close();
buf=0;
free(buf);
return 1;
}
else
{
CString erroinf("文件打开错误");
MessageBox(filename+erroinf);
return 0;
}
}
CFjhDlg::findsearchfile()
{
WIN32_FIND_DATA filedata;
HANDLE searchfile;
BOOL nextfile=1,fileopenreturn=1;
SHORT indata=0;
CString filename(" ");
CString pathname(" ");
m_e1.GetWindowText(filename);
m_e4.GetWindowText(pathname);
SetCurrentDirectory(pathname);
searchfile=FindFirstFile(filename,&filedata);
if(searchfile==INVALID_HANDLE_VALUE){MessageBox("没有找到文件","fjh",NULL);}
else
{
fileopenreturn=findreplacetext(filedata.cFileName);
// m_list.AddString(filedata.cFileName);
while(nextfile)
{
nextfile=FindNextFile(searchfile,&filedata);
if(nextfile==0)break;
// m_list.AddString(filedata.cFileName);
fileopenreturn=findreplacetext(filedata.cFileName);
}
FindClose(searchfile);
if(fileopenreturn==1)MessageBox("查找替换成功");
}
}
int CFjhDlg::GMXTaskBarAddIcon()
{
BOOL res;
NOTIFYICONDATA tnid;
HICON hicon;
hicon=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDR_MAINFRAME));
tnid.cbSize=sizeof(NOTIFYICONDATA);
tnid.hWnd=m_hWnd;
tnid.uID=IDR_MAINFRAME;
tnid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnid.uCallbackMessage=MYWM_NOTIFYICON;
tnid.hIcon=hicon;
lstrcpyn(tnid.szTip,MYTIP,sizeof(MYTIP));
res=Shell_NotifyIcon(NIM_ADD,&tnid);
if(hicon)
DestroyIcon(hicon);
return res;
}
int CFjhDlg::GMXTaskBarDeleteIcon()
{
BOOL res;
NOTIFYICONDATA tnid;
tnid.cbSize=sizeof(NOTIFYICONDATA);
tnid.hWnd =m_hWnd;
tnid.uID =IDR_MAINFRAME;
res=Shell_NotifyIcon(NIM_DELETE,&tnid);
return res;
}
LRESULT CFjhDlg::OnMyNotifyIcon(WPARAM wParam,LPARAM lParam)
{
switch(lParam)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN:
if(wParam=IDR_MAINFRAME)
{
ShowWindow(SW_SHOW);
SetForegroundWindow();
break;
}
/*if(wParam==IDR_MAINFRAME)
{
CMenu *pt,t;
CPoint pp(LOWORD(lParam),HIWORD(lParam));
t.LoadMenu(IDR_MENU);
pt=t.GetSubMenu(0);
ClientToScreen(&pp);
pt->TrackPopupMenu (TPM_RIGHTALIGN|TPM_LEFTBUTTON,pp.x+350,GetSystemMetrics(SM_CYSCREEN)-50,this,NULL);
}
break; */
default:
break;
}
return 0L;
}
void CFjhDlg::OnOK()
{
int i;
// DWORD ExitCode;
fileopenflag=0;
for(i=0;i<1000;i++){}
GMXTaskBarDeleteIcon();
//if(GetExitCodeThread(m_hListenerThread,&ExitCode))
//TerminateThread(m_hListenerThread,ExitCode);
// TODO: Add extra validation here
CDialog::OnOK();
}
void CFjhDlg::OnChangeEdit1()
{
if(flag1==0)
{
add++;
if(add>=4)
{
m_s.EnableWindow(TRUE);
add=0;
}
}
flag1=1;
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CFjhDlg::OnChangeEdit2()
{
if(flag2==0){
add++;
if(add>=4)
{
m_s.EnableWindow(TRUE);
add=0;
}
}
flag2=1;
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CFjhDlg::OnChangeEdit3()
{
if(flag3==0)
{
add++;
if(add>=4)
{
m_s.EnableWindow(TRUE);
add=0;
}
}
flag3=1;
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_C
findstring 文本替换
3星 · 超过75%的资源 需积分: 9 97 浏览量
2010-10-14
22:01:43
上传
评论
收藏 30KB ZIP 举报
ssss5257
- 粉丝: 10
- 资源: 19