?? ftpdownloaddlg.cpp
字號:
// FtpDownloadDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FtpDownload.h"
#include "FtpDownloadDlg.h"
#include "Ftpclient.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()
/////////////////////////////////////////////////////////////////////////////
// CFtpDownloadDlg dialog
CFtpDownloadDlg::CFtpDownloadDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFtpDownloadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFtpDownloadDlg)
m_strFtpSite = _T("");
m_strName = _T("");
m_strPwd = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFtpDownloadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFtpDownloadDlg)
DDX_Control(pDX, IDC_UPLOAD, m_BtnUpLoad);
DDX_Control(pDX, IDOK, m_BtnQuery);
DDX_Control(pDX, IDC_LIST_FILE, m_ListFile);
DDX_Control(pDX, IDC_EDIT_PWD, m_EditPwd);
DDX_Control(pDX, IDC_EDIT_NAME, m_EditName);
DDX_Control(pDX, IDC_EDIT_FTP, m_EditFtp);
DDX_Text(pDX, IDC_EDIT_FTP, m_strFtpSite);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
DDX_Text(pDX, IDC_EDIT_PWD, m_strPwd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFtpDownloadDlg, CDialog)
//{{AFX_MSG_MAP(CFtpDownloadDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, OnQuery)
ON_LBN_DBLCLK(IDC_LIST_FILE, OnDblclkListFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFtpDownloadDlg message handlers
BOOL CFtpDownloadDlg::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
// TODO: Add extra initialization here
ftp = new CFTPClient(this);
//域名初始化
m_strFtpSite=_T("se.sjtu.edu.cn");
//登錄名初始化
m_strName=_T("anonymous");
//口令初始化
m_strPwd=_T("anony@se.sjtu.edu.cn");
//更新界面
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFtpDownloadDlg::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 CFtpDownloadDlg::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 CFtpDownloadDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFtpDownloadDlg::OnQuery()
{
// TODO: Add your control notification handler code here
//獲得當前輸入
UpdateData(TRUE);
//清除列表框的內容
while(m_ListFile.GetCount()!=0)
m_ListFile.DeleteString(0);
//顯示文件和目錄名
ListContent();
}
void CFtpDownloadDlg::ListContent()
{//AfxMessageBox(m_strFtpSite);
//AfxMessageBox( m_strName);
//AfxMessageBox( m_strPwd);
ftp->Logon(m_strFtpSite ,21, m_strName,
m_strPwd);
ftp->List();
}
void CFtpDownloadDlg::OnDblclkListFile()
{
// TODO: Add your control notification handler code here
//獲得當前輸入
//獲得當前輸入
UpdateData(TRUE);
int nSel=m_ListFile.GetCurSel();
CString strSourceName;
CString m_strName;
BOOL m_bDirectory;
//獲得用戶在列表框中的選擇
nSel=m_ListFile.GetCurSel();
m_ListFile.GetText(nSel,strSourceName);
if(strSourceName.IsEmpty())
return ;
char ch = strSourceName.GetAt(0);
if(ch == 'd' || ch == 'D'){
m_bDirectory = TRUE;
}
else
if(ch == '-')
m_bDirectory = FALSE;
else{
if(strSourceName.Find("<DIR>") != -1 || strSourceName.Find("<dir>") != -1)
m_bDirectory = TRUE;
else
m_bDirectory = FALSE;
if(strSourceName.GetLength() < 40)
return ;
m_strName = strSourceName.Mid(39);
m_strName.TrimLeft();
m_strName.TrimRight();
}
int ndx = strSourceName.Find(':');
if(ndx == -1){
if(strSourceName.GetLength() > 56)
ndx = 51;
}
m_strName = strSourceName.Mid(ndx + 3);
m_strName.TrimLeft();
m_strName.TrimRight();
if(m_bDirectory==TRUE)
{m_strName.TrimLeft();
m_strName.TrimRight();
CString cmd = "CWD " + m_strName;// + "\r\n";
//獲得當前輸入
UpdateData(TRUE);
//清除列表框的內容
while(m_ListFile.GetCount()!=0)
m_ListFile.DeleteString(0);
ftp->FTPcommand(cmd);
ftp->FTPcommand("PWD");
ftp->List();}
else {
CFileDialog dlg(FALSE, NULL, "test", OFN_EXTENSIONDIFFERENT |
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"All Files(*.*)|*.*||");
if(dlg.DoModal() == IDOK){
CString strFileName = dlg.m_ofn.lpstrFile;
ftp->MoveFile(m_strName, strFileName, TRUE);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -