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

📄 transferagentframe.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
//
//////////////////////////////////////////////////////////////////////

// TransferAgentFrame.cpp : implementation file
//

#include "stdafx.h"
#include "Oscar.h"

#include "TransferAgentFrame.h"
#include "TransferAgentView.h"

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

static UINT AutoCloseMessage = 
			RegisterWindowMessage(_T("Oscar auto close transfer agent"));

/////////////////////////////////////////////////////////////////////////////
// CTransferAgentFrame

IMPLEMENT_DYNCREATE(CTransferAgentFrame, CMDIChildWnd)

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

	m_bAutoClose = FALSE;
}

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


BEGIN_MESSAGE_MAP(CTransferAgentFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(CTransferAgentFrame)
	ON_WM_CLOSE()
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_REGISTERED_MESSAGE(AutoCloseMessage, OnAutoClose)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTransferAgentFrame message handlers

void CTransferAgentFrame::OnClose() 
{
	CTransferAgentView *pView = (CTransferAgentView *)GetActiveView();

	ASSERT(pView);
	if(pView)
	{
		// Check to see if we're still transferring stuff.

		if(pView->IsWorking())
		{
			// Make sure we really want to close and stop the transfers.

			if(MessageBox(_T("Are you sure you want to close the Transfer\n"
				"Agent and stop your transfers?"), _T("Transfer Agent"),
				MB_YESNO | MB_ICONQUESTION) == IDNO)
				return;

			// We want to stop.  Stop the transfers.
			CWaitCursor waitCursor;
			pView->StopTransfer(TRUE);
		}
	}
	
	CMDIChildWnd::OnClose();
}

int CTransferAgentFrame::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_arch1.rectTransferAgent;
	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_arch1.bShowingTransferAgent = TRUE;

	return 0;
}

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

	// Get the column widths.
	int nColWidths[3];
	memset((void *)nColWidths, 0, sizeof(nColWidths));
	CTransferAgentView *pView = (CTransferAgentView *)GetActiveView();
	ASSERT(pView);
	if(pView)
	{
		nColWidths[0] = pView->m_cListCtrl.GetColumnWidth(0);
		nColWidths[1] = pView->m_cListCtrl.GetColumnWidth(1);
		nColWidths[2] = pView->m_cListCtrl.GetColumnWidth(2);
	}

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

	pArchive->m_arch1.rectTransferAgent = rectWindow;
	if(pApp->m_bCanChangeSettings)
		pArchive->m_arch1.bShowingTransferAgent = FALSE;

	// Store the column widths.
	memcpy((void *)pArchive->m_arch1.nTransferAgentWidths,
		(void *)nColWidths, sizeof(nColWidths));
}

BOOL CTransferAgentFrame::AutoCloseOnComplete()
{
	m_bAutoClose = TRUE;

	return TRUE;
}

LRESULT CTransferAgentFrame::OnAutoClose(WPARAM wParam, LPARAM lParam)
{
	// We got an autoclose message from the other thread.
	CTransferAgentView *pView = (CTransferAgentView *)GetActiveView();

	ASSERT(pView);
	if(!pView) return 0;

	// Wait for the other thread to finish, if it hasn't already.
	pView->StopTransfer(TRUE);
	m_bAutoClose = FALSE;      // Clear it.

	// Now we can safely close.
	DestroyWindow();

	return 0;
}

BOOL CTransferAgentFrame::RegisterWithView()
{
	// Make a connection with the view.
	CTransferAgentView *pView = (CTransferAgentView *)GetActiveView();
	ASSERT(pView);
	ASSERT(pView->IsKindOf(RUNTIME_CLASS(CTransferAgentView)));
	if(!pView) return FALSE;

	pView->m_pFrame = this;
	return TRUE;
}

⌨️ 快捷键说明

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