⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 networkmonitorframe.cpp

📁 c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++6.0
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////
// FileFury
// Copyright (c) 2000 Tenebril Incorporated
// All rights reserved.
//
// This source code is governed by the Tenebril open source
// license (http://www.tenebril.com/developers/opensource/license.html)
//
// For more information on this and other open source applications,
// visit the Tenebril OpenSource page:
//       http://www.tenebril.com/developers/opensource
//
//////////////////////////////////////////////////////////////////////

// NetworkMonitorFrame.cpp : implementation file
//

#include "stdafx.h"
#include "Oscar.h"
#include "NetworkMonitorFrame.h"
#include "NetworkMonitorView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorFrame

IMPLEMENT_DYNCREATE(CNetworkMonitorFrame, CMDIChildWnd)

CNetworkMonitorFrame::CNetworkMonitorFrame()
{
	// Update the App's pointer to here.
	COscarApp *pApp = (COscarApp *)AfxGetApp();
	ASSERT(pApp);
	if(pApp)
	{
		ASSERT(pApp->m_pNetworkMonitor == NULL);
		pApp->m_pNetworkMonitor = this;
	}
}

CNetworkMonitorFrame::~CNetworkMonitorFrame()
{
	// Clear the App's pointer.
	COscarApp *pApp = (COscarApp *)AfxGetApp();
	ASSERT(pApp);
	if(pApp)
	{
		ASSERT(pApp->m_pNetworkMonitor);
		pApp->m_pNetworkMonitor = NULL;
	}
}


BEGIN_MESSAGE_MAP(CNetworkMonitorFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(CNetworkMonitorFrame)
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_WM_MDIACTIVATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetworkMonitorFrame message handlers

int CNetworkMonitorFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	// Set the window size to the last observed.
	COscarApp *pApp = (COscarApp *)AfxGetApp();
	ASSERT(pApp);
	CSettingsArchive *pArchive = pApp->GetArchive();
	ASSERT(pArchive);

	CRect rectWindow = pArchive->m_arch2.rectNetworkMonitor;
	if(rectWindow.Width() > 0 && rectWindow.Height() > 0)
	{
		// Make sure the window rect is not unreasonable.
		if(rectWindow.left < 0)
			rectWindow.OffsetRect(-rectWindow.left, 0);
		if(rectWindow.top < 0)
			rectWindow.OffsetRect(0, -rectWindow.top);
		CWnd *pParent = GetParent();
		ASSERT(pParent);
		CRect ParentRect;
		pParent->GetClientRect(ParentRect);
		if(rectWindow.left > ParentRect.Width() - 20)
			rectWindow.left = ParentRect.Width() - 20;
		if(rectWindow.top > ParentRect.Height() - 20)
			rectWindow.top = ParentRect.Height() - 20;

		// We have valid coordinates.  Set the window to that position.	
		SetWindowPos(NULL, rectWindow.left, rectWindow.top,
			rectWindow.Width(), rectWindow.Height(), SWP_NOZORDER);
	}

	pArchive->m_arch2.bShowingNetworkMonitor = TRUE;
	
	return 0;
}

void CNetworkMonitorFrame::OnDestroy() 
{
	// Get the window coordinates before we die.
	CRect rectWindow;
	WINDOWPLACEMENT wndPlacement;
	GetWindowPlacement( &wndPlacement );
	rectWindow = wndPlacement.rcNormalPosition;

	CMDIChildWnd::OnDestroy();
	
	// Store the window coordinates.
	COscarApp *pApp = (COscarApp *)AfxGetApp();
	ASSERT(pApp);
	CSettingsArchive *pArchive = pApp->GetArchive();
	ASSERT(pArchive);

	pArchive->m_arch2.rectNetworkMonitor = rectWindow;
	if(pApp->m_bCanChangeSettings)
		pArchive->m_arch2.bShowingNetworkMonitor = FALSE;

	return;	
}

void CNetworkMonitorFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd) 
{
	// Get a pointer to the view.
	CNetworkMonitorView *pView = (CNetworkMonitorView *)GetActiveView( );
	// ASSERT(pView);    // This can happen somehow.
	if(pView) pView->m_cListCtrl.SetRedraw();

	CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);	
}

BOOL CNetworkMonitorFrame::AddComment(LPCTSTR czComment)
{
	// Make sure we don't have thread clashes.
	m_cMutex.Lock();

	// Get a pointer to the view.
	CNetworkMonitorView *pView = (CNetworkMonitorView *)GetActiveView( );

	// This can happen somehow.
	if(!pView)
	{
		m_cMutex.Unlock();
		return FALSE;
	}

	// Format the comment.
	CString cszComment = czComment;

	// Remove any newlines.
	if(cszComment.GetLength() < 1)
	{
		m_cMutex.Unlock();
		return FALSE;
	}

	int nNewline;
	while((nNewline = cszComment.Find(_T('\n'))) > -1)
		cszComment.SetAt(nNewline, _T(' '));

	// Insert the comment into the view's list control.
	if(!pView->m_cListCtrl.InsertItem(pView->m_cListCtrl.GetItemCount(), 
		cszComment))
	{
		m_cMutex.Unlock();
		return FALSE;
	}

	// Make sure the new item is visible.
	BOOL bRet = pView->m_cListCtrl.EnsureVisible(pView->m_cListCtrl.GetItemCount() - 1,
		FALSE);
	m_cMutex.Unlock();

	return bRet;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -