📄 filemergerdlg.cpp
字号:
// FileMergerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileMerger.h"
#include "FileMergerDlg.h"
#include "FMerge.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileMergerDlg dialog
CFileMergerDlg::CFileMergerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileMergerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileMergerDlg)
m_strDir = _T("");
m_strFile1 = _T("");
m_strFile2 = _T("");
m_strFileName = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFileMergerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileMergerDlg)
DDX_Text(pDX, IDC_ED_DIR, m_strDir);
DDX_Text(pDX, IDC_ED_FILE1, m_strFile1);
DDX_Text(pDX, IDC_ED_FILE2, m_strFile2);
DDX_Text(pDX, IDC_ED_FNAME, m_strFileName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileMergerDlg, CDialog)
//{{AFX_MSG_MAP(CFileMergerDlg)
ON_BN_CLICKED(IDC_BROWSE1, OnBrowse1)
ON_BN_CLICKED(IDC_BROWSE2, OnBrowse2)
ON_BN_CLICKED(IDC_BROWSED, OnBrowsed)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileMergerDlg message handlers
BOOL CFileMergerDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileMergerDlg::OnBrowse1()
{
CFileDialog fileDialog(TRUE,NULL,NULL,NULL,
"所有文件(*.*)|*.*||");
if (fileDialog.DoModal() == IDOK)
{
m_strFile1 = fileDialog.GetPathName();
UpdateData(FALSE);
}
}
void CFileMergerDlg::OnBrowse2()
{
CFileDialog fileDialog(TRUE,NULL,NULL,NULL,
"所有文件(*.*)|*.*||");
if (fileDialog.DoModal() == IDOK)
{
m_strFile2 = fileDialog.GetPathName();
UpdateData(FALSE);
}
}
void CFileMergerDlg::OnBrowsed()
{
CString strResult ="";
LPMALLOC lpMalloc; // pointer to IMalloc
if (::SHGetMalloc(&lpMalloc) != NOERROR)
{
AfxMessageBox("Path operation error!");
return ;
}
char szDisplayName[_MAX_PATH];
char szBuffer[_MAX_PATH];
BROWSEINFO browseInfo;
browseInfo.hwndOwner = this->m_hWnd;
// set root at Desktop
browseInfo.pidlRoot = NULL;
browseInfo.pszDisplayName = szDisplayName;
browseInfo.lpszTitle = "请选择分类数据路径"; // Dialog title
browseInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
browseInfo.lpfn = NULL; // not used
browseInfo.lParam = 0; // not used
LPITEMIDLIST lpItemIDList;
if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo))
!= NULL)
{
// Get the path of the selected folder from the item ID list.
if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
{
// At this point, szBuffer contains the path the user chose.
if (szBuffer[0] == '\0')
{
// SHGetPathFromIDList failed, or SHBrowseForFolder failed.
AfxMessageBox("Fail to get directory!",
MB_ICONSTOP|MB_OK);
return ;
}
// We have a path in szBuffer! Return it.
strResult = szBuffer;
}
else
{
// The thing referred to by lpItemIDList
// might not have been a file system object.
// For whatever reason, SHGetPathFromIDList didn't work!
AfxMessageBox("Fail to get directory!",
MB_ICONSTOP|MB_OK);
return ;
}
lpMalloc->Free(lpItemIDList);
lpMalloc->Release();
}
m_strDir=strResult;
UpdateData(FALSE);
}
void CFileMergerDlg::OnOK()
{
UpdateData();
CFMerge merge;
if(merge.Bind(m_strFile1,m_strFile2,m_strDir+"\\"+m_strFileName))
AfxMessageBox("Successful!");
else
AfxMessageBox("Failed!");
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -