Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / MFC

A Realtime Logfile Viewer

Rate me:
Please Sign up or sign in to vote.
4.98/5 (39 votes)
24 Feb 2004CPOL20 min read 233.3K   4.9K   151  
Part two of the logging service - the viewer
/*
 *	$Header :$
 *
 *	$History: MainFrm.cpp $
 * 
 * *****************  Version 3  *****************
 * User: Administrator Date: 12/02/03   Time: 9:20p
 * Updated in $/logger/logviewer
 * Added pretty icons, version resource, tooltip support, fixed various
 * bugs in continuation record support.
 * 
 * *****************  Version 2  *****************
 * User: Administrator Date: 11/27/03   Time: 3:17p
 * Updated in $/logger/logviewer
 * Revamped the LogUpdateThread to post messages to the main thread for
 * dealing with the listcontrol.
 * 
 * *****************  Version 1  *****************
 * User: Administrator Date: 11/25/03   Time: 5:20p
 * Created in $/logger/logviewer
 */
#include "stdafx.h"
#include "logviewer.h"

#include "LogData.h"

#include "MainFrm.h"
#include "logviewerDoc.h"
#include "logviewerView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(IDM_CLOSE_ALL, OnCloseAll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
	{
		TRACE0("Failed to create dialogbar\n");
		return -1;		// fail to create
	}

	if (!m_wndReBar.Create(this) || !m_wndReBar.AddBar(&m_wndToolBar) || !m_wndReBar.AddBar(&m_wndDlgBar))
	{
		TRACE0("Failed to create rebar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Remove this if you don't want tool tips
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);

	//	Load our bitmap images
	m_imageList.Create(IDB_IMAGES, 16, 0, RGB(0, 255, 255));
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if (!CMDIFrameWnd::PreCreateWindow(cs))
		return FALSE;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CMDIFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CMDIFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnCloseAll() 
{
	CMDIChildWnd *pChild = MDIGetActive();
	CSleeper	 sleeper;

	while (pChild != (CMDIChildWnd *) NULL)
	{
		ASSERT(pChild);
		ASSERT_KINDOF(CMDIChildWnd, pChild);

		pChild->SendMessage(WM_CLOSE);

		while (pChild == MDIGetActive())
			//	Give the window a chance to respond (it can't close until
			//	it's threads have exited).
			sleeper.Sleep(50);

		pChild = MDIGetActive();
	}
}

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)


Written By
United States United States
I've been programming for 35 years - started in machine language on the National Semiconductor SC/MP chip, moved via the 8080 to the Z80 - graduated through HP Rocky Mountain Basic and HPL - then to C and C++ and now C#.

I used (30 or so years ago when I worked for Hewlett Packard) to repair HP Oscilloscopes and Spectrum Analysers - for a while there I was the one repairing DC to daylight SpecAns in the Asia Pacific area.

Afterward I was the fourth team member added to the Australia Post EPOS project at Unisys Australia. We grew to become an A$400 million project. I wrote a few device drivers for the project under Microsoft OS/2 v 1.3 - did hardware qualification and was part of the rollout team dealing directly with the customer.

Born and bred in Melbourne Australia, now living in Scottsdale Arizona USA, became a US Citizen on September 29th, 2006.

I work for a medical insurance broker, learning how to create ASP.NET websites in VB.Net and C#. It's all good.

Oh, I'm also a Kentucky Colonel. http://www.kycolonels.org

Comments and Discussions