Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Complete FTP Server

, 30 May 2005
This article presents a fully functional implementation of a FTP server.
/****************************************************************/
/*																*/
/*  ConfigurationPage.cpp										*/
/*																*/
/*  Implementation of the CConfigurationPage class.				*/
/*	This class is a part of Quick 'n Easy FTP Server.			*/
/*																*/
/*  Programmed by Pablo van der Meer							*/
/*  Copyright Pablo Software Solutions 2005						*/
/*	http://www.pablosoftwaresolutions.com						*/
/*																*/
/*  Last updated: May 28, 2005									*/
/*																*/
/****************************************************************/


#include "stdafx.h"
#include "FTPServerApp.h"
#include "FTPServer.h"
#include "ConfigurationPage.h"
#include "ApplicationDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CFTPServer theServer;
extern CFTPServerApp theApp;

CConfigurationPage::CConfigurationPage() : CDialogResize(CConfigurationPage::IDD)
{
	//{{AFX_DATA_INIT(CConfigurationPage)
	m_nPort = 0;
	m_nMaxUsers = 0;
	m_strGoodbyeMessage = _T("");
	m_bStartInTray = FALSE;
	m_nTimeout = 0;
	m_strWelcomeMessage = _T("");
	m_bLaunchOnStartup = FALSE;
	m_bAutoActivate = FALSE;
	//}}AFX_DATA_INIT
	m_bModified = FALSE;
}

CConfigurationPage::~CConfigurationPage()
{
}

void CConfigurationPage::DoDataExchange(CDataExchange* pDX)
{
	CDialogResize::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConfigurationPage)
	DDX_Text(pDX, IDC_PORT, m_nPort);
	DDX_Text(pDX, IDC_MAX_USERS, m_nMaxUsers);
	DDX_Text(pDX, IDC_GOODBYE_MSG, m_strGoodbyeMessage);
	DDX_Check(pDX, IDC_START_IN_TRAY, m_bStartInTray);
	DDX_Text(pDX, IDC_TIMEOUT, m_nTimeout);
	DDX_Text(pDX, IDC_WELCOME_MSG, m_strWelcomeMessage);
	DDX_Check(pDX, IDC_LAUNCH_ON_STARTUP, m_bLaunchOnStartup);
	DDX_Check(pDX, IDC_AUTOACTIVATE, m_bAutoActivate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigurationPage, CDialogResize)
	//{{AFX_MSG_MAP(CConfigurationPage)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_LAUNCH_ON_STARTUP, OnLaunchOnStartup)
	ON_UPDATE_COMMAND_UI(IDC_APPLY, OnUpdateApply)
	ON_EN_CHANGE(IDC_PORT, OnSomethingChanged)
	ON_BN_CLICKED(IDC_APPLY, OnApply)
	ON_EN_CHANGE(IDC_MAX_USERS, OnSomethingChanged)
	ON_EN_CHANGE(IDC_TIMEOUT, OnSomethingChanged)
	ON_EN_CHANGE(IDC_WELCOME_MSG, OnSomethingChanged)
	ON_EN_CHANGE(IDC_GOODBYE_MSG, OnSomethingChanged)
	ON_BN_CLICKED(IDC_START_IN_TRAY, OnSomethingChanged)
	ON_BN_CLICKED(IDC_AUTOACTIVATE, OnSomethingChanged)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BEGIN_DLGRESIZE_MAP(CConfigurationPage)
	DLGRESIZE_CONTROL(IDC_WELCOME_MSG, DLSZ_SIZE_X)
	DLGRESIZE_CONTROL(IDC_GOODBYE_MSG, DLSZ_SIZE_X)
	DLGRESIZE_CONTROL(IDC_APPLY, DLSZ_MOVE_X | DLSZ_MOVE_Y)
END_DLGRESIZE_MAP()


/********************************************************************/
/*																	*/
/* Function name : OnInitDialog										*/		
/* Description   : Called by the framework in response to the		*/
/*				   WM_INITDIALOG message.							*/
/*																	*/
/********************************************************************/
BOOL CConfigurationPage::OnInitDialog() 
{
	CDialogResize::OnInitDialog();
	
	InitResizing(FALSE, FALSE, WS_CLIPCHILDREN);
	UpdateDialogControls(this, FALSE);
	return TRUE;
}


/********************************************************************/
/*																	*/
/* Function name : OnDestroy										*/		
/* Description   : Called by the framework in response to the		*/
/*				   WM_DESTROY message.								*/
/*																	*/
/********************************************************************/
void CConfigurationPage::OnDestroy() 
{
	UpdateData();

	// save settings
	AfxGetApp()->WriteProfileInt("Settings", "Port", m_nPort);
	AfxGetApp()->WriteProfileInt("Settings", "MaxUsers", m_nMaxUsers);
	AfxGetApp()->WriteProfileInt("Settings", "Timeout", m_nTimeout);
	AfxGetApp()->WriteProfileString("Settings", "WelcomeMsg", m_strWelcomeMessage); 
	AfxGetApp()->WriteProfileString("Settings", "GoodbyeMsg", m_strGoodbyeMessage); 
	AfxGetApp()->WriteProfileInt("Settings", "LaunchOnStartup", m_bLaunchOnStartup);
	AfxGetApp()->WriteProfileInt("Settings", "StartInTray", m_bStartInTray);
	AfxGetApp()->WriteProfileInt("Settings", "AutoActivate", m_bAutoActivate);
	CDialogResize::OnDestroy();
}


/********************************************************************/
/*																	*/
/* Function name : OnLaunchOnStartup								*/		
/* Description   : Launch application on startup?					*/
/*																	*/
/********************************************************************/
void CConfigurationPage::OnLaunchOnStartup() 
{
	UpdateData(TRUE);
	
	if (m_bLaunchOnStartup)
	{
		char szModuleFilename[MAX_PATH];
		
		// Get application's full path.
		::GetModuleFileName(NULL, szModuleFilename, MAX_PATH);
		// create shortcut
		CreateStartMenuShortcut(szModuleFilename, "Quick 'n Easy FTP Server");
	}
	else
	{
		// remove shortcut
		RemoveStartMenuShortcut("Quick 'n Easy FTP Server");
	}	
	OnSomethingChanged();
}


/********************************************************************/
/*																	*/
/* Function name : OnApply											*/		
/* Description   : Update FTP server settings.						*/	
/*																	*/
/********************************************************************/
void CConfigurationPage::OnApply() 
{
	m_bModified = FALSE;
	UpdateDialogControls(this, FALSE);	
	
	AfxGetMainWnd()->SendMessage(WM_COMMAND, IDC_APPLY);	

	// save settings
	AfxGetApp()->WriteProfileInt("Settings", "Port", m_nPort);
	AfxGetApp()->WriteProfileInt("Settings", "MaxUsers", m_nMaxUsers);
	AfxGetApp()->WriteProfileInt("Settings", "Timeout", m_nTimeout);
	AfxGetApp()->WriteProfileString("Settings", "WelcomeMsg", m_strWelcomeMessage); 
	AfxGetApp()->WriteProfileString("Settings", "GoodbyeMsg", m_strGoodbyeMessage); 
	AfxGetApp()->WriteProfileInt("Settings", "LaunchOnStartup", m_bLaunchOnStartup);
	AfxGetApp()->WriteProfileInt("Settings", "StartInTray", m_bStartInTray);
	AfxGetApp()->WriteProfileInt("Settings", "AutoActivate", m_bAutoActivate);
}


/********************************************************************/
/*																	*/
/* Function name : OnUpdateApply									*/		
/* Description   : Update button state.								*/	
/*																	*/
/********************************************************************/
void CConfigurationPage::OnUpdateApply(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_bModified);			
}


/********************************************************************/
/*																	*/
/* Function name : OnSomethingChanged								*/
/* Description   : Something has changed...							*/
/*																	*/
/********************************************************************/
void CConfigurationPage::OnSomethingChanged() 
{
	m_bModified = TRUE;	
	UpdateDialogControls(this, FALSE);	
}


void CConfigurationPage::OnOK() 
{
//	CDialogResize::OnOK();
}

void CConfigurationPage::OnCancel() 
{
//	CDialogResize::OnCancel();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Pablo van der Meer
Web Developer
Netherlands Netherlands
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 30 May 2005
Article Copyright 2002 by Pablo van der Meer
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid