📄 mainfrm.cpp
字号:
HINSTANCE hInst = AfxGetInstanceHandle();
WNDCLASS wc;
if (!::GetClassInfo(hInst, lpszOldClassName, &wc)) {
TRACE(_T("Can't find window class %s\n"), lpszOldClassName);
return NULL;
}
// Register new class with same info, but different name and icon.
//
wc.lpszClassName = lpszNewClassName;
wc.hIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(nIDResource));
if (!AfxRegisterClass(&wc)) {
TRACE(_T("Unable to register window class%s\n"), lpszNewClassName);
return NULL;
}
return lpszNewClassName;
}
// Static class member holds window class name
// (NULL if not registered yet).
//
LPCTSTR CMainFrame::s_winClassName = NULL;
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.lpszClass = AfxRegisterWndClass(0);
//Change the window class name
if (s_winClassName==NULL)
{
// One-time initialization: register the class
//
s_winClassName = RegisterSimilarClass(_T("FileZilla Main Window"),
cs.lpszClass, IDR_MAINFRAME);
if (!s_winClassName)
return FALSE;
}
cs.lpszClass = s_winClassName;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame Diagnose
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
dc << "FileZilla Main Window";
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame Nachrichten-Handler
void CMainFrame::OnQuickConnect()
{
ProcessQuickconnect(FALSE);
}
CStatusView* CMainFrame::GetStatusPane()
{
CWnd* pWnd = m_wndVertSplitter.GetPane(0, 0);
CStatusView* pView = DYNAMIC_DOWNCAST(CStatusView, pWnd);
return pView;
}
CQueueView* CMainFrame::GetQueuePane()
{
static CQueueView *sView=0;
if (sView)
return sView;
CWnd* pWnd = m_wndVertSplitter.GetPane(2, 0);
CQueueView* pView = DYNAMIC_DOWNCAST(CQueueView, pWnd);
sView=pView;
return pView;
}
CLocalView *CMainFrame::GetLocalPane()
{
static CLocalView *sView=0;
if (sView)
return sView;
CWnd* pWnd = m_wndLocalSplitter.GetPane(0, 0);
CLocalView* pView = DYNAMIC_DOWNCAST(CLocalView, pWnd);
sView=pView;
return pView;
}
CLocalView2 *CMainFrame::GetLocalPane2()
{
static CLocalView2 *sView=0;
if (sView)
return sView;
CWnd* pWnd;
if (m_nLocalTreeViewLocation)
pWnd = m_wndLocalSplitter.GetPane(0, 1);
else
pWnd = m_wndLocalSplitter.GetPane(1, 0);
CLocalView2* pView = DYNAMIC_DOWNCAST(CLocalView2, pWnd);
sView=pView;
return pView;
}
CFtpView *CMainFrame::GetFtpPane()
{
CWnd* pWnd;
if (m_nRemoteTreeViewLocation)
pWnd = m_wndRemoteSplitter.GetPane(0, 1);
else
pWnd = m_wndRemoteSplitter.GetPane(1, 0);
CFtpView* pView = DYNAMIC_DOWNCAST(CFtpView, pWnd);
return pView;
}
CFtpTreeView *CMainFrame::GetFtpTreePane()
{
CWnd* pWnd = m_wndRemoteSplitter.GetPane(0, 0);
CFtpTreeView* pView = DYNAMIC_DOWNCAST(CFtpTreeView, pWnd);
return pView;
}
void CMainFrame::SetLocalFolder(CString folder)
{
folder.TrimRight( _T("\\") );
CString folder2=folder;
folder+=_T("\\");
if ( folder2!="" && folder2.Right(1)!=_T(":") )
{
CFileStatus64 status;
if (!GetStatus64(folder2, status) || !(status.m_attribute&0x10))
{
m_pLocalViewHeader->m_pEdit->SetWindowText(GetLocalPane2()->GetLocalFolder());
if (m_pLocalViewHeader->m_pEdit->FindStringExact(-1, GetLocalPane2()->GetLocalFolder())==CB_ERR)
{
m_pLocalViewHeader->m_pEdit->AddString(GetLocalPane2()->GetLocalFolder());
}
return;
}
}
if (GetLocalPane2()->GetLocalFolder()!=folder)
{
GetLocalPane2()->SetLocalFolder(folder);
}
if (m_bShowTree)
if (GetLocalPane()->GetLocalFolder()!=folder)
{
GetLocalPane()->SetLocalFolder(folder);
}
m_pLocalViewHeader->m_pEdit->SetWindowText(folder);
if (m_pLocalViewHeader->m_pEdit->FindStringExact(-1, GetLocalPane2()->GetLocalFolder())==CB_ERR)
{
m_pLocalViewHeader->m_pEdit->AddString(GetLocalPane2()->GetLocalFolder());
}
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
if (m_wndStatusBar.GetSafeHwnd())
{
if (nType!=SIZE_MAXIMIZED)
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_SENDLED),ID_INDICATOR_SENDLED,SBPS_NOBORDERS,0);
else
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_SENDLED),ID_INDICATOR_SENDLED,SBPS_NOBORDERS,10);
}
if (initialized)
{
//Hide the queue if visible
m_wndVertSplitter.SetRedraw(FALSE);
if (m_bShowQueue)
m_wndVertSplitter.HideRow(2,1);
}
//Now only the main splitter gets resized
CFrameWnd::OnSize(nType, cx, cy);
if (initialized)
{
//Restore the queue
if (m_bShowQueue)
m_wndVertSplitter.ShowRow(2);
m_wndVertSplitter.SetRedraw(TRUE);
m_wndVertSplitter.RedrawWindow();
}
if (m_wndStatusBar.GetSafeHwnd())
{
RECT rc;
m_wndStatusBar.GetItemRect(m_wndStatusBar.CommandToIndex(ID_INDICATOR_PROGRESS_PANE), &rc);
// Reposition the progress control correctly!
m_ProgressCtrl.SetWindowPos(&wndTop, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, 0);
m_wndStatusBar.GetItemRect(m_wndStatusBar.CommandToIndex(ID_INDICATOR_RECVLED), &rc);
// Reposition the first LED correctly!
m_RecvLed.SetWindowPos(&wndTop, rc.left, rc.top+1, rc.right - rc.left,
rc.bottom - rc.top, 0);
m_wndStatusBar.GetItemRect(m_wndStatusBar.CommandToIndex(ID_INDICATOR_SENDLED), &rc);
// Reposition the second LED correctly!
m_SendLed.SetWindowPos(&wndTop, rc.left, rc.top+1, rc.right - rc.left+15,
rc.bottom - rc.top, SWP_SHOWWINDOW);
if (m_pSecureIconCtrl)
{
m_wndStatusBar.GetItemRect(m_wndStatusBar.CommandToIndex(ID_INDICATOR_SECURESERVER), &rc);
rc.left=rc.right-16;
m_pSecureIconCtrl->MoveWindow(&rc);
}
}
}
void CMainFrame::SetStatusbarText(int nIndex,CString str)
{
m_wndStatusBar.GetStatusBarCtrl().SetText(str,nIndex,0);
HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
if (str=="")
str.LoadString(m_wndStatusBar.GetItemID(nIndex));
CClientDC dcScreen(NULL);
HGDIOBJ hOldFont = NULL;
if (hFont != NULL)
hOldFont = dcScreen.SelectObject(hFont);
int cx=dcScreen.GetTextExtent(str).cx;
int cxold;
unsigned int nID,nStyle;
m_wndStatusBar.GetPaneInfo(nIndex,nID,nStyle,cxold);
if (cx!=cxold)
{
//m_wndStatusBar.SetPaneInfo(nIndex,nID,nStyle,cx);
RECT rc;
m_wndStatusBar.GetItemRect(m_wndStatusBar.CommandToIndex(ID_INDICATOR_PROGRESS_PANE), &rc);
// Reposition the progress control correctly!
m_ProgressCtrl.SetWindowPos(&wndTop, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, 0);
}
if (hOldFont != NULL)
dcScreen.SelectObject(hOldFont);
}
void CMainFrame::SetProgress(t_ffam_transferstatus *status)
{
if (!m_wndStatusBar.GetSafeHwnd())
return;
if (!status)
{
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ELAPSEDTIME),"");
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIMELEFT),"");
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_BYTES),"");
m_ProgressCtrl.ShowWindow(SW_HIDE);
}
else
{
CString str,str2;
str2.Format(_T("%d:%02d:%02d"), status->timeelapsed/3600, (status->timeelapsed/60)%60, status->timeelapsed%60);
str.Format(IDS_STATUSBAR_ELAPSED,str2);
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ELAPSEDTIME),str);
if (status->timeleft!=-1)
{
str2.Format(_T("%d:%02d:%02d"), status->timeleft/3600, (status->timeleft/60)%60, status->timeleft%60);
str.Format(IDS_STATUSBAR_LEFT,str2);
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIMELEFT),str);
}
else
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIMELEFT),"");
CString tmp=_T("? ");
if (status->transferrate)
{
if (status->transferrate>(1000*1000))
{
tmp.Format(_T("%d.%d M"),status->transferrate/1000/1000,(status->transferrate/1000/100)%10);
}
else if (status->transferrate>1000)
{
tmp.Format(_T("%d.%d K"),status->transferrate/1000,(status->transferrate/100)%10);
}
else
{
tmp.Format(_T("%d "),status->transferrate);
}
}
str.Format(_T("%I64d bytes (%sB/s)"), status->bytes,tmp);
SetStatusbarText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_BYTES), str);
if (status->percent!=-1)
{
m_ProgressCtrl.ShowWindow(SW_SHOW);
m_ProgressCtrl.SetPos(status->percent);
}
else
m_ProgressCtrl.ShowWindow(SW_HIDE);
}
}
void CMainFrame::AddQueueItem(BOOL get, CString filename, CString subdir, CString localdir, const CServerPath &remotepath, BOOL stdtransfer, CString user /*=""*/, CString pass /*=""*/, int nOpen /*0*/)
{
t_transferfile transferfile;
transferfile.remotefile = filename;
if (!m_nTransferType)
{
transferfile.nType = 2;
CString AsciiFiles = COptions::GetOption(OPTION_ASCIIFILES);
CString fn = filename;
fn.MakeUpper();
int i;
if (fn.Find( _T(".") )==-1)
while ((i=AsciiFiles.Find( _T(";") ))!=-1)
{
if (AsciiFiles.Left(i)==_T("."))
{
transferfile.nType = 1;
break;
}
AsciiFiles = AsciiFiles.Mid(i+1);
}
else
while ((i=AsciiFiles.Find( _T(";") ))!=-1)
{
if ("."+AsciiFiles.Left(i)==fn.Right(AsciiFiles.Left(i).GetLength()+1))
{
transferfile.nType = 1;
break;
}
AsciiFiles = AsciiFiles.Mid(i+1);
}
}
else
transferfile.nType = m_nTransferType;
localdir.TrimRight( _T("\\") );
if (!nOpen)
{
if (localdir == _T(""))
{
if (m_DropTarget == "")
transferfile.localfile = GetLocalPane2()->GetLocalFolder();
else
transferfile.localfile = m_DropTarget;
transferfile.localfile += _T("\\") + subdir + _T("\\") + filename;
while(transferfile.localfile.Replace( _T("\\\\"), _T("\\") ));
}
else
transferfile.localfile = localdir+_T("\\")+filename;
}
else
{
if (!get)
ASSERT(nOpen==3);
else
{
ASSERT(nOpen==1 || nOpen==2);
TCHAR temppath[MAX_PATH];
GetTempPath(MAX_PATH, temppath);
transferfile.localfile=temppath;
if (transferfile.localfile.Right(1)!=_T("\\"))
transferfile.localfile+=_T("\\");
transferfile.localfile+=transferfile.remotefile;
}
}
if (!remotepath.IsEmpty())
transferfile.remotepath = remotepath;
else
{
if (m_DropTarget != "")
transferfile.remotepath.SetSafePath(m_DropTarget);
else
transferfile.remotepath = ((CFtpListCtrl *)GetFtpPane()->GetListCtrl())->GetCurrentDirectory();
transferfile.remotepath.AddSubdirs(subdir);
}
transferfile.get = get;
if (GetFtpPane()->GetTransferfile(transferfile))
{
if (!get)
{
CFileStatus64 status;
BOOL res = GetStatus64(transferfile.localfile, status);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -