Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC

DTX - Database Toolbox For MFC Ver 1.8 (Freeware Version)

Rate me:
Please Sign up or sign in to vote.
3.88/5 (8 votes)
2 Apr 20024 min read 106.4K   3.6K   56  
DTX is a set of classes for editing and automatic read, write and display of datatabase fields, as well as 70+ ready to use classes
// dtxdbcombobox.cpp : implementation file
//

#include "stdafx.h"
#include "dtxdbcombobox.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDTXDBComboBox

CDTXDBComboBox::CDTXDBComboBox()
: CDTXEditBase(NULL)
{
	CDTXEditBase::SetOwner(this);
}

CDTXDBComboBox::~CDTXDBComboBox()
{
}

BEGIN_MESSAGE_MAP(CDTXDBComboBox, CDTXComboBox)
	//{{AFX_MSG_MAP(CDTXDBComboBox)
	ON_WM_SHOWWINDOW()
	ON_WM_KILLFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDTXDBComboBox message handlers

void CDTXDBComboBox::OnKillFocus(CWnd* pNewWnd) 
{
	if(GetSafeHwnd() && !m_EditField.IsEmpty())
	{
		DTXField* nField = GetField();
		if(nField && !nField->m_FieldName.IsEmpty())
		{
			if(nField->m_Type == dtxfInteger)
			{
				if(nField->intVal != GetCurSel())
				{
					CString nVal;
					nVal.Format(_T("%d"), GetCurSel());
					SetFieldValue(nVal);
				}
			}
			else
			{
				CString m_FieldText = DTXFieldToString(nField);
				CString m_WinText;
				GetWindowText(m_WinText);
				if(m_WinText != m_FieldText)
					SetFieldValue(m_WinText);
			}
		}
	}	
	CDTXComboBox::OnKillFocus(pNewWnd);
}

void CDTXDBComboBox::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	if(!m_EditField.IsEmpty())
	{
		DTXField* nField = GetField();
		if(nField && !nField->m_FieldName.IsEmpty())
			SetWindowText(DTXFieldToString(nField));
		else
			SetWindowText(_T(""));
		if(nField->m_Kind == dtxfkCalculated)
			EnableWindow(false);
	}
	else
	{
		SetWindowText(_T(""));
		EnableWindow(false);
	}
	CDTXComboBox::OnShowWindow(bShow, nStatus);
}

void CDTXDBComboBox::TableDataChange()
{
	if(GetSafeHwnd() && !m_EditField.IsEmpty())
	{
		DTXField* nField = GetField();
		if(nField && !nField->m_FieldName.IsEmpty())
		{
			if(nField->m_Type == dtxfInteger)
			{
				SetCurSel(nField->intVal);
			}
			else
			{
				CString m_FieldText = DTXFieldToString(nField);
				CString m_WinText;
				GetWindowText(m_WinText);
				if(m_WinText != m_FieldText)
				{
					SetWindowText(m_FieldText);
					Invalidate();
				}
			}
			if(nField->m_Kind == dtxfkCalculated)
				EnableWindow(false);
		}
	}
}

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


Written By
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions