📄 sample34view.cpp
字号:
// Sample34View.cpp : implementation of the CSample34View class
//
#include "stdafx.h"
#include "Sample34.h"
#include "Sample34Doc.h"
#include "Sample34View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSample34View
IMPLEMENT_DYNCREATE(CSample34View, CFormView)
BEGIN_MESSAGE_MAP(CSample34View, CFormView)
//{{AFX_MSG_MAP(CSample34View)
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_LBN_DBLCLK(IDC_LIST, OnDblclkList)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSample34View construction/destruction
CSample34View::CSample34View()
: CFormView(CSample34View::IDD)
{
//{{AFX_DATA_INIT(CSample34View)
m_sPSW = _T("user@sina.com");
m_sServer = _T("192.168.1.12");
m_sUser = _T("anonymous");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_pFtpConnection = NULL;
m_sFullPath = "";
}
CSample34View::~CSample34View()
{
}
void CSample34View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSample34View)
DDX_Control(pDX, IDC_LIST, m_listDirectory);
DDX_Text(pDX, IDC_PSW, m_sPSW);
DDX_Text(pDX, IDC_SERVER, m_sServer);
DDX_Text(pDX, IDC_USER, m_sUser);
//}}AFX_DATA_MAP
}
BOOL CSample34View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CSample34View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CSample34View printing
BOOL CSample34View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSample34View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSample34View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CSample34View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CSample34View diagnostics
#ifdef _DEBUG
void CSample34View::AssertValid() const
{
CFormView::AssertValid();
}
void CSample34View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CSample34Doc* CSample34View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSample34Doc)));
return (CSample34Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSample34View message handlers
void CSample34View::OnConnect()
{
// 清空列表框
Clear();
// 更新数据
UpdateData(TRUE);
try
{
// 与FTP服务器建立连接
m_pFtpConnection = m_InternetSession.GetFtpConnection(m_sServer, m_sUser, m_sPSW);
// 设置当前目录
m_pFtpConnection->SetCurrentDirectory(m_sFullPath);
}
catch (CInternetException* pEx)
{
// 异常处理
m_pFtpConnection = NULL;
pEx->Delete();
return;
}
CFtpFileFind Files(m_pFtpConnection);
// 寻找第一个文件
BOOL ret = Files.FindFile(m_sFullPath + "/*");
if (ret == FALSE)
Clear();
m_listDirectory.AddString("..");
while (ret)
{
// 寻找下一个文件
ret = Files.FindNextFile();
// 添加到列表框
m_listDirectory.AddString(Files.GetFileName());
}
// 关闭连接
m_pFtpConnection->Close();
}
void CSample34View::Clear()
{
// 清空列表框
while(m_listDirectory.GetCount() > 0)
{
for (int i = 0; i < m_listDirectory.GetCount(); i++)
m_listDirectory.DeleteString(i);
}
}
BOOL CSample34View::DestroyWindow()
{
// 关闭会话
m_InternetSession.Close();
return CFormView::DestroyWindow();
}
void CSample34View::OnDblclkList()
{
// 得到光标所在位置
int ID = m_listDirectory.GetCurSel();
if (ID > 0)
{
// 到下一级目录
CString sPath;
m_listDirectory.GetText(ID, sPath);
m_sFullPath = m_sFullPath + sPath + "/*";
}
else
{
// 回到上一级目录
m_sFullPath = m_sFullPath.Left(m_sFullPath.ReverseFind('\\'));
}
// 在新目录重新连接
OnConnect();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -