?? dbreaderdlg.cpp
字號:
// DBReaderDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DBReader.h"
#include "DBReaderDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CDBReaderDlg dialog
CDBReaderDlg::CDBReaderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDBReaderDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDBReaderDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pReader = NULL;
}
void CDBReaderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDBReaderDlg)
DDX_Control(pDX, IDC_STATIC_STATE, m_state);
DDX_Control(pDX, IDC_PROGRESS_DO, m_progress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDBReaderDlg, CDialog)
//{{AFX_MSG_MAP(CDBReaderDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_DO, OnButtonDo)
ON_BN_CLICKED(IDC_BUTTON_FILE, OnButtonFile)
ON_BN_CLICKED(IDC_BUTTON_TXT, OnButtonTxt)
//}}AFX_MSG_MAP
ON_MESSAGE(CReader::WM_WTNOTIFY,OnWorkingNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDBReaderDlg message handlers
BOOL CDBReaderDlg::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
m_progress.SetRange(0,10000);
m_progress.SetPos(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDBReaderDlg::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 CDBReaderDlg::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 CDBReaderDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDBReaderDlg::OnButtonDo()
{
// TODO: Add your control notification handler code here
CString sFile1,sFile2;
GetDlgItemText(IDC_EDIT_FILE_SOURCE,sFile1);
GetDlgItemText(IDC_EDIT_FILE_TARGET,sFile2);
if (m_pReader != NULL)
{
delete m_pReader;
m_pReader = NULL;
}
m_pReader = new CReader(this,sFile1,sFile2);
m_pReader->DoWork();
GetDlgItem(IDC_BUTTON_DO)->EnableWindow(FALSE);
GetDlgItem(IDCANCEL)->EnableWindow(TRUE);
}
void CDBReaderDlg::OnButtonFile()
{
// TODO: Add your control notification handler code her
CString tsFilters;
static char BASED_CODE szFilter[] = "數據庫文件(*.dbf)|*.dbf|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE, NULL,NULL , OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
if (dlg.DoModal() == IDCANCEL)
return;
SetDlgItemText(IDC_EDIT_FILE_SOURCE,dlg.GetPathName());
CString sDest;
GetDlgItemText(IDC_EDIT_FILE_TARGET,sDest);
if (sDest.IsEmpty())
{
sDest.Format("%stxt",dlg.GetPathName().Left(dlg.GetPathName().GetLength()-3));
SetDlgItemText(IDC_EDIT_FILE_TARGET,sDest);
}
}
void CDBReaderDlg::OnButtonTxt()
{
// TODO: Add your control notification handler code here
CString sFilePath;
DWORD dwFlags ;
dwFlags = OFN_FILEMUSTEXIST ;
CFileDialog dlg(FALSE,"TXT",NULL,OFN_OVERWRITEPROMPT|OFN_EXPLORER|OFN_ENABLESIZING|OFN_FILEMUSTEXIST,
"TXT(文本)(*.txt)|*.txt||",this);
if (dlg.DoModal() == IDCANCEL)
return;
sFilePath = dlg.GetPathName();
if(IsFileExists(sFilePath))
{
::DeleteFile(sFilePath);
}
SetDlgItemText(IDC_EDIT_FILE_TARGET , sFilePath);
}
void CDBReaderDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
LRESULT CDBReaderDlg::OnWorkingNotify(WPARAM tiPos1, LPARAM tiPos2)
{
TNotifyMsg *pMsg = (TNotifyMsg*)tiPos1;
if (pMsg != NULL)
{
m_progress.SetPos(10000 * pMsg->GetProgress());
m_state.SetWindowText(pMsg->GetState());
delete pMsg;
pMsg = NULL;
}
return 0;
}
bool CDBReaderDlg::IsFileExists(const CString szFileFullPath)
{
bool bExists = false;
CFileStatus fileStat;
if(CFile::GetStatus(szFileFullPath, fileStat))
{
if((fileStat.m_attribute & CFile::directory) == 0)
{
bExists = true;
}
}
return bExists;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -