Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / MFC

A Logging Listbox Control

Rate me:
Please Sign up or sign in to vote.
4.80/5 (9 votes)
16 May 2000 176.6K   3K   85  
Learn how to use printf-like functionality to debug your GUI applications.
// LogFrame.cpp : implementation file
//

#include "stdafx.h"
#include "log.h"
#include "LogFrame.h"
#include "TraceEvent.h"
#include "Trace.h"
#include "LogWindowView.h" // *** JMN
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLogFrame

IMPLEMENT_DYNCREATE(CLogFrame, CMDIChildWnd)

CLogFrame::CLogFrame()
{
}

CLogFrame::~CLogFrame()
{
}


BEGIN_MESSAGE_MAP(CLogFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(CLogFrame)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogFrame message handlers

/****************************************************************************
*                            CLogFrame::AddString
* Inputs:
*       TraceEvent * event: Event to add to logging window
* Result: int
*       Position at which it was added
* Effect: 
*       Adds the event to the trace log
****************************************************************************/

int CLogFrame::AddString(TraceEvent * event)                         // *** JMN
    {                                                                // *** JMN
     CLogWindowView * child = (CLogWindowView *)GetWindow(GW_CHILD); // *** JMN
     return child->AddString(event);                                 // *** JMN
    } // CLogFrame::AddString                                        // *** JMN

/****************************************************************************
*                              CLogFrame::OnSize
* Inputs:
*       UINT nType: Sizing type
*	int cx: Width
*	int cy: Height
* Result: void
*       
* Effect: 
*       Computes the new client area and resizes the child window, the
*       CFormView, to fit in that area.
****************************************************************************/

void CLogFrame::OnSize(UINT nType, int cx, int cy)                   // *** JMN
{                                                                    // *** JMN
	CMDIChildWnd::OnSize(nType, cx, cy);                         // *** JMN
	                                                             // *** JMN
	CWnd * child = GetWindow(GW_CHILD);                          // *** JMN
	CRect r;                                                     // *** JMN
	GetClientRect(&r);                                           // *** JMN
	child->SetWindowPos(NULL, 0, 0, r.Width(), r.Height(),       // *** JMN
			    SWP_NOMOVE | SWP_NOZORDER);              // *** JMN
}                                                                    // *** JMN

/****************************************************************************
*                         CLogFrame::PreCreateWindow
* Inputs:
*       CREATESTRUCT & cs: Creation structure
* Result: BOOL
*       Result of CMDIChildWnd::PreCreateWindow
* Effect: 
*       Removes the automatic-titling flag from the styles so the
*	title remains fixed (it is not associated with any file)
****************************************************************************/

BOOL CLogFrame::PreCreateWindow(CREATESTRUCT& cs)                    // *** JMN
{                                                                    // *** JMN
    cs.style &= ~FWS_ADDTOTITLE;                                     // *** JMN
	                                                             // *** JMN
	return CMDIChildWnd::PreCreateWindow(cs);                    // *** JMN
}                                                                    // *** JMN


/****************************************************************************
*                             CLogger::AddString
* Inputs:
*       TraceEvent * event
* Result: int
*       Position of insertio
* Effect: 
*       Adds the element to the list. If the list does not exist, delets the
*	event.
****************************************************************************/

int CLogger::AddString(TraceEvent * event)
    {
     if(IsValid())
	return frame->AddString(event);
     else
	{ /* no window */
	 delete event;
	 return LB_ERR;
	} /* no window */
    } // CLogger::AddString

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
Retired
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

Comments and Discussions