📄 applicationdlg.cpp
字号:
CSize size = dc.GetTextExtent(strStatus);
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
}
/********************************************************************/
/* */
/* Function name : OnFTPSentBytesChange */
/* Description : Number of sent bytes has changed. */
/* */
/********************************************************************/
void CApplicationDlg::OnFTPSentBytesChange(int nBytes)
{
m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
CString strStatus;
strStatus.Format("%s sent", FormatSize(nBytes, 0));
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
CClientDC dc(this);
CSize size = dc.GetTextExtent(strStatus);
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
}
/********************************************************************/
/* */
/* Function name : OnViewTrace */
/* Description : Handle menu selection. */
/* */
/********************************************************************/
void CApplicationDlg::OnViewTrace()
{
ActivatePage(0);
}
/********************************************************************/
/* */
/* Function name : OnViewOnlineUsers */
/* Description : Handle menu selection. */
/* */
/********************************************************************/
void CApplicationDlg::OnViewOnlineUsers()
{
ActivatePage(1);
}
/********************************************************************/
/* */
/* Function name : OnViewConfiguration */
/* Description : Handle menu selection. */
/* */
/********************************************************************/
void CApplicationDlg::OnViewConfiguration()
{
ActivatePage(2);
}
/********************************************************************/
/* */
/* Function name : OnViewStatistics */
/* Description : Handle menu selection. */
/* */
/********************************************************************/
void CApplicationDlg::OnViewStatistics()
{
ActivatePage(3);
}
/********************************************************************/
/* */
/* Function name : OnViewSecurity */
/* Description : Handle menu selection. */
/* */
/********************************************************************/
void CApplicationDlg::OnViewSecurity()
{
ActivatePage(4);
}
/********************************************************************/
/* */
/* Function name : OnUpdateViewTrace */
/* Description : Update menu state of Trace item. */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
}
/********************************************************************/
/* */
/* Function name : OnUpdateViewOnlineUsers */
/* Description : Update menu state of Online Users item. */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
}
/********************************************************************/
/* */
/* Function name : OnUpdateViewConfiguration */
/* Description : Update menu state of Configuration item. */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
}
/********************************************************************/
/* */
/* Function name : OnUpdateViewStatistics */
/* Description : Update menu state of Statistics item. */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
}
/********************************************************************/
/* */
/* Function name : OnUpdateViewSecurity */
/* Description : Update menu state of Security item. */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
{
pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
}
/********************************************************************/
/* */
/* Function name : PreTranslateMessage */
/* Description : Needed to make tooltips work. */
/* */
/********************************************************************/
BOOL CApplicationDlg::PreTranslateMessage(MSG* pMsg)
{
// enable tooltips
if (m_hWnd)
{
if (IsWindow(m_ToolTipCtrl.m_hWnd))
m_ToolTipCtrl.RelayEvent(pMsg);
}
return CDialogResize::PreTranslateMessage(pMsg);
}
/********************************************************************/
/* */
/* Function name : OnToolTipText */
/* Description : Tooltip handler for this dialog. */
/* */
/********************************************************************/
BOOL CApplicationDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
// need to handle both ANSI and UNICODE versions of the message
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
TCHAR szFullText[256];
CString cstTipText;
CString cstStatusText;
UINT nID = pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
// idFrom is actually the HWND of the tool
nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));
}
if (nID != 0) // will be zero on a separator
{
AfxLoadString(nID, szFullText);
// this is the command id, not the button index
AfxExtractSubString(cstTipText, szFullText, 1, '\n');
AfxExtractSubString(cstStatusText, szFullText, 0, '\n');
}
// Non-UNICODE Strings only are shown in the tooltip window...
if (pNMHDR->code == TTN_NEEDTEXTA)
lstrcpyn(pTTTA->szText, cstTipText,
(sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
else
_mbstowcsz(pTTTW->szText, cstTipText,
(sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
*pResult = 0;
// bring the tooltip window above other popup windows
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
// message was handled
return TRUE;
}
/********************************************************************/
/* */
/* Function name : SetOnlineLed */
/* Description : Turn online LED on/off. */
/* */
/********************************************************************/
void CApplicationDlg::SetOnlineLed(BOOL bOnline)
{
HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
IMAGE_ICON, 16, 16, LR_SHARED);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
m_wndStatusBar.GetStatusBarCtrl().Invalidate();
m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
DestroyIcon(hIcon);
}
/********************************************************************/
/* */
/* Function name : SetOfflineLed */
/* Description : Turn offline LED on/off. */
/* */
/********************************************************************/
void CApplicationDlg::SetOfflineLed(BOOL bOffline)
{
HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
IMAGE_ICON, 16, 16, LR_SHARED);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
m_wndStatusBar.GetStatusBarCtrl().Invalidate();
m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
DestroyIcon(hIcon);
}
/********************************************************************/
/* */
/* Function name : OnUpdateApply */
/* Description : Update FTP server parameters. */
/* */
/********************************************************************/
void CApplicationDlg::OnApply()
{
m_ConfigurationPage.UpdateData();
theServer.SetPort(m_ConfigurationPage.m_nPort);
theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
SetWindowText(m_ConfigurationPage.m_strApplicationName);
// set log level
theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
OnFTPStatusChange(0, "FTP Server configuration updated.");
}
void CApplicationDlg::OnFTPStatisticChange(int nType, int nValue)
{
m_StatisticsPage.SetValue(nType, nValue);
}
/********************************************************************/
/* */
/* Function name : FormatSize */
/* Description : Format size, the way explorer diplays it */
/* */
/********************************************************************/
char* CApplicationDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
{
static char szBuff[100];
unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
unsigned __int64 kb = 0;
if (nFileSize > 1024)
{
kb = nFileSize / 1024;
if (nFileSize % 1024)
kb++;
}
// make it a string
_ui64tot(kb, szBuff, 10);
// add thousand seperators
int nLength = lstrlen(szBuff);
if (nLength > 3)
{
LPCTSTR ptr = szBuff;
ptr += (nLength-1);
char szTemp[100];
LPTSTR ptrTemp = szTemp;
for(int i=0; i<nLength; i++)
{
if (i && ((i % 3) == 0))
{
if (*ptrTemp != ',')
{
*ptrTemp = ',';
ptrTemp = _tcsinc(ptrTemp);
}
}
*ptrTemp = *ptr;
ptrTemp = _tcsinc(ptrTemp);
ptr = _tcsdec(szBuff, ptr);
}
// terminate string
*ptrTemp = '\0';
// reverse string
_tcsrev(szTemp);
lstrcpy(szBuff, szTemp);
}
// add 'KB' to it
lstrcat(szBuff, " KB");
return szBuff;
}
/********************************************************************/
/* */
/* Function name : OnAccountWizard */
/* Description : Launch New Account Wizard */
/* */
/********************************************************************/
void CApplicationDlg::OnAccountWizard()
{
CBitmap bmpHeader, bmpWatermark;
VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
// show windows 2000-like wizard
CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
if (wizSheet.DoModal() == ID_WIZFINISH)
{
CArray<CUser, CUser&> m_UserArray;
theServer.m_UserManager.GetUserList(m_UserArray);
int nIndex = -1;
for (int i=0; i<m_UserArray.GetSize(); i++)
{
// if it already exists -> update it
if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
{
nIndex = i;
break;
}
}
// add new account ?
if (nIndex == -1)
{
CUser user;
nIndex = m_UserArray.Add(user);
}
m_UserArray[nIndex].m_bAccountDisabled = FALSE;
m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
// add home directory
CDirectory directory;
directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
directory.m_strAlias = "";
directory.m_bIsHomeDir = TRUE;
directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
directory.m_strAlias = "";
m_UserArray[nIndex].m_DirectoryArray.Add(directory);
// update
theServer.m_UserManager.UpdateUserList(m_UserArray);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -