📄 fileexampledlg.cpp
字号:
// FileExampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileExample.h"
#include "FileExampleDlg.h"
#include "FileOP.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileExampleDlg dialog
CFileExampleDlg::CFileExampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileExampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileExampleDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFileExampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileExampleDlg)
DDX_Control(pDX, IDC_EDT_TEXTDISP, m_edtDisp);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileExampleDlg, CDialog)
//{{AFX_MSG_MAP(CFileExampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_COPY, OnBtnCopy)
ON_BN_CLICKED(IDC_BTN_GETSTATUS, OnBtnGetstatus)
ON_BN_CLICKED(IDC_BTN_SETSTATUS, OnBtnSetstatus)
ON_BN_CLICKED(IDC_BTN_DELETE, OnBtnDelete)
ON_BN_CLICKED(IDC_BTN_RENAME, OnBtnRename)
ON_BN_CLICKED(IDC_BTN_DISPLAY, OnBtnDisplay)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileExampleDlg message handlers
BOOL CFileExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
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);
}
}
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileExampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CFileExampleDlg::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 CFileExampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFileExampleDlg::OnBtnCopy()
{
// TODO: Add your control notification handler code here
CString strSourcePath, strTargetPath;
//取得文件路径
((CEdit *)GetDlgItem(IDC_EDT_SOURCE_PATH))->GetWindowText(strSourcePath);
((CEdit *)GetDlgItem(IDC_EDT_TARGET_PATH))->GetWindowText(strTargetPath);
//判断路径是否合法
if (strSourcePath.IsEmpty())
{
MessageBox("Please input Source Path!");
return;
}
if (strTargetPath.IsEmpty())
{
MessageBox("Please input Target Path!");
return;
}
//拷贝
if (!CFileOP::Copy(strSourcePath, strTargetPath))
MessageBox("Don't Copy files!");
else
MessageBox("Copy Success!");
}
void CFileExampleDlg::OnBtnGetstatus()
{
// TODO: Add your control notification handler code here
CString strSourcePath;
((CEdit *)GetDlgItem(IDC_EDT_SOURCE_PATH))->GetWindowText(strSourcePath);
if (strSourcePath.IsEmpty())
{
MessageBox("Please input File Path!");
return;
}
CFileStatus fs;
char c[20];
CString strSize;
memset(&fs, 0, sizeof(CFileStatus));
if (!CFile::GetStatus(strSourcePath, fs))
{
MessageBox("Can't get file info!");
return;
}
//取得文件长度
itoa(fs.m_size, c, 10);
strSize = c;
((CStatic *)GetDlgItem(IDC_LBL_FILELENGTH))->SetWindowText(strSize);
((CButton *)GetDlgItem(IDC_CHK_READONLY))->SetCheck(fs.m_attribute & CFile::readOnly);
((CButton *)GetDlgItem(IDC_CHK_HIDE))->SetCheck(fs.m_attribute & CFile::hidden);
((CButton *)GetDlgItem(IDC_CHK_SYSTEM))->SetCheck(fs.m_attribute & CFile::system);
}
void CFileExampleDlg::OnBtnSetstatus()
{
// TODO: Add your control notification handler code here
CString strSourcePath;
((CEdit *)GetDlgItem(IDC_EDT_SOURCE_PATH))->GetWindowText(strSourcePath);
if (strSourcePath.IsEmpty())
{
MessageBox("Please input File Path!");
return;
}
CFileStatus fs;
memset(&fs, 0, sizeof(CFileStatus));
if (!CFile::GetStatus(strSourcePath, fs))
{
MessageBox("Can't get file info!");
return;
}
if (((CButton *)GetDlgItem(IDC_CHK_READONLY))->GetCheck())
fs.m_attribute |= CFile::readOnly;
else
fs.m_attribute &= ~CFile::readOnly;
if (((CButton *)GetDlgItem(IDC_CHK_HIDE))->GetCheck())
fs.m_attribute |= CFile::hidden;
else
fs.m_attribute &= ~CFile::hidden;
if (((CButton *)GetDlgItem(IDC_CHK_SYSTEM))->GetCheck())
fs.m_attribute |= CFile::system;
else
fs.m_attribute &= ~CFile::system;
CFile::SetStatus(strSourcePath, fs);
}
void CFileExampleDlg::OnBtnDelete()
{
// TODO: Add your control notification handler code here
CString strSourcePath;
((CEdit *)GetDlgItem(IDC_EDT_SOURCE_PATH))->GetWindowText(strSourcePath);
if (strSourcePath.IsEmpty())
{
MessageBox("Please input File Path!");
return;
}
CFile::Remove(strSourcePath);
}
void CFileExampleDlg::OnBtnRename()
{
// TODO: Add your control notification handler code here
CString strSourcePath, strTargetPath;
//取得文件路径
((CEdit *)GetDlgItem(IDC_EDT_SOURCE_PATH))->GetWindowText(strSourcePath);
((CEdit *)GetDlgItem(IDC_EDT_TARGET_PATH))->GetWindowText(strTargetPath);
//判断路径是否合法
if (strSourcePath.IsEmpty())
{
MessageBox("Please input Source Path!");
return;
}
if (strTargetPath.IsEmpty())
{
MessageBox("Please input Target Path!");
return;
}
//改名
CFile::Rename(strSourcePath, strTargetPath);
}
void CFileExampleDlg::OnBtnDisplay()
{
// TODO: Add your control notification handler code here
CString strPath;
int lie;
//取得文件路径
((CEdit *)GetDlgItem(IDC_EDT_SOURCE_PATH))->GetWindowText(strPath);
lie = strPath.ReverseFind('.');
if (lie < 0 || strPath.Right(strPath.GetLength() - lie - 1).CompareNoCase("txt"))
{
MessageBox("Only display text file!");
return;
}
m_edtDisp.FillTextDisp(strPath);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -