📄 applicationdlg.cpp
字号:
/****************************************************************/
/* */
/* ApplicationDlg.cpp */
/* */
/* Implementation of the CApplicationDlg class. */
/* This class is a part of the FTP Server. */
/* */
/* Programmed by Pablo van der Meer */
/* Copyright Pablo Software Solutions 2002 */
/* http://www.pablovandermeer.nl */
/* */
/* Last updated: 10 july 2002 */
/* */
/****************************************************************/
#include "stdafx.h"
#include "FTPServerApp.h"
#include "FTPServer.h"
#include "ApplicationDlg.h"
#include "UserAccountsDlg.h"
#include "WizardPages.h"
#include "AboutDlg.h"
#include <afxpriv.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFTPServerApp theApp;
extern CFTPServer theServer;
static UINT auIDStatusBar[] =
{
ID_SEPARATOR,
ID_INDICATOR_DATA_RECEIVED,
ID_INDICATOR_DATA_SEND,
ID_INDICATOR_ONLINELED,
ID_INDICATOR_OFFLINELED
};
/********************************************************************/
/* */
/* Function name : CApplicationDlg::CApplicationDlg */
/* Description : Constructor */
/* */
/********************************************************************/
CApplicationDlg::CApplicationDlg(CWnd* pParent /*=NULL*/)
: CDialogResize(CApplicationDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CApplicationDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDI_FTPSERVER);
m_bInitialized = FALSE;
}
/********************************************************************/
/* */
/* Function name : CApplicationDlg::~CApplicationDlg */
/* Description : Destructor */
/* */
/********************************************************************/
CApplicationDlg::~CApplicationDlg()
{
}
/********************************************************************/
/* */
/* Function name : CApplicationDlg::DoDataExchange */
/* Description : Called by the framework to exchange and validate */
/* dialog data. */
/* */
/********************************************************************/
void CApplicationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogResize::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CApplicationDlg)
DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CApplicationDlg, CDialogResize)
//{{AFX_MSG_MAP(CApplicationDlg)
ON_WM_SYSCOMMAND()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_COMMAND(ID_SERVER_START, OnServerStart)
ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
ON_COMMAND(ID_SERVER_STOP, OnServerStop)
ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop)
ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
ON_WM_CLOSE()
ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
ON_COMMAND(IDC_APPLY, OnApply)
END_MESSAGE_MAP()
BEGIN_DLGRESIZE_MAP(CApplicationDlg)
DLGRESIZE_CONTROL(IDC_OUTLOOKBAR, DLSZ_SIZE_Y)
DLGRESIZE_CONTROL(IDC_DIALOG_AREA, DLSZ_SIZE_X | DLSZ_SIZE_Y)
DLGRESIZE_CONTROL(AFX_IDW_STATUS_BAR, DLSZ_MOVE_Y | DLSZ_SIZE_X)
DLGRESIZE_CONTROL(AFX_IDW_TOOLBAR, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_STATIC1, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_INFOBAR, DLSZ_SIZE_X)
END_DLGRESIZE_MAP()
/********************************************************************/
/* */
/* Function name : CApplicationDlg::OnInitDialog */
/* Description : Called by the framework in response to the */
/* WM_INITDIALOG message. */
/* */
/********************************************************************/
BOOL CApplicationDlg::OnInitDialog()
{
CDialogResize::OnInitDialog();
// setup listview ctrl, so that it looks like the outbar control
SetupOutlookBar();
// Add statusbar to the dialog
CreateStatusbar();
CRect rect;
GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
ScreenToClient(rect);
rect.right+=4;
GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
InitResizing(FALSE);
int s, t, b, r, l;
if (AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
{
// only restore if there is a previously saved position
if ( -1 != (s = AfxGetApp()->GetProfileInt("Settings", "FrameStatus", -1)) &&
-1 != (t = AfxGetApp()->GetProfileInt("Settings", "FrameTop", -1)) &&
-1 != (l = AfxGetApp()->GetProfileInt("Settings", "FrameLeft", -1)) &&
-1 != (b = AfxGetApp()->GetProfileInt("Settings", "FrameBottom", -1)) &&
-1 != (r = AfxGetApp()->GetProfileInt("Settings", "FrameRight", -1))
)
{
WINDOWPLACEMENT wp;
// restore the window's status
wp.showCmd = s;
// restore the window's width and height
wp.rcNormalPosition.bottom = b;
wp.rcNormalPosition.right = r;
// the following correction is needed when the taskbar is
// at the left or top and it is not "auto-hidden"
RECT workArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
l += workArea.left;
t += workArea.top;
// make sure the window is not completely out of sight
int max_x = GetSystemMetrics(SM_CXSCREEN) -
GetSystemMetrics(SM_CXICON);
int max_y = GetSystemMetrics(SM_CYSCREEN) -
GetSystemMetrics(SM_CYICON);
wp.rcNormalPosition.top = min(t, max_y);
wp.rcNormalPosition.left = min(l, max_x);
SetWindowPlacement(&wp);
}
}
// create property pages
m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
// activate main page
ActivatePage(0);
// Set the icon for this dialog.
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// get registry values
m_ConfigurationPage.m_nPort = AfxGetApp()->GetProfileInt("Settings", "Port", 21);
m_ConfigurationPage.m_nMaxUsers = AfxGetApp()->GetProfileInt("Settings", "MaxUsers", 10);
m_ConfigurationPage.m_nTimeout = AfxGetApp()->GetProfileInt("Settings", "Timeout", 5);
m_ConfigurationPage.m_strWelcomeMessage = AfxGetApp()->GetProfileString("Settings", "WelcomeMsg", "Welcome to Pablo's FTP Server");
m_ConfigurationPage.m_strGoodbyeMessage = AfxGetApp()->GetProfileString("Settings", "GoodbyeMsg", "Bye");
m_ConfigurationPage.m_bLaunchOnStartup = AfxGetApp()->GetProfileInt("Settings", "LaunchOnStartup", 0);
m_ConfigurationPage.m_bStartInTray = AfxGetApp()->GetProfileInt("Settings", "StartInTray", 0);
m_ConfigurationPage.m_bAutoActivate = AfxGetApp()->GetProfileInt("Settings", "AutoActivate", 0);
m_ConfigurationPage.m_nLogLevel = AfxGetApp()->GetProfileInt("Settings", "LogLevel", 1);
m_ConfigurationPage.m_strApplicationName = AfxGetApp()->GetProfileString("Settings", "AppName", "Pablo's FTP Server");
m_ConfigurationPage.UpdateData(FALSE);
SetWindowText(m_ConfigurationPage.m_strApplicationName);
// set log level
theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
// and finally, let's add some tooltips
m_ToolTipCtrl.Create(this);
m_ToolTipCtrl.Activate(TRUE);
// minimize at startup ?
if (m_ConfigurationPage.m_bStartInTray)
{
PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
// this seems to be a workaround to let the statement above to get working
CRect rect;
GetWindowRect(rect);
SetWindowPos(&CWnd::wndTop, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE);
}
theServer.Initialize(this);
if (m_ConfigurationPage.m_bAutoActivate)
{
OnServerStart();
}
m_bInitialized = TRUE;
return TRUE;
}
/********************************************************************/
/* */
/* Function name : CApplicationDlg::OnSysCommand */
/* Description : Here we catch the minimizing */
/* */
/********************************************************************/
void CApplicationDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
switch(nID)
{
case SC_MINIMIZE:
// do not minimize to the taskbar
ShowWindow(SW_HIDE);
break;
default:
CDialog::OnSysCommand(nID, lParam);
break;
}
}
/********************************************************************/
/* */
/* Function name : OnSize */
/* Description : Handle WM_SIZE message */
/* */
/********************************************************************/
void CApplicationDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogResize::OnSize(nType, cx, cy);
if (m_bInitialized)
MoveChilds();
}
/********************************************************************/
/* */
/* Function name : OnClose */
/* Description : Hide the dialogbox (instead of closing it) */
/* */
/********************************************************************/
void CApplicationDlg::OnClose()
{
if (AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
{
// Save main window position
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
AfxGetApp()->WriteProfileInt("Settings", "FrameStatus", wp.showCmd);
AfxGetApp()->WriteProfileInt("Settings", "FrameTop", wp.rcNormalPosition.top);
AfxGetApp()->WriteProfileInt("Settings", "FrameLeft", wp.rcNormalPosition.left);
AfxGetApp()->WriteProfileInt("Settings", "FrameBottom", wp.rcNormalPosition.bottom);
AfxGetApp()->WriteProfileInt("Settings", "FrameRight", wp.rcNormalPosition.right);
}
CDialog::OnClose();
}
/********************************************************************/
/* */
/* Function name : OnDestroy */
/* Description : Handle WM_DESTROY message */
/* */
/********************************************************************/
void CApplicationDlg::OnDestroy()
{
OnServerStop();
CDialogResize::OnDestroy();
}
/********************************************************************/
/* */
/* Function name : OnServerStart */
/* Description : Start FTP server -> start listening on port 21 */
/* */
/********************************************************************/
void CApplicationDlg::OnServerStart()
{
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);
theServer.SetStatisticsInterval(5000);
BOOL bBlockAll = AfxGetApp()->GetProfileInt("Settings", "BlockAll", 0);
theServer.SetSecurityMode(!bBlockAll);
if (theServer.Start())
{
m_wndStatusBar.SetPaneText(0, "FTP Server is online", TRUE);
SetOnlineLed(TRUE);
SetOfflineLed(FALSE);
}
}
/********************************************************************/
/* */
/* Function name : OnUpdateServerStart */
/* Description : Update 'Start' status */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!theServer.IsActive());
}
/********************************************************************/
/* */
/* Function name : OnServerStop */
/* Description : Stop FTP server */
/* */
/********************************************************************/
void CApplicationDlg::OnServerStop()
{
theServer.Stop();
m_wndStatusBar.SetPaneText(0, "FTP Server is offline", TRUE);
SetOnlineLed(FALSE);
SetOfflineLed(TRUE);
}
/********************************************************************/
/* */
/* Function name : OnUpdateServerStop */
/* Description : Update 'Stop' status */
/* */
/********************************************************************/
void CApplicationDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(theServer.IsActive());
}
/********************************************************************/
/* */
/* Function name : OnKickIdle */
/* Description : Make ON_UPDATE_COMMAND_UI work for this dialog. */
/* */
/********************************************************************/
LRESULT CApplicationDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
{
UpdateDialogControls(this, FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -