www.pudn.com > FTPServerSrc.rar > AddIPDlg.cpp
/****************************************************************/
/* */
/* AddIPDlg.cpp */
/* */
/* Implementation of the CAddIPDlg class. */
/* This class is a part of the FTP Server Application */
/* */
/* Programmed by Pablo van der Meer */
/* Copyright Pablo Software Solutions 2002 */
/* http://www.pablovandermeer.nl */
/* */
/* Last updated: 05 september 2002 */
/* */
/****************************************************************/
#include "stdafx.h"
#include "FTPServerApp.h"
#include "ftpserver.h"
#include "AddIPDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CAddIPDlg::CAddIPDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAddIPDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddIPDlg)
m_strPart1 = _T("");
m_strPart2 = _T("");
m_strPart3 = _T("");
m_strPart4 = _T("");
//}}AFX_DATA_INIT
}
void CAddIPDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddIPDlg)
DDX_Text(pDX, IDC_PART1, m_strPart1);
DDX_Text(pDX, IDC_PART2, m_strPart2);
DDX_Text(pDX, IDC_PART3, m_strPart3);
DDX_Text(pDX, IDC_PART4, m_strPart4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddIPDlg, CDialog)
//{{AFX_MSG_MAP(CAddIPDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/********************************************************************/
/* */
/* Function name : OnInitDialog */
/* Description : Initialize dialog */
/* */
/********************************************************************/
BOOL CAddIPDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (!m_strTitle.IsEmpty())
SetWindowText(m_strTitle);
((CEdit *)GetDlgItem(IDC_PART1))->SetLimitText(3);
((CEdit *)GetDlgItem(IDC_PART2))->SetLimitText(3);
((CEdit *)GetDlgItem(IDC_PART3))->SetLimitText(3);
((CEdit *)GetDlgItem(IDC_PART4))->SetLimitText(3);
AfxExtractSubString(m_strPart1, m_strIPaddress, 0, '.');
AfxExtractSubString(m_strPart2, m_strIPaddress, 1, '.');
AfxExtractSubString(m_strPart3, m_strIPaddress, 2, '.');
AfxExtractSubString(m_strPart4, m_strIPaddress, 3, '.');
UpdateData(FALSE);
CenterWindow();
return TRUE;
}
/********************************************************************/
/* */
/* Function name : PreTranslateMessage */
/* Description : Only accept numeric characters, decimal point */
/* separators, backspace and tabs. */
/* */
/********************************************************************/
BOOL CAddIPDlg::PreTranslateMessage(MSG* pMsg)
{
if ((pMsg->message == WM_CHAR && pMsg->hwnd == ::GetDlgItem(m_hWnd, IDC_PART1)) ||
(pMsg->message == WM_CHAR && pMsg->hwnd == ::GetDlgItem(m_hWnd, IDC_PART2)) ||
(pMsg->message == WM_CHAR && pMsg->hwnd == ::GetDlgItem(m_hWnd, IDC_PART3)) ||
(pMsg->message == WM_CHAR && pMsg->hwnd == ::GetDlgItem(m_hWnd, IDC_PART4)))
{
TCHAR nChar = (TCHAR)pMsg->wParam;
if ((IsCharAlphaNumeric(nChar) && !IsCharAlpha(nChar)) ||
nChar == '.' || nChar == '\b' || nChar == '\t' || nChar == '*')
{
return CDialog::PreTranslateMessage(pMsg);
}
else
{
// eat character
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CAddIPDlg::OnOK()
{
UpdateData();
m_strIPaddress.Format("%s.%s.%s.%s", m_strPart1, m_strPart2, m_strPart3, m_strPart4);
CDialog::OnOK();
}