www.gusucode.com > 基于VC编程界面编程高级应用技术源码程序 > VC界面编程高级应用技术/code/1/DevDemo/OutputBar.cpp

    // OutputBar.cpp : implementation file
//
/////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "Resource.h"
#include "OutputBar.h"

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

/////////////////////////////////////////////////////////////////////////////
// COutputBar

COutputBar::COutputBar()
{
	NONCLIENTMETRICS ncm;
	memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
	ncm.cbSize = sizeof(NONCLIENTMETRICS);
	VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
		sizeof(NONCLIENTMETRICS), &ncm, 0));
	_tcscpy( ncm.lfMessageFont.lfFaceName, _T("Courier"));
	m_Font.CreateFontIndirect(&ncm.lfMessageFont);
}

COutputBar::~COutputBar()
{
	// TODO: add destruction code here.
}

IMPLEMENT_DYNAMIC(COutputBar, CCJControlBar)

BEGIN_MESSAGE_MAP(COutputBar, CCJControlBar)
	//{{AFX_MSG_MAP(COutputBar)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static CString strBuild[] =
{
	_T("--------------------Configuration: TestApp - Win32 Debug--------------------"),
	_T("Compiling..."),
	_T("TestAppView.cpp"),
	_T("Linking..."),
	_T(""),
	_T("TestApp.exe - 0 error(s), 0 warning(s)"),
};

static CString strDebug[] =
{
	_T("Loaded 'E:\\WINNT\\System32\\ntdll.dll', no matching symbolic information found."),
	_T("Loaded symbols for 'E:\\WINNT\\system32\\MFC42D.DLL'"),
	_T("Loaded symbols for 'E:\\WINNT\\system32\\MSVCRTD.DLL'"),
	_T("Loaded 'E:\\WINNT\\system32\\KERNEL32.DLL', no matching symbolic information found."),
	_T("Loaded 'E:\\WINNT\\system32\\GDI32.DLL', no matching symbolic information found."),
	_T("Loaded 'E:\\WINNT\\system32\\USER32.DLL', no matching symbolic information found."),
	_T("Loaded 'E:\\WINNT\\system32\\ADVAPI32.DLL', no matching symbolic information found."),
	_T("Loaded 'E:\\WINNT\\system32\\RPCRT4.DLL', no matching symbolic information found."),
	_T("Loaded symbols for 'E:\\WINNT\\system32\\MFCO42D.DLL'")
};

static CString strTabs[] =
{
	"Build",
	"Debug",
	"Find in Files 1",
	"Find in Files 2"
};

/////////////////////////////////////////////////////////////////////////////
// COutputBar message handlers

int COutputBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CCJControlBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_FlatTabCtrl.Create(NULL, "", WS_VISIBLE | WS_CHILD | FTS_HASARROWS | FTS_BOTTOM,
		CRect(10,10,200,25), this, IDC_FLATTAB))
	{
		TRACE0(_T("Unable to create flat tab control bar\n"));
		return -1;
	}
	
	int nItemCount = sizeof(strTabs)/sizeof(strTabs[0]);
	for( int iItem = 0; iItem < nItemCount; ++iItem)
	{
		m_FlatTabCtrl.InsertItem(iItem, strTabs[iItem]);
	}

	DWORD dwStyle = WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | 
		WS_VSCROLL | WS_TABSTOP;

	int nListCount = sizeof(m_OutputList)/sizeof(m_OutputList[0]);
	for( int iList = 0; iList < nListCount; ++iList)
	{
		if (!m_OutputList[iList].Create( dwStyle, CRect(0,0,0,0), this,
			IDC_OUTPUT_LIST+iList ))
		{
			TRACE(_T("Failed to create output window.\n"));
			return -1;
		}
		m_OutputList[iList].SetFont( &m_Font );
	}
	
	int nBuildCount = sizeof(strBuild)/sizeof(strBuild[0]);
	for( int i = 0; i < nBuildCount; ++i)
	{
		m_OutputList[0].AddString(strBuild[i]);
	}

	int nDebugCount = sizeof(strDebug)/sizeof(strDebug[0]);
	for( i = 0; i < nDebugCount; ++i)
	{
		m_OutputList[1].AddString(strDebug[i]);
	}

	SelectTabView(0);
	return 0;
}

BOOL COutputBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
	if(IDC_FLATTAB == (UINT)wParam)
	{
		NMHDR* pNMHDR = (NMHDR*)lParam;

		switch(pNMHDR->code)
		{
		case TCN_SELCHANGING:
			break;
		case TCN_SELCHANGE:
			SelectTabView(m_FlatTabCtrl.GetCurSel());
			break;
		}
	}
	
	return CCJControlBar::OnNotify(wParam, lParam, pResult);
}

void COutputBar::SelectTabView(int nTab)
{
	int nListCount = sizeof(m_OutputList)/sizeof(m_OutputList[0]);
	for( int iList = 0; iList < nListCount; ++iList) {
		m_OutputList[iList].ShowWindow(SW_HIDE);
	}

	m_OutputList[nTab].ShowWindow(SW_SHOW);
}

void COutputBar::OnSize(UINT nType, int cx, int cy) 
{
	CCJControlBar::OnSize(nType, cx, cy);
	
	if(m_FlatTabCtrl.GetSafeHwnd())
	{
		CRect rc;
		GetChildRect(rc);
		rc.DeflateRect(1,1);

		int nListCount = sizeof(m_OutputList)/sizeof(m_OutputList[0]);
		for( int iList = 0; iList < nListCount; ++iList) {
			m_OutputList[iList].MoveWindow(rc.left, rc.top,
				rc.Width(), rc.bottom-(IsFloating()?18:19));
		}

		m_FlatTabCtrl.MoveWindow(rc.left, rc.bottom-15, rc.Width(), 15);
	}
}

void COutputBar::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect rc;
//	m_iAuxImage = (UINT)-1;
	GetClientRect(&rc);
	CRect rect;
	GetChildRect(rect);
	DrawBorders(&dc,rc);
	dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DDKSHADOW),
		::GetSysColor(COLOR_3DDKSHADOW));
}