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

Address Book

, 6 Aug 2000 CPOL
Address Book application
// AddressCtrl.cpp : implementation file
//
// AddressCtrl is derived from CGfxListCtrl.
// This is where event associated with each column is taken care of
// like double clicking on Phone No. Columns starts to dial the number. etc ...

#include "stdafx.h"
#include "Address.h"
#include "AddressCtrl.h"
#include "PersonPropSheet.h"
#include "tapi.h"
#include "hyperlink.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAddressCtrl

CAddressCtrl::CAddressCtrl()
{
}

CAddressCtrl::~CAddressCtrl()
{
}


BEGIN_MESSAGE_MAP(CAddressCtrl, CGfxListCtrl)
	//{{AFX_MSG_MAP(CAddressCtrl)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddressCtrl message handlers

void CAddressCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	if( GetFocus() != this ) SetFocus();
	int index, column;
	if ((index = HitTestEx(point, &column)) != -1)	{
		if (column > 0 )	{
			CString cs;
			CString strURL;
			CString strName;
			CString strComment;
			GetItemTextEx(index,column,cs);
			if (pManager) {
				column = pManager->FindColumnById(GetColumnIndex(column));
			}
			switch (column) {
			case ADDR_EMAIL: 
				// Double clicked on an e-mail address 
				// then start the e-mail program and
				// give it the e-mail address
				if (!cs.IsEmpty()) {
					strURL.Format("mailto:%s",(LPCTSTR)cs);
					CHyperLink::GotoURL(strURL,SW_SHOWNORMAL);
					break;
				}
			case ADDR_PERSONAL_WEB_PAGE:
			case ADDR_BUSINESS_WEB_PAGE:
				// Double clicked on a URL
				// start the default web browser and
				// give it the URL
				if (!cs.IsEmpty()) {
					if (strncmp((LPCTSTR) cs, "http://",7)==0)
						strURL=cs;
					else {
						strURL.Format("http://%s",(LPCTSTR)cs);
					}
					CHyperLink::GotoURL(strURL,SW_SHOWNORMAL);
					break;
				}
			case ADDR_HOME_PHONE:
			case ADDR_BUSINESS_PHONE:
				// Double clicked on a phone number
				// Request a call throught TAPI
				if (!cs.IsEmpty()) {
					if ( column == ADDR_BUSINESS_PHONE)
						strComment = "Business Number";
					else
						strComment = "Home Number";
					if (tapiRequestMakeCall(cs,"Address",m_pAddressDoc->m_PersonArray[index].m_strName, strComment)!=0) {
						AfxMessageBox("Unable to dial the number");
					}
					break;
				}
			default: 
				// If double clicked on any other column
				// Give the details of that person.
				DisplayProperties();
			}
		}
	}
	CGfxListCtrl::OnLButtonDblClk(nFlags, point);
}


// Display the details of the person in a property sheet.
void CAddressCtrl::DisplayProperties()
{
	CPersonPropSheet PersonPropSheet("Properties");
	CPersonalPage personalPage;
	CHomePage homePage;
	CBusinessPage businessPage;

	int i = GetNextItem(-1, LVNI_SELECTED);
	if (i < 0) return;

	CPerson &Person= m_pAddressDoc->m_PersonArray[ GetItemData(i) - 1];
    PersonPropSheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
	PersonPropSheet.AddPage(&personalPage);
	PersonPropSheet.AddPage(&homePage);
	PersonPropSheet.AddPage(&businessPage);

	personalPage.m_strFirstName =     Person.m_strFirstName;
	personalPage.m_strLastName=	      Person.m_strLastName;       
	personalPage.m_strMiddleName=	  Person.m_strMiddleName;
	personalPage.m_strName=		      Person.m_strName;
	personalPage.m_strNickName=		  Person.m_strNickName;
	personalPage.m_strEMail=		  Person.m_strEMail;
	personalPage.m_strNotes=          Person.m_strNotes;
	homePage.m_strHomeStreet=		  Person.m_strHomeStreet;
    homePage.m_strHomeCity=		      Person.m_strHomeCity;
	homePage.m_strHomePostalCode=	  Person.m_strHomePostalCode;
	homePage.m_strHomeState=		  Person.m_strHomeState;
	homePage.m_strHomeCountry=		  Person.m_strHomeCountry;
	homePage.m_strHomePhone=		  Person.m_strHomePhone;
	homePage.m_strHomeFax=		      Person.m_strHomeFax;
	homePage.m_strCarPhone=		      Person.m_strCarPhone;
	homePage.m_strPersonalWebPage=	  Person.m_strPersonalWebPage;
	businessPage.m_strBusinessStreet= Person.m_strBusinessStreet;
	businessPage.m_strBusinessCity=	  Person.m_strBusinessCity;
	businessPage.m_strBusinessPostalCode=Person.m_strBusinessPostalCode;
	businessPage.m_strBusinessState=  Person.m_strBusinessState;
	businessPage.m_strBusinessCountry=Person.m_strBusinessCountry;
	businessPage.m_strBusinessWebPage=Person.m_strBusinessWebPage;
	businessPage.m_strBusinessPhone=  Person.m_strBusinessPhone;
	businessPage.m_strBusinessFax=	  Person.m_strBusinessFax;
	businessPage.m_strPager=		  Person.m_strPager;
	businessPage.m_strCompany=		  Person.m_strCompany;
	businessPage.m_strJobTitle=		  Person.m_strJobTitle;
	businessPage.m_strDepartment=	  Person.m_strDepartment;
	businessPage.m_strOfficeLocation= Person.m_strOfficeLocation;

	if (PersonPropSheet.DoModal() == IDOK)	{
	    Person.m_strFirstName =     personalPage.m_strFirstName  ;
	    Person.m_strLastName  =     personalPage.m_strLastName;
	    Person.m_strMiddleName=     personalPage.m_strMiddleName;
	    Person.m_strName=           personalPage.m_strName;
	    Person.m_strNickName=       personalPage.m_strNickName;
	    Person.m_strEMail=          personalPage.m_strEMail;
		Person.m_strNotes=          personalPage.m_strNotes;
	    Person.m_strHomeStreet=     homePage.m_strHomeStreet;
	    Person.m_strHomeCity=       homePage.m_strHomeCity;
	    Person.m_strHomePostalCode= homePage.m_strHomePostalCode;
		Person.m_strHomeState=      homePage.m_strHomeState;
	    Person.m_strHomeCountry=    homePage.m_strHomeCountry;
		Person.m_strHomePhone=      homePage.m_strHomePhone;
		Person.m_strHomeFax=        homePage.m_strHomeFax;
		Person.m_strCarPhone=       homePage.m_strCarPhone;
		Person.m_strPersonalWebPage=homePage.m_strPersonalWebPage;
		Person.m_strBusinessStreet= businessPage.m_strBusinessStreet;
		Person.m_strBusinessCity=   businessPage.m_strBusinessCity;
		Person.m_strBusinessPostalCode=businessPage.m_strBusinessPostalCode;
		Person.m_strBusinessState=  businessPage.m_strBusinessState;
		Person.m_strBusinessCountry=businessPage.m_strBusinessCountry;
		Person.m_strBusinessWebPage=businessPage.m_strBusinessWebPage;
		Person.m_strBusinessPhone=  businessPage.m_strBusinessPhone;
		Person.m_strBusinessFax=    businessPage.m_strBusinessFax;
		Person.m_strPager=          businessPage.m_strPager;
		Person.m_strCompany=        businessPage.m_strCompany;
		Person.m_strJobTitle=       businessPage.m_strJobTitle;
		Person.m_strDepartment=     businessPage.m_strDepartment;
		Person.m_strOfficeLocation= businessPage.m_strOfficeLocation;
	    m_pAddressDoc->SetModifiedFlag();
		Invalidate();
	}
}


// Handle the Delete key so that when pressed, it deletes
// the current record after confirmation.
void CAddressCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar == VK_DELETE) {
		AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_DELETE, NULL);
	}
	
	CGfxListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

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 | Terms of Use | Mobile
Web02 | 2.8.141030.1 | Last Updated 7 Aug 2000
Article Copyright 1999 by Xavier John
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid