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

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

// DirectoryListFrame.cpp : implementation file
//

#include "stdafx.h"
#include "Oscar.h"
#include "DirectoryListFrame.h"
#include "DirectoryListView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDirectoryListFrame

IMPLEMENT_DYNCREATE(CDirectoryListFrame, CMDIChildWnd)

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

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


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

/////////////////////////////////////////////////////////////////////////////
// CDirectoryListFrame message handlers

BOOL CDirectoryListFrame::AddDirectory(LPCTSTR czDir)
{
	// Get a pointer to the view.
	CDirectoryListView *pView = (CDirectoryListView *)GetActiveView( );
	ASSERT(pView);
	if(!pView) return FALSE;

	// Add the directory.
	return pView->AddDirectory(czDir);
}

BOOL CDirectoryListFrame::RemoveDirectory(LPCTSTR czDir)
{
	// Get a pointer to the view.
	CDirectoryListView *pView = (CDirectoryListView *)GetActiveView( );
	ASSERT(pView);
	if(!pView) return FALSE;

	// Add the directory.
	return pView->RemoveDirectory(czDir);
}

// Need to override this so the control updates itself when its focus changes.
void CDirectoryListFrame::OnMDIActivate(BOOL bActivate, CWnd * pActivateWnd, 
										CWnd * pDeactivateWnd)
{
	// Get a pointer to the view.
	CDirectoryListView *pView = (CDirectoryListView *)GetActiveView( );
	// ASSERT(pView);    // This can happen somehow.
	if(pView) pView->m_cListCtrl.SetRedraw();

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

void CDirectoryListFrame::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_arch1.rectDirectoryList = rectWindow;
	if(pApp->m_bCanChangeSettings)
		pArchive->m_arch1.bShowingDirectoryList = FALSE;

	return;
}

int CDirectoryListFrame::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.rectDirectoryList;
	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.bShowingDirectoryList = TRUE;
	
	return 0;
}

⌨️ 快捷键说明

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