📄 filemadifydlg.cpp
字号:
// fileMadifyDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "fileMadify.h"
#include "fileMadifyDlg.h"
#include ".\filemadifydlg.h"
#include "FindFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CfileMadifyDlg 对话框
CfileMadifyDlg::CfileMadifyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CfileMadifyDlg::IDD, pParent)
, m_strPath(_T(""))
, m_bFileC(FALSE)
, m_bFileCPP(FALSE)
, m_bFileH(FALSE)
, m_strSrc(_T(""))
, m_strDest(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CfileMadifyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_strPath);
DDX_Check(pDX, IDC_CHECK1, m_bFileC);
DDX_Check(pDX, IDC_CHECK2, m_bFileCPP);
DDX_Check(pDX, IDC_CHECK3, m_bFileH);
DDX_Text(pDX, IDC_EDIT2, m_strSrc);
DDX_Text(pDX, IDC_EDIT3, m_strDest);
DDX_Control(pDX, IDC_LIST1, m_lsBox);
}
BEGIN_MESSAGE_MAP(CfileMadifyDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_SELECT, OnBnClickedButtonSelect)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
END_MESSAGE_MAP()
// CfileMadifyDlg 消息处理程序
BOOL CfileMadifyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 将\“关于...\”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
}
void CfileMadifyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CfileMadifyDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CfileMadifyDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CfileMadifyDlg::OnBnClickedButtonSelect()
{
//CFileDialog fdlg( TRUE, "", "*.*");
//fdlg.DoModal();
BROWSEINFO bi;
ITEMIDLIST *pidl;
char Dir[100] = "d:\\shared";
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = Dir;
bi.lpszTitle = "Select a directory";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder( &bi ); /* Display "Select Folder" dialog box, Get the folder name and convert it into a ITEMLISTdata structure. */
if ( pidl == NULL )
Dir[0] = 0;
if (!SHGetPathFromIDList( pidl, Dir )) /* Retrieve folder name from ITEMLIST structure. */
Dir[0] = 0;
m_strPath = Dir;
//this->UpdateDialogControls(
this->UpdateData( FALSE);
}
void CfileMadifyDlg::OnBnClickedOk()
{
POSITION pos;
UpdateData( TRUE);
CFindFile find;
CString rootPath = m_strPath;
rootPath.Append( "\\");
CStringList lsDir;
CStringList lsFileName;
CString strFliter;
lsDir.AddTail( rootPath);
find.FindDirInDir( rootPath, lsDir);
if( !m_bFileC && !m_bFileCPP && !m_bFileH)
{
MessageBox( "no select file type!");
return;
}
pos = lsDir.GetHeadPosition();
while( pos)
{
CString path = lsDir.GetNext( pos);
if( m_bFileC)
{
strFliter = "*.c";
find.FindFileInDir( path, lsFileName, strFliter);
}
if( m_bFileCPP)
{
strFliter = "*.cpp";
find.FindFileInDir( path, lsFileName, strFliter);
}
if( m_bFileH)
{
strFliter = "*.h";
find.FindFileInDir( path, lsFileName, strFliter);
}
}
pos = lsFileName.GetHeadPosition();
while( pos)
{
//CString str = lsFileName.;
CString str = lsFileName.GetNext(pos);
m_lsBox.AddString( str);
ModifyFile( str);
UpdateData( FALSE);
}
//OnOK();
}
int CfileMadifyDlg::ModifyFile( CString &filename)
{
FILE *fp = fopen( filename, "r+b");
if( !fp)
return FALSE;
int len;
fseek( fp, 0, SEEK_END);
len = ftell( fp);
fseek( fp, 0, SEEK_SET);
if( len <= 0)
{
fclose( fp);
return FALSE;
}
char *buf = (char*)malloc( len+10);
len = fread( buf, 1, len, fp);
int bChange = FALSE;
for( int i=0; i<len; i++)
{
if( buf[i] == 0x5C) // && buf[i+1] == 0x0d && buf[i+2] == 0x0a)
{
if( buf[i+1] == 0x0D) //0x20) //0x0D)
{
if( buf[i+2] == 0x0A)
{
buf[i+1] = 0x20;
bChange = TRUE;
len--;
memcpy( buf+i+1, buf+i+2, len-i-1);
}
}
}
}
if( bChange)
{
fp = fopen( filename, "w+b");
fwrite( buf, 1, len, fp);
fclose( fp);
}
return 0;
}
void CfileMadifyDlg::OnBnClickedButton2()
{
CString name = "DeprecationMgr.h";
ModifyFile( name);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -