Click here to Skip to main content
12,631,574 members (33,676 online)
Click here to Skip to main content

Stats

30.1K views
1.2K downloads
23 bookmarked
Posted

Creation and memory mapping existing DBF files as alternative of data serialization during work with modified CListCtrl classes in virtual mode on dialogs of MDI application

, 22 Jul 2009 CPOL
The demonstration of reading, writing and creation of standard DBF files with random access in memory instead of serialization of typical MFC application for descendants of CListCtrl classes in Virtual Mode.
ModifiedListCtrl04
Bin
Main.exe
Dbf
First.dbf
Second.dbf
Third.dbf
ListCtrlEx
Main.aps
Main.clw
Main.dsp
Main.dsw
Main.ncb
Main.opt
Main.plg
res
Main.ico
MainDoc.ico
Toolbar.bmp
Toolbar2.bmp
Toolbar2_.bmp
////////////////////////////////////////////////////////////////////////////
// HeaderCtrlEx.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "HeaderCtrlEx.h"

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

/////////////////////////////////////////////////////////////////////////////
// MESSAGE MAP
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CHeaderCtrlEx, CHeaderCtrl)
	//{{AFX_MSG_MAP(CChildFrame)
	ON_MESSAGE(HDM_LAYOUT, OnLayout)
	//ON_MESSAGE(HDM_GETITEM, OnGetItem)
	//ON_NOTIFY_REFLECT(HDN_ENDTRACK, OnEndTrack)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHeaderCtrlEx
/////////////////////////////////////////////////////////////////////////////
CHeaderCtrlEx::CHeaderCtrlEx() {
	//*** Main Application Pointer
	CMainApp *pMainApp = reinterpret_cast<CMainApp *>(AfxGetApp());

	if(!pMainApp) {
		_M("CHeaderCtrlEx: Empty object of the CMainApp class!");
		return;
	}

	//*** Table Id
	ETABLE eTable = pMainApp->m_eTable;

	//*** The Meta Table Structure
	m_MetaTable = pMainApp->m_aMetaTable[eTable];

	//*** The width of defect of displacement of the table header to the left
	m_nHdrWidthDefect = 1;

	//*** The height of defect of the table header
	m_nHdrHeightDefect = 2;
}  // CHeaderCtrlEx

/////////////////////////////////////////////////////////////////////////////
// ~CHeaderCtrlEx
/////////////////////////////////////////////////////////////////////////////
CHeaderCtrlEx::~CHeaderCtrlEx() {
}  // ~CHeaderCtrlEx

///////////////////////////////////////////////////////////////////////////////
// OnLayout
///////////////////////////////////////////////////////////////////////////////
LRESULT CHeaderCtrlEx::OnLayout(WPARAM, LPARAM lParam) {
	LPHDLAYOUT pHL = reinterpret_cast<LPHDLAYOUT>(lParam);
	
	//*** The table list rectangle
	RECT *pRect = pHL->prc;

	//*** The table header rectangle
	WINDOWPOS *pWPos = pHL->pwpos;

	//*** Here's equivalent code for the code which follows after
	/*
	pWPos->hwndInsertAfter = NULL;

	//*** Moves the table header to the righ
	pWPos->x = pRect->left + m_nHdrWidthDefect;
	pWPos->y = pRect->top;
	pWPos->cx = pRect->right - pRect->left;

	//*** New table header height
	pWPos->cy = m_nHdrHeight + m_nHdrHeightDefect;

	pWPos->flags = SWP_NOACTIVATE|SWP_NOZORDER;

	//*** Decreases the table list height on the table header height
	pRect->top += m_nHdrHeight;

	return TRUE;
	*/
	//***
	
	//*** Sends HDM_LAYOUT message to the base class
	int nRet = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);

	//*** Moves the table header to the right
	pWPos->x += m_nHdrWidthDefect;

	// Table header height
	UINT nHdrHeight = m_MetaTable.nHdrHeight;

	//*** New table header height
	pWPos->cy = nHdrHeight + m_nHdrHeightDefect;

	//*** Decreases the table list height on the table header height
	pRect->top = nHdrHeight;

	return nRet;
}  // OnLayout
/*
/////////////////////////////////////////////////////////////////////////////
// OnGetItem
/////////////////////////////////////////////////////////////////////////////
BOOL CHeaderCtrlEx::OnGetItem(WPARAM wParam, LPARAM lParam) {
	//*** Index of the item for which data is retrieved
	//int nIndex = (int) wParam;

	//*** Pointer to an HDITEM structure. When the message is sent, the mask 
	// member indicates the type of data requested. When the message returns, 
	// the other members receive the requested data. If the mask member specifies 
	// zero, the message returns TRUE, but copies no data to the structure. 
	//HD_ITEM *pHDI = (HD_ITEM *) lParam;

	return TRUE;
}
*/
/*
/////////////////////////////////////////////////////////////////////////////
// OnEndTrack
/////////////////////////////////////////////////////////////////////////////
void CHeaderCtrlEx::OnEndTrack(NMHDR *pNMHDR, LRESULT *pResult) {
	// HD_NOTIFY *pHdn = (HD_NOTIFY *) pNMHDR;
	// NMHEADER *pHdr = (NMHEADER *) pNMHDR

	*pResult = 0;
}  // OnEndTrack
*/
/////////////////////////////////////////////////////////////////////////////
// DrawItem
/////////////////////////////////////////////////////////////////////////////
void CHeaderCtrlEx::DrawItem(LPDRAWITEMSTRUCT pDIS) {
	HDITEM hDI;
	TCHAR szBuf[MAXITEMTEXT];

	hDI.mask = HDI_TEXT;
	hDI.pszText = szBuf;
	hDI.cchTextMax = MAXITEMTEXT;

	GetItem(pDIS->itemID, &hDI);

	CDC *pDC;
	HDC hDC = pDIS->hDC;  // Handle to device context
	pDC = CDC::FromHandle(hDC);

	//*** Selects necessary font
	pDC->SelectObject(m_MetaTable.pHdrFont);
	//pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));

	int x = 0;  // x-coordinate of reference point
	int y = 0;  // y-coordinate of reference point
	UINT nOptions = 0;  // Text-output options ETO_CLIPPED|ETO_OPAQUE
	RECT *pIRect = NULL;  // Optional clipping and/or opaquing rectangle

	pIRect = &pDIS->rcItem;
	SIZE Size = {0};

	//*** Gets the header cell sizes
	if(!GetTextExtentPoint(hDC, szBuf, wcslen(szBuf), &Size)) {
		_M("Failed to call GetTextExtentPoint for table header!");
		return;
	}

	//*** x-coordinate of reference point
	x = (pIRect->left + pIRect->right - Size.cx)/2 - 1;
	x = (x < pIRect->left + 2) ? pIRect->left + 2 : x;

	//*** y-coordinate of reference point
	y = (pIRect->bottom - pIRect->top - Size.cy)/2 - 1;
	
	//*** Specifies that text is clipped to the rectangle pIRect
	nOptions |= ETO_CLIPPED;

	//*** Specifies that the current background color fills the rectangle pIRect
	nOptions |= ETO_OPAQUE;

	//*** Decreases the text border to the right
	pIRect->right -= 4;

	//*** Writes the text in the (x, y) - coordinates
	pDC->ExtTextOut(x, y, nOptions, pIRect, szBuf, wcslen(szBuf), NULL);

	//*** Restores system font
	pDC->SelectStockObject(SYSTEM_FONT);

	//*** Shows the vertical scroll bar always
	GetParent()->ShowScrollBar(SB_VERT);
}  // DrawItem

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

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

Emery Emerald
Software Developer
Ukraine Ukraine
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 22 Jul 2009
Article Copyright 2009 by Emery Emerald
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid