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

📄 mfcd3dview.cpp

📁 MFC+D3D编程:在MFC单文档界面下使用D3D9.0进行编程
💻 CPP
字号:
// MFCD3DView.cpp : implementation of the CMFCD3DView class
//

#include "stdafx.h"
#include "MFCD3D.h"

#include "MFCD3DDoc.h"
#include "MFCD3DView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMFCD3DView

IMPLEMENT_DYNCREATE(CMFCD3DView, CFormView)

BEGIN_MESSAGE_MAP(CMFCD3DView, CFormView)
	//{{AFX_MSG_MAP(CMFCD3DView)
	ON_COMMAND(ID_VIEW_RENDER, OnRender)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCD3DView construction/destruction

CMFCD3DView::CMFCD3DView()
	: CFormView(CMFCD3DView::IDD)
{
	//{{AFX_DATA_INIT(CMFCD3DView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

	m_pD3DWnd = new CD3DWnd;
}

CMFCD3DView::~CMFCD3DView()
{
	delete m_pD3DWnd;
}

void CMFCD3DView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMFCD3DView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CMFCD3DView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	// init D3D
	m_pD3DWnd->SubclassDlgItem(IDC_RENDER, this);

	if (FAILED(m_pD3DWnd->Initialize()))
		PostQuitMessage(1);

	// keep track of the main frame window
	m_pMainFrame = (CMainFrame*)GetTopLevelFrame();

	// update D3D device description status bar pane
	m_pMainFrame->UpdateStatusBar(ID_INDICATOR_DEVICE, m_pD3DWnd->GetDeviceStats());
}

/////////////////////////////////////////////////////////////////////////////
// CMFCD3DView diagnostics

#ifdef _DEBUG
void CMFCD3DView::AssertValid() const
{
	CFormView::AssertValid();
}

void CMFCD3DView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CMFCD3DView message handlers

void CMFCD3DView::OnRender() 
{
	m_pD3DWnd->RenderEnvironment();

	// update D3D fps status bar pane
	m_pMainFrame->UpdateStatusBar(ID_INDICATOR_FPS, m_pD3DWnd->GetFrameStats());
}

LRESULT CMFCD3DView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	if (m_pD3DWnd && m_pD3DWnd->IsActive())
		if (m_pD3DWnd->HandleMouseMessages(message, wParam, lParam))
			return 0L;
	
	return CFormView::WindowProc(message, wParam, lParam);
}

⌨️ 快捷键说明

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