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

📄 xindowview.cpp

📁 我们使用Windows资源管理器[Exporlor]时
💻 CPP
字号:
// XindowView.cpp : implementation of the CXindowView class
//

#include "stdafx.h"
#include "Xindow.h"

#include "XindowDoc.h"
#include "XindowView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CXindowView

IMPLEMENT_DYNCREATE(CXindowView, CView)

BEGIN_MESSAGE_MAP(CXindowView, CView)
	//{{AFX_MSG_MAP(CXindowView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXindowView construction/destruction

CXindowView::CXindowView()
{
	m_bFormShow = TRUE;
}

CXindowView::~CXindowView()
{
}

BOOL CXindowView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CXindowView drawing

void CXindowView::OnDraw(CDC* pDC)
{
	CXindowDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CXindowView diagnostics

#ifdef _DEBUG
void CXindowView::AssertValid() const
{
	CView::AssertValid();
}

void CXindowView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CXindowDoc* CXindowView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXindowDoc)));
	return (CXindowDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CXindowView message handlers

int CXindowView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	/* 创建左右两个视图 */
	m_pForm = (CXindowForm *) okCreateView(RUNTIME_CLASS(CXindowForm), 1001);
	m_pList = (CXindowList *) okCreateView(RUNTIME_CLASS(CXindowList), 1002);
	
	m_pForm->m_pParent = this;

	return 0;
}

/*
 * 创建视图
 */
CView* CXindowView::okCreateView(CRuntimeClass *pViewClass, int nCtrlID)
{
	CDocument* pDocument = (CDocument*) GetDocument();

	// Create new view
	CCreateContext contextT;
	contextT.m_pLastView	   = NULL;
	contextT.m_pCurrentDoc	   = pDocument;
	contextT.m_pNewViewClass   = pViewClass;
	contextT.m_pNewDocTemplate = pDocument ? pDocument->GetDocTemplate() : NULL;
	contextT.m_pCurrentFrame   = NULL;

	CWnd* pWnd;
	TRY
	{
		pWnd = (CWnd*)pViewClass->CreateObject();
		if (pWnd == NULL) AfxThrowMemoryException();
	}
	CATCH_ALL(e)
	{
		TRACE0( "Out of memory creating a view.\n" );
		// Note: DELETE_EXCEPTION(e) not required
		return NULL;
	}
	END_CATCH_ALL
		
	ASSERT_KINDOF(CWnd, pWnd);
	ASSERT(pWnd->m_hWnd == NULL); // not yet created.

	// Create with the right size (wrong position)
	if (!pWnd->Create(NULL, NULL, WS_CHILD | WS_VISIBLE,
		CRect(0,0,0,0), this, nCtrlID, &contextT))
	{
		TRACE0( "Warning: couldn't create new view.\n" );
		// pWnd will be cleaned up by PostNcDestroy
		return NULL;
	}

	CView* pNewView = (CView *) pWnd;
	ASSERT_KINDOF (CView, pNewView);
	pNewView->OnInitialUpdate();

	return pNewView;
}

/*
 * 调整左右两个视图的位置
 */
void CXindowView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	int nFormWidth = 200;

	/* 如果窗口宽度<400, 就隐藏左视图 */
	if(cx>400)
	{
		if(m_pForm->GetSafeHwnd())  m_pForm->ShowWindow(SW_SHOW);
		if(m_pForm->GetSafeHwnd())  m_pForm->MoveWindow(0,0,nFormWidth,cy);
		if(m_pList->GetSafeHwnd())  m_pList->ShowWindow(SW_SHOW);
		if(m_pList->GetSafeHwnd())  m_pList->MoveWindow(nFormWidth,0,cx-nFormWidth,cy);
	}
	else
	{
		if(m_pForm->GetSafeHwnd())  m_pForm->ShowWindow(SW_HIDE);
		if(m_pList->GetSafeHwnd())  m_pList->ShowWindow(SW_SHOW);
		if(m_pList->GetSafeHwnd())  m_pList->MoveWindow(0,0,cx,cy);
	}
}

⌨️ 快捷键说明

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