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

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
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.zip
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
/////////////////////////////////////////////////////////////////////////////
// MainTabs.cpp : implementation of the CMainTabs class
/////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "Resource.h"
#include "MainTabs.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainTabs
/////////////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNCREATE(CMainTabs, CTabCtrl)

BEGIN_MESSAGE_MAP(CMainTabs, CTabCtrl)
	//{{AFX_MSG_MAP(CMainTabs)
  ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelChange)
  ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMainTabs construction
/////////////////////////////////////////////////////////////////////////////
CMainTabs::CMainTabs() {
	//*** Height of tabs
	m_nHeight = 21;  // See CMainApp::m_nClientCtrlsHeight

	//*** Tab vertical offset
	m_nVertOffset = 2;

	//*** Tab horizontal offset
	m_nHorzOffset = 2;

	//*** Handle of Client
	m_hClient = NULL;
}  // CMainTabs

/////////////////////////////////////////////////////////////////////////////
// CMainTabs destruction
/////////////////////////////////////////////////////////////////////////////
CMainTabs::~CMainTabs() {
}  // ~CMainTabs

/////////////////////////////////////////////////////////////////////////////
// Create
/////////////////////////////////////////////////////////////////////////////
void CMainTabs::Create(CFrameWnd *pMainFrame) {
  //*** Creates the CTabCtrl object
	CTabCtrl::Create(
			TCS_BUTTONS,
			CRect(0, 0, 0, 0),
			pMainFrame,
			ID_MAINTABS
	);
  
	//*** Changes of tab sizes
	SetItemSize(CSize(0, m_nHeight));

	//*** Changes of tab extension style
	ModifyStyleEx(0, WS_EX_OVERLAPPEDWINDOW);

  //*** Sets current tab font
	SendMessage(WM_SETFONT, WPARAM(GetStockObject(DEFAULT_GUI_FONT)), 0);

  //*** Seeks m_hClient for using in Update function
	m_hClient = ::GetTopWindow(*pMainFrame);

	//*** Creates the status bar
	if(!m_hClient) {
		_M("CMainTabs: Failed to get a client window!");
	}
}  // Create

/////////////////////////////////////////////////////////////////////////////
// OnSelChange
/////////////////////////////////////////////////////////////////////////////
void CMainTabs::OnSelChange(NMHDR *pNMHDR, LRESULT *pResult) {
  TCITEM Item;

  Item.mask = TCIF_PARAM;

  GetItem(GetCurSel(), &Item);

	HWND hWnd = HWND(Item.lParam);

  ::BringWindowToTop(hWnd);

  *pResult = 0;
}  // OnSelChange

/////////////////////////////////////////////////////////////////////////////
// OnSizeParent
/////////////////////////////////////////////////////////////////////////////
afx_msg LRESULT CMainTabs::OnSizeParent(WPARAM, LPARAM lParam) {
  AFX_SIZEPARENTPARAMS *pParams = reinterpret_cast<AFX_SIZEPARENTPARAMS *>(lParam);

	//*** Client rectangle
  RECT *pCR = &pParams->rect;
	
	//*** Tab width
  UINT nWidth = pCR->right - pCR->left;

  pCR->left -= m_nHorzOffset;
	pCR->bottom -= m_nHeight;

  MoveWindow(
			pCR->left,
			pCR->bottom - m_nVertOffset,
			nWidth + m_nHorzOffset,
			m_nHeight + m_nVertOffset
	);

  ShowWindow(SW_NORMAL);
  
  return 0;
}  // OnSizeParent

/////////////////////////////////////////////////////////////////////////////
// Update
/////////////////////////////////////////////////////////////////////////////
void CMainTabs::Update() {
  SetRedraw(false);

  //*** Get active view window (actually the frame of the view)
	HWND active = ::GetTopWindow(m_hClient);

  typedef std::vector<HWND> TWndVec;
  typedef TWndVec::iterator TWndIter;

  //*** Put all child windows in a list (actually a vector)
	TWndVec vChild;
  
	for(HWND child = active; child; child = ::GetNextWindow(child, GW_HWNDNEXT)) {
    vChild.push_back(child);
  }

  TCHAR text[MAXITEMTEXT];
  TCITEM item;

  item.pszText = text;
  
	for(int i = GetItemCount(); i--;) {  // For each tab
    item.mask = TCIF_PARAM;
    GetItem(i, &item);

    TWndIter it = std::find(vChild.begin(), vChild.end(), HWND(item.lParam));

    if(it == vChild.end()) {  // Associatete view does no longer exist, so delete the tab
      DeleteItem(i);
    } else {  // Update the tab's text, image and selection state
      item.mask = TCIF_TEXT;
      ::GetWindowText(*it, text, MAXITEMTEXT);

			SetItem(i, &item);
      
			if(*it == active)
					SetCurSel(i);  // Associated view is active => make it the current selection
      
			vChild.erase(it);  // Remove view from list
    }
  }

  //*** All remaining views in vChild have to be added as new tabs
  i = GetItemCount();

  for(TWndIter it = vChild.begin(), end = vChild.end(); it != end; ++it) {
    item.mask = TCIF_TEXT|TCIF_PARAM|TCIF_IMAGE;
    ::GetWindowText(*it, text, MAXITEMTEXT);
  
		item.iImage = i;
    item.lParam = LPARAM(*it);
    InsertItem(i, &item);
    
		if(*it == active)
				SetCurSel(i);
    
		++i;
  }

  static_cast<CMDIFrameWnd *>(FromHandlePermanent(::GetParent(m_hClient)))->RecalcLayout();

  RedrawWindow(NULL, NULL, RDW_FRAME|RDW_INVALIDATE|RDW_ERASE);

  SetRedraw(true);
}  // Update

/////////////////////////////////////////////////////////////////////////////
// CMainTabs diagnostics
/////////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
	/////////////////////////////////////////////////////////////////////////////
	// AssertValid
	/////////////////////////////////////////////////////////////////////////////
	void CMainTabs::AssertValid() const {
		CTabCtrl::AssertValid();
	}  // AssertValid

	/////////////////////////////////////////////////////////////////////////////
	// Dump
	/////////////////////////////////////////////////////////////////////////////
	void CMainTabs::Dump(CDumpContext &dc) const {
		CTabCtrl::Dump(dc);
	}  // Dump
#endif //_DEBUG

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

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

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