www.pudn.com > mischat.rar > OutputBar.cpp


// outputbar.cpp : implementation of the COutputBar class 
// 
 
#include "stdafx.h" 
#include "mischat.h" 
#include "outputbar.h" 
#include "mischatDoc.h" 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
const int nBorderSize = 1; 
extern CmischatDoc* pDoc; 
extern CMainFrame* pMainWnd; 
 
///////////////////////////////////////////////////////////////////////////// 
// COutputBar 
 
BEGIN_MESSAGE_MAP(COutputBar, CBCGPDockingControlBar) 
	//{{AFX_MSG_MAP(COutputBar) 
	ON_WM_CREATE() 
	ON_WM_SIZE() 
	ON_WM_PAINT() 
	ON_WM_SETFOCUS() 
	ON_COMMAND(ID_OUTPUT_CLEAR, OnOutputClear) 
	ON_COMMAND(ID_OUTPUT_OPEN, OnOutputOpen) 
	ON_COMMAND(ID_OUTPUT_SAVE, OnOutputSave) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// COutputBar construction/destruction 
 
COutputBar::COutputBar() 
{ 
	// TODO: add one-time construction code here 
} 
 
COutputBar::~COutputBar() 
{ 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// COutputBar message handlers 
 
int COutputBar::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CBCGPDockingControlBar::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	CRect rectDummy; 
	rectDummy.SetRectEmpty (); 
 
	// Create list window. 
	// TODO: create your own window here: 
	const DWORD dwViewStyle =	 
		LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL|LVS_REPORT; 
	 
	if (!m_wndList.Create (dwViewStyle, rectDummy, this, 1)) 
	{ 
		TRACE0("Failed to create output view\n"); 
		return -1;      // fail to create 
	} 
	m_wndList.SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_LABELTIP);	 
	m_wndList.InsertColumn (0,_T("序号"),LVCFMT_LEFT,60); 
	m_wndList.InsertColumn (1,_T("信息"),LVCFMT_LEFT,800); 
	imageList.Create(IDB_OUTPUTBARINFO,16,1,RGB(0,128,128)); 
	m_wndList.SetImageList(&imageList,LVSIL_SMALL); 
 
	m_wndToolBar.Create (this, dwDefaultToolbarStyle, IDR_OUTPUT_TOOLBAR); 
	m_wndToolBar.LoadToolBar (IDR_OUTPUT_TOOLBAR, 0, 0, TRUE /* Is locked */); 
 
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | 
		CBRS_TOOLTIPS | CBRS_FLYBY); 
		 
	m_wndToolBar.SetBarStyle ( 
		m_wndToolBar.GetBarStyle () &  
			~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT)); 
 
	m_wndToolBar.SetOwner (this); 
 
	// All commands will be routed via this control , not via the parent frame: 
	m_wndToolBar.SetRouteCommandsViaFrame (FALSE); 
 
	AdjustLayout (); 
	return 0; 
} 
 
void COutputBar::AdjustLayout () 
{ 
	if (GetSafeHwnd () == NULL) 
	{ 
		return; 
	} 
 
	CRect rectClient; 
	GetClientRect (rectClient); 
 
	int cyTlb = m_wndToolBar.CalcFixedLayout (FALSE, TRUE).cy; 
 
	m_wndToolBar.SetWindowPos (NULL, rectClient.left, rectClient.top,  
								rectClient.Width (), cyTlb, 
								SWP_NOACTIVATE | SWP_NOZORDER); 
	m_wndList.SetWindowPos (NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, 
								rectClient.Width () - 2, rectClient.Height () - cyTlb - 2, 
								SWP_NOACTIVATE | SWP_NOZORDER); 
} 
 
void COutputBar::OnSize(UINT nType, int cx, int cy)  
{ 
	CBCGPDockingControlBar::OnSize(nType, cx, cy); 
 
	AdjustLayout (); 
} 
 
void COutputBar::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	CRect rectList; 
	m_wndList.GetWindowRect (rectList); 
	ScreenToClient (rectList); 
 
	rectList.InflateRect (1, 1); 
	dc.Draw3dRect (rectList,	::GetSysColor (COLOR_3DSHADOW),  
								::GetSysColor (COLOR_3DSHADOW)); 
} 
 
void COutputBar::OnSetFocus(CWnd* pOldWnd)  
{ 
	CBCGPDockingControlBar::OnSetFocus(pOldWnd); 
	m_wndList.SetFocus (); 
} 
 
void COutputBar::OnOutputClear() 
{ 
	m_wndList.DeleteAllItems (); 
	pDoc->csOutputInfo.Lock (); 
	pDoc->outInfoIndex =0; 
	pDoc->outputInfo.RemoveAll (); 
	pDoc->csOutputInfo.Unlock (); 
} 
 
void COutputBar::OnOutputOpen() 
{ 
	TCHAR strFilter[]=_T("会商日志(*.log)|*.log||"); 
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,strFilter); 
	if(dlg.DoModal ()!=IDOK) return; 
	 
	CFile myFile; 
	CFileException e; 
 
	try{   
		myFile.Open(dlg.GetPathName(),CFile::modeRead|CFile::typeBinary, &e); 
		CArchive ar(&myFile, CArchive::load); 
		pDoc->csOutputInfo.Lock (); 
		pDoc->outputInfo.RemoveAll (); 
		pDoc->outputInfo.Serialize(ar); 
		ar.Close(); 
		myFile.Close(); 
		pMainWnd->FillOutputBarInfo (); 
		pDoc->csOutputInfo.Unlock (); 
	} 
	catch(CFileException * e){ 
		e->ReportError(); 
		e->Delete(); 
	} 
} 
 
void COutputBar::OnOutputSave() 
{ 
	HRESULT hResult; 
	TCHAR strFilter[]=_T("会商日志(*.log)|*.log||"); 
	CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,strFilter); 
	hResult = (int)dlg.DoModal(); 
	if (hResult != IDOK) { 
		return; 
	} 
    // Add the appropriate extension if the user didn't type one 
	CString strFileName; 
	strFileName = dlg.m_ofn.lpstrFile; 
	// add the file extension if the user didn't supply one 
	if (dlg.m_ofn.nFileExtension == 0)  
	{ 
		strFileName = strFileName + ".log"; 
	} 
 
	CFile myFile; 
	CFileException e; 
 
	try{   
		myFile.Open(strFileName,CFile::modeWrite|CFile::modeCreate|CFile::typeBinary, &e); 
		CArchive ar(&myFile, CArchive::store); 
		pDoc->csOutputInfo.Lock (); 
		pDoc->outputInfo.Serialize(ar); 
		pDoc->csOutputInfo.Unlock (); 
		ar.Close(); 
		myFile.Close(); 
	} 
	catch(CFileException * e){ 
		e->ReportError(); 
		e->Delete(); 
	} 
}