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

Address Book

, 6 Aug 2000
Address Book application
// PersonalPage.cpp : implementation file
//

#include "stdafx.h"
#include "Address.h"
#include "PersonalPage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPersonalPage property page

IMPLEMENT_DYNCREATE(CPersonalPage, CPropertyPage)

CPersonalPage::CPersonalPage() : CPropertyPage(CPersonalPage::IDD)
{
	//{{AFX_DATA_INIT(CPersonalPage)
	m_strEMail = _T("");
	m_strFirstName = _T("");
	m_strLastName = _T("");
	m_strMiddleName = _T("");
	m_strName = _T("");
	m_strNickName = _T("");
	m_strNotes = _T("");
	//}}AFX_DATA_INIT
}

CPersonalPage::~CPersonalPage()
{
}

void CPersonalPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPersonalPage)
	DDX_Text(pDX, IDC_EMAIL, m_strEMail);
	DDX_Text(pDX, IDC_FIRSTNAME, m_strFirstName);
	DDX_Text(pDX, IDC_LASTNAME, m_strLastName);
	DDX_Text(pDX, IDC_MIDDLENAME, m_strMiddleName);
	DDX_CBString(pDX, IDC_NAME, m_strName);
	DDX_Text(pDX, IDC_NICKNAME, m_strNickName);
	DDX_Text(pDX, IDC_NOTES, m_strNotes);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPersonalPage, CPropertyPage)
	//{{AFX_MSG_MAP(CPersonalPage)
	ON_EN_CHANGE(IDC_FIRSTNAME, OnDisplayName)
	ON_CBN_EDITCHANGE(IDC_NAME, OnEditchangeName)
	ON_EN_CHANGE(IDC_MIDDLENAME, OnDisplayName)
	ON_EN_CHANGE(IDC_LASTNAME, OnDisplayName)
	ON_CBN_DROPDOWN(IDC_NAME, OnDropdownName)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPersonalPage message handlers

void CPersonalPage::OnDisplayName() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CPropertyPage::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_CHANGE flag ORed into the lParam mask.
	if (m_bIsNameModifiable) {
		CString strName;
		strName = DisplayName();
		SetDlgItemText(IDC_NAME, strName);
	}
}

CString CPersonalPage::DisplayName()
{
	CString strName;
	CString strText;

	GetDlgItemText(IDC_FIRSTNAME, strName);
	GetDlgItemText(IDC_MIDDLENAME, strText);
	if (!strText.IsEmpty())
		strName = strName + " " + strText;
	GetDlgItemText(IDC_LASTNAME, strText);
	if (!strText.IsEmpty())
		strName = strName + " " + strText;
	return strName;
}

BOOL CPersonalPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	m_bIsNameModifiable= false;

	if (m_strName.IsEmpty()) {
		m_bIsNameModifiable= true;
	}

	if (strncmp(m_strName, m_strFirstName, m_strFirstName.GetLength()) == NULL) {
		m_bIsNameModifiable = true;
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPersonalPage::OnEditchangeName() 
{
	m_bIsNameModifiable = false;
}

void CPersonalPage::OnDropdownName() 
{
	CComboBox* pctlName = (CComboBox*)GetDlgItem(IDC_NAME);
	CString strText;
	CString strNickName;

	GetDlgItemText(IDC_NICKNAME, strNickName);
	pctlName->GetWindowText(strText);
	pctlName->ResetContent();
	pctlName->SetWindowText(strText);
	if (m_bIsNameModifiable == false) {
		pctlName->AddString(strText);
	}
	pctlName->AddString(DisplayName());

	if (!strNickName.IsEmpty())
		pctlName->AddString(strNickName);

}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Xavier John
Software Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 7 Aug 2000
Article Copyright 1999 by Xavier John
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid