Click here to Skip to main content
13,148,260 members (58,054 online)
Click here to Skip to main content

Stats

248.7K views
5.2K downloads
93 bookmarked
Posted 16 Nov 1999

Address Book

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

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


#include "GfxInComboList.h"
#include "GfxInCombo.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGfxInComboList

CGfxInComboList::CGfxInComboList()
{
	pCombo = NULL;
	iLastSel = -1;
}

CGfxInComboList::~CGfxInComboList()
{
}


BEGIN_MESSAGE_MAP(CGfxInComboList, CListBox)
	//{{AFX_MSG_MAP(CGfxInComboList)
	ON_WM_KILLFOCUS()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGfxInComboList message handlers

void CGfxInComboList::OnKillFocus(CWnd* pNewWnd) 
{
	iLastSel = GetCurSel();
	if (iLastSel >= 0) GetText(iLastSel, csLastItem);

	CListBox::OnKillFocus(pNewWnd);

	if (pCombo && ::IsWindow(pCombo->GetSafeHwnd())) 
	{
		pCombo->SetFocus();
		pCombo->InvalidateButton();
	}
//	PostMessage(WM_CLOSE);
	DestroyWindow();
}

void CGfxInComboList::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CListBox::OnLButtonUp(nFlags, point);

	if (pCombo && ::IsWindow(pCombo->GetSafeHwnd())) 
	{
		pCombo->SetFocus();
		pCombo->InvalidateButton();
		if (GetSafeHwnd())
		{
			int iCurSel = GetCurSel();
			if (iCurSel >= 0)
			{
				CString csItem;
				GetText(iCurSel, csItem);
				char * ptx = csItem.LockBuffer();
				pCombo->SendMessage(WM_USER_SELENDOK, iCurSel, (LPARAM) ptx);
				csItem.UnlockBuffer();
			}
		}
		else
		{
			if (iLastSel >= 0) 	
			{
				char * ptx = csLastItem.LockBuffer();
				pCombo->SendMessage(WM_USER_SELENDOK, iLastSel, (LPARAM) ptx);
				csLastItem.UnlockBuffer();
			}
		}
	}

//	PostMessage(WM_CLOSE);
	DestroyWindow();
}

BOOL CGfxInComboList::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message == WM_KEYDOWN)
	{
		if (pMsg->wParam == VK_RETURN)
		{
			pCombo->SetFocus();
			pCombo->InvalidateButton();

			if (GetSafeHwnd())
			{
				int iCurSel = GetCurSel();
				if (iCurSel >= 0)
				{
					CString csItem;
					GetText(iCurSel, csItem);
					char * ptx = csItem.LockBuffer();
					pCombo->SendMessage(WM_USER_SELENDOK, iCurSel, (LPARAM) ptx);
					csItem.UnlockBuffer();
				}
			}
			else
			{
				if (iLastSel >= 0)
				{
					char * ptx = csLastItem.LockBuffer();
					pCombo->SendMessage(WM_USER_SELENDOK, iLastSel, (LPARAM) ptx);
					csLastItem.UnlockBuffer();
				}
			}
//			PostMessage(WM_CLOSE);
			DestroyWindow();
			return true;
		}
		if (pMsg->wParam == VK_ESCAPE)
		{
			pCombo->SetFocus();
			pCombo->InvalidateButton();
//			PostMessage(WM_CLOSE);
			DestroyWindow();
			return true;
		}
	}
	
	return CListBox::PreTranslateMessage(pMsg);
}

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

You may also be interested in...

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