MFC 单文档视图架构

这篇具有很好参考价值的文章主要介绍了MFC 单文档视图架构。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

单文档视图架构

模仿单文档视图结构

InitInstance()函数执行分析

框架生成单文档视图项目

框架窗口类

应用程序类

文档类

视图类

类向导


单文档视图架构

只能管理一个文档,但可以有多个视图窗口。

参与架构的类:CFrameWnd ,  CWinApp , CView , CDocument

需要用到的类:CDocTemplate(文档模板类)的一个子类CSingleDocTemplate(单文档模板类),以及CDocManger(文档管理类)

代码书写:参与架构的四个类除了应用程序类,其余三个类均支持动态创建机制。

模仿单文档视图结构

创建一个Win32桌面程序

代码如下:

#include <afxwin.h>
#include "resource1.h"
class CMyDoc : public CDocument {
	DECLARE_DYNCREATE(CMyDoc)
};
IMPLEMENT_DYNCREATE(CMyDoc, CDocument)

class CMyView : public CView {
	DECLARE_DYNCREATE(CMyView)
public:
	virtual void OnDraw(CDC* pDC);
};
IMPLEMENT_DYNCREATE(CMyView, CView)
void CMyView::OnDraw(CDC* pDC) {
	pDC->TextOut(100, 100, "我是视图窗口");
}

class CMyFrameWnd : public CFrameWnd {
	DECLARE_DYNCREATE(CMyFrameWnd)
};
IMPLEMENT_DYNCREATE(CMyFrameWnd, CFrameWnd)

class CMyWinApp : public CWinApp {
public:
	virtual BOOL InitInstance();
};
BOOL CMyWinApp::InitInstance() {
	CSingleDocTemplate* pTemplate = new CSingleDocTemplate(IDR_MENU1,
		RUNTIME_CLASS(CMyDoc),
		RUNTIME_CLASS(CMyFrameWnd),
		RUNTIME_CLASS(CMyView));
	AddDocTemplate(pTemplate);
	OnFileNew();
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}
CMyWinApp theApp;
  • 文档类,视图类,框架窗口类需要实现动态创建机制,交给程序实现
  • 视图类需要重写虚函数OnDraw()
  • 应用程序类需要重写虚函数InitInstance()

遇见报错

MFC 单文档视图架构,MFC,mfc,c++

点击重试,跳转至代码报错位置

MFC 单文档视图架构,MFC,mfc,c++

这里需要一个字符串,作为窗口的标题,添加一个字符串资源即可,值必须是61443

MFC 单文档视图架构,MFC,mfc,c++

InitInstance()函数执行分析

InitInstance()函数中,首先创建了一个CSingleDocTemplate对象,接下来进入构造函数中看看

MFC 单文档视图架构,MFC,mfc,c++

首先创建了一个CSingleDocTemplate对象,接下来进入构造函数中看看,this指针是CSingleDocTemplate对象

先进入父类的构造函数,函数内部this指针是CSingleDocTemplate对象

MFC 单文档视图架构,MFC,mfc,c++

给CSingleDocTemplate对象的诸多成员变量赋值

MFC 单文档视图架构,MFC,mfc,c++

MFC 单文档视图架构,MFC,mfc,c++

构造函数执行完毕

进入函数  AddDocTemplate(pTemplate);   this指针是thsApp

MFC 单文档视图架构,MFC,mfc,c++

MFC 单文档视图架构,MFC,mfc,c++

进入函数AddDocTemplate函数,this指针是theApp的成员变量m_pDocManager,参数是CSingleDocTemplate对象

进入函数LoadTemplate(),this指针是CSingleDocTemplate对象

theApp还有一个成员变量m_templateList是一个链表结构,m_templateList.AddTail(pTemplate);  这句代码应该是把CSingleDocTemplate对象放到链表结构的尾部。

MFC 单文档视图架构,MFC,mfc,c++

到此,大概就构成下面的数据关系

MFC 单文档视图架构,MFC,mfc,c++

进入函数OnFileNew();  函数内部this指针是theApp

MFC 单文档视图架构,MFC,mfc,c++

 theApp的成员变量m_pDocMannager调用函数OnFileNew(),函数内部this为文档管理类对象地址

MFC 单文档视图架构,MFC,mfc,c++

拿到刚刚放到链表尾部的CSingleDocTemplate对象地址

MFC 单文档视图架构,MFC,mfc,c++

函数OpenDocumentFile内部this为单文档模板类对象地址

MFC 单文档视图架构,MFC,mfc,c++

进入函数看看

MFC 单文档视图架构,MFC,mfc,c++

调用函数CreateNewDocument(),函数内部this为单文档模板类对象地址

MFC 单文档视图架构,MFC,mfc,c++

动态创建文档类对象,并返回对象地址;并调用AddDocument(pDocument);

MFC 单文档视图架构,MFC,mfc,c++

 函数内部this为单文档模板类对象地址,并且把pDocument赋值给单文档模板类对象的成员变量m_pOnly

MFC 单文档视图架构,MFC,mfc,c++

调用函数CreateNewFrame(pDocument, NULL);  函数内部this为单文档模板类对象地址

MFC 单文档视图架构,MFC,mfc,c++

动态创建框架类对象,并返回对象地址

MFC 单文档视图架构,MFC,mfc,c++

之后就是pFrame->LoadFrame,创建框架窗口

函数OnFileNew的逻辑如下:

MFC 单文档视图架构,MFC,mfc,c++

框架生成单文档视图项目

单文档视图项目的类信息

MFC 单文档视图架构,MFC,mfc,c++

 

框架窗口类

MainFrm.h


// MainFrm.h : interface of the CMainFrame class
//

#pragma once

class CMainFrame : public CFrameWnd   // 框架窗口类
{
	
protected: // create from serialization only
	CMainFrame();                      // 构造函数
	DECLARE_DYNCREATE(CMainFrame)      // 消息映射

// Attributes
public:

// Operations
public:

// Overrides
public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);  // (1)注册窗口,(2)把为NULL的成员赋值

// Implementation
public:
	virtual ~CMainFrame();             // 析构函数
#ifdef _DEBUG // 和调试程序相关不需要管
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif


// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()

};

MainFrm.cpp


// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "MFCSdiWizard.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)  // 动态创建

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)    // 消息映射
END_MESSAGE_MAP()

// CMainFrame construction/destruction

CMainFrame::CMainFrame()  // 构造函数
{
	// TODO: add member initialization code here
}

CMainFrame::~CMainFrame()   // 析构函数
{
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)  //(1)注册窗口 (2)更改为NULL,并给窗口标题
{
	if( !CFrameWnd::PreCreateWindow(cs) )   // 调用父类的
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

// CMainFrame diagnostics

#ifdef _DEBUG  // 调试程序相关
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}
#endif //_DEBUG


// CMainFrame message handlers

应用程序类

MFCSdiWizard.h


// MFCSdiWizard.h : main header file for the MFCSdiWizard application
//
#pragma once

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h"       // main symbols


// CMFCSdiWizardApp:
// See MFCSdiWizard.cpp for the implementation of this class
//

class CMFCSdiWizardApp : public CWinApp  // 应用程序类
{
public:
	CMFCSdiWizardApp();  // 构造函数


// Overrides
public:
	virtual BOOL InitInstance();  // 初始化函数
	virtual int ExitInstance();   // 反初始化函数

// Implementation
	afx_msg void OnAppAbout();    // 处理WM_COMMAND消息
	DECLARE_MESSAGE_MAP()         // 消息映射
};

extern CMFCSdiWizardApp theApp;

MFCSdiWizard.cpp


// MFCSdiWizard.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "afxwinappex.h"
#include "afxdialogex.h"
#include "MFCSdiWizard.h"
#include "MainFrm.h"

#include "MFCSdiWizardDoc.h"
#include "MFCSdiWizardView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCSdiWizardApp

BEGIN_MESSAGE_MAP(CMFCSdiWizardApp, CWinApp)  // 消息映射
	ON_COMMAND(ID_APP_ABOUT, &CMFCSdiWizardApp::OnAppAbout)
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()


// CMFCSdiWizardApp construction

CMFCSdiWizardApp::CMFCSdiWizardApp()  // 构造函数
{
	// support Restart Manager
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
#ifdef _MANAGED
	// If the application is built using Common Language Runtime support (/clr):
	//     1) This additional setting is needed for Restart Manager support to work properly.
	//     2) In your project, you must add a reference to System.Windows.Forms in order to build.
	System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
#endif

	// TODO: replace application ID string below with unique ID string; recommended
	// format for string is CompanyName.ProductName.SubProduct.VersionInformation
	SetAppID(_T("MFCSdiWizard.AppID.NoVersion"));

	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

// The one and only CMFCSdiWizardApp object

CMFCSdiWizardApp theApp;  // 爆破点,程序由次开始


// CMFCSdiWizardApp initialization

BOOL CMFCSdiWizardApp::InitInstance()   // 初始化函数,前面是初始化一些组件,和架构关系不大
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	EnableTaskbarInteraction(FALSE);

	// AfxInitRichEdit2() is required to use RichEdit control	
	// AfxInitRichEdit2();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)


	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CSingleDocTemplate* pDocTemplate;   // 单文档类对象
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMFCSdiWizardDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CMFCSdiWizardView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);


	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);



	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))  //这个函数里面就会调用OnFileNew函数
		return FALSE;

	// The one and only window has been initialized, so show and update it
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	// call DragAcceptFiles only if there's a suffix
	//  In an SDI app, this should occur after ProcessShellCommand
	return TRUE;
}

int CMFCSdiWizardApp::ExitInstance()  // 反初始化函数
{
	//TODO: handle additional resources you may have added
	AfxOleTerm(FALSE);  // 处理前面的初始化的组件

	return CWinApp::ExitInstance();
}

// CMFCSdiWizardApp message handlers


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx  // 管理点击Help的对话框类
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()

// App command to run the dialog
void CMFCSdiWizardApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

// CMFCSdiWizardApp message handlers

文档类

MFCSdiWizardDoc.h


// MFCSdiWizardDoc.h : interface of the CMFCSdiWizardDoc class
//


#pragma once


class CMFCSdiWizardDoc : public CDocument  // 文档类
{
protected: // create from serialization only
	CMFCSdiWizardDoc();  // 构造函数
	DECLARE_DYNCREATE(CMFCSdiWizardDoc)  // 动态创建

// Attributes
public:

// Operations
public:

// Overrides
public:// 和管理数据有关的两个函数
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
#ifdef SHARED_HANDLERS // 不需要管 
	virtual void InitializeSearchContent();
	virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
#endif // SHARED_HANDLERS

// Implementation
public:
	virtual ~CMFCSdiWizardDoc(); //析构函数
#ifdef _DEBUG  // 调试程序相关
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()  // 消息映射

#ifdef SHARED_HANDLERS
	// Helper function that sets search content for a Search Handler
	void SetSearchContent(const CString& value);
#endif // SHARED_HANDLERS
};

MFCSdiWizardDoc.cpp


// MFCSdiWizardDoc.cpp : implementation of the CMFCSdiWizardDoc class
//

#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "MFCSdiWizard.h"
#endif

#include "MFCSdiWizardDoc.h"

#include <propkey.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CMFCSdiWizardDoc

IMPLEMENT_DYNCREATE(CMFCSdiWizardDoc, CDocument)   // 动态创建

BEGIN_MESSAGE_MAP(CMFCSdiWizardDoc, CDocument)   // 消息映射
END_MESSAGE_MAP()


// CMFCSdiWizardDoc construction/destruction

CMFCSdiWizardDoc::CMFCSdiWizardDoc()  // 构造
{
	// TODO: add one-time construction code here

}

CMFCSdiWizardDoc::~CMFCSdiWizardDoc()  //析构
{
}

// 下面两个函数与管理数据有关
BOOL CMFCSdiWizardDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}




// CMFCSdiWizardDoc serialization

void CMFCSdiWizardDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

#ifdef SHARED_HANDLERS

// Support for thumbnails
void CMFCSdiWizardDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
	// Modify this code to draw the document's data
	dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));

	CString strText = _T("TODO: implement thumbnail drawing here");
	LOGFONT lf;

	CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
	pDefaultGUIFont->GetLogFont(&lf);
	lf.lfHeight = 36;

	CFont fontDraw;
	fontDraw.CreateFontIndirect(&lf);

	CFont* pOldFont = dc.SelectObject(&fontDraw);
	dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
	dc.SelectObject(pOldFont);
}

// Support for Search Handlers
void CMFCSdiWizardDoc::InitializeSearchContent()
{
	CString strSearchContent;
	// Set search contents from document's data. 
	// The content parts should be separated by ";"

	// For example:  strSearchContent = _T("point;rectangle;circle;ole object;");
	SetSearchContent(strSearchContent);
}

void CMFCSdiWizardDoc::SetSearchContent(const CString& value)
{
	if (value.IsEmpty())
	{
		RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
	}
	else
	{
		CMFCFilterChunkValueImpl *pChunk = NULL;
		ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
		if (pChunk != NULL)
		{
			pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
			SetChunkValue(pChunk);
		}
	}
}

#endif // SHARED_HANDLERS

// CMFCSdiWizardDoc diagnostics

#ifdef _DEBUG  // 调试程序相关
void CMFCSdiWizardDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CMFCSdiWizardDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CMFCSdiWizardDoc commands

视图类

MFCSdiWizardView.h


// MFCSdiWizardView.h : interface of the CMFCSdiWizardView class
//

#pragma once


class CMFCSdiWizardView : public CView  // 视图类
{
protected: // create from serialization only
	CMFCSdiWizardView();   // 构造
	DECLARE_DYNCREATE(CMFCSdiWizardView)  //动态创建

// Attributes
public:
	CMFCSdiWizardDoc* GetDocument() const;  // 可以拿到视图类对应的文档类对象

// Operations
public:

// Overrides
public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view  // 绘制
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs); // 视图类本质也是窗口
protected: // 和打印机相关
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// Implementation
public:
	virtual ~CMFCSdiWizardView();  //析构
#ifdef _DEBUG   // 调试程序相关
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()  // 消息映射
public:
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnTest();
};

#ifndef _DEBUG  // debug version in MFCSdiWizardView.cpp
inline CMFCSdiWizardDoc* CMFCSdiWizardView::GetDocument() const
   { return reinterpret_cast<CMFCSdiWizardDoc*>(m_pDocument); }
#endif

MFCSdiWizardView.cpp


// MFCSdiWizardView.cpp : implementation of the CMFCSdiWizardView class
//

#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "MFCSdiWizard.h"
#endif

#include "MFCSdiWizardDoc.h"
#include "MFCSdiWizardView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCSdiWizardView

IMPLEMENT_DYNCREATE(CMFCSdiWizardView, CView)  // 动态创建

BEGIN_MESSAGE_MAP(CMFCSdiWizardView, CView)  // 消息映射
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(ID_TEST_TT, &CMFCSdiWizardView::OnTest)
END_MESSAGE_MAP()

// CMFCSdiWizardView construction/destruction

CMFCSdiWizardView::CMFCSdiWizardView()  //构造
{
	// TODO: add construction code here

}

CMFCSdiWizardView::~CMFCSdiWizardView() //析构
{
}

BOOL CMFCSdiWizardView::PreCreateWindow(CREATESTRUCT& cs)  // (1)注册窗口 (2)窗口标题赋值
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	
	return CView::PreCreateWindow(cs);  // 调用父类的
}

// CMFCSdiWizardView drawing

void CMFCSdiWizardView::OnDraw(CDC* /*pDC*/)
{
	CMFCSdiWizardDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
}


// CMFCSdiWizardView printing

BOOL CMFCSdiWizardView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMFCSdiWizardView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMFCSdiWizardView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}


// CMFCSdiWizardView diagnostics

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

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

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


// CMFCSdiWizardView message handlers


void CMFCSdiWizardView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CView::OnLButtonDown(nFlags, point);
}


void CMFCSdiWizardView::OnTest()
{
	// TODO: Add your command handler code here
	AfxMessageBox("点了菜单项");
}

类向导

项目->添加类

MFC 单文档视图架构,MFC,mfc,c++

MFC 单文档视图架构,MFC,mfc,c++

处理WM_COMMAND消息

MFC 单文档视图架构,MFC,mfc,c++

处理系统消息

MFC 单文档视图架构,MFC,mfc,c++

处理添加虚函数

MFC 单文档视图架构,MFC,mfc,c++文章来源地址https://www.toymoban.com/news/detail-784914.html

到了这里,关于MFC 单文档视图架构的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 24 MFC文档串行化和单文档应用程序

    ui 设计 保存 读取 定义一个文档类 添加虚函数判断是否保存还是读取 在 主对话框 内添加Serialize虚函数 // fileDemoDlg.h: 头文件 单文档应用程序(SDI应用程序)是一种基于文档的应用程序,它允许用户打开、编辑和保存单个文档。这种类型的应用程序通常用于文本编辑器、图像

    2024年02月17日
    浏览(29)
  • mfc入门基础(一)-单文档应用程序框架

    最近因为相关业务,需要接触下mfc的一些老代码,但是mfc上手并没有qt那么简单,所以四处寻找学习资料,发现一个写的挺好的教程,这边我进行转载下,学习的过程中进行了一些修改,总结下。 此处附上原文链接:鸡啄米MFC入门系列教程_逸适安然的博客-CSDN博客_鸡啄米 V

    2024年02月04日
    浏览(35)
  • MFC 单文档弹出对话框 标题图标

    创建MFC时 1、应用程序类型:以单个文档-项目样式选择MFC标准 菜单关联对话框  2、菜单关联-资源视图中的Menu-IDR_MAINFRAME(此处看想关联谁,如果是想关联一个对话框,那就先创建一个对话框再进行关联,如果是想关联一个类,可以看函数在哪个类下面从而进行关联) a.关联

    2024年02月06日
    浏览(30)
  • MFC 单文档 静态分割窗口 m_wndSplitter 状态栏

    MFC 单文档 静态分割窗口 VC++图形编程之状态栏和进度条,源码在VC6.0下测试编译通过。 第4章 状态栏与进度条/扩展实例1 带进度条的状态栏 第4章 状态栏与进度条/扩展实例2 带位图的状态栏 第4章 状态栏与进度条/扩展实例3 在状态栏中显示时间 第4章 状态栏与进度条/扩展实例

    2024年02月06日
    浏览(22)
  • MFC第二十八天 WM_SIZE应用,CFrameWnd类LoadFrame的方法,PreCreateWindow窗口预处理,Frame-view窗口视图

    点击相应控件的属性,对其进行动态布局的设置,选择两者,窗口再次进行拉伸就会进行改变。 a)CFrameWnd类偏爱WM_CREATE,因为所有的内部窗口都是代码创建的。 而不像对话框是拖入的。 b)CFrameWnd::rectDefault管理层叠 static const CRect rectDefault; c)LoadFrame内部包含CreateFrame,同时执行

    2024年02月14日
    浏览(64)
  • 基于MFC的图书馆图书管理系统 VC++操作Excel文档的方法,读取,查询,写入,修改,删除

    VS2017加装MFC以及创建第一个MFC程序_赵满刚的博客-CSDN博客 MFC读取Excel文件+数据处理+写入Excel_土豪gold的博客-CSDN博客 VS2013 MFC连接Access数据库(ADO)详细版实例操作(含Combo Box读取数据库内容,附源码)_土豪gold的博客-CSDN博客_mfc连接access数据库 MFC 导入EXCEL到数据库_weixin_338

    2024年02月06日
    浏览(34)
  • 基于MFC的图书馆图书管理系统 VC++操作Excel文档的方法,读取,查询,写入,修改,删除

    VS2017加装MFC以及创建第一个MFC程序_赵满刚的博客-CSDN博客 MFC读取Excel文件+数据处理+写入Excel_土豪gold的博客-CSDN博客 VS2013 MFC连接Access数据库(ADO)详细版实例操作(含Combo Box读取数据库内容,附源码)_土豪gold的博客-CSDN博客_mfc连接access数据库 MFC 导入EXCEL到数据库_weixin_338

    2024年02月06日
    浏览(39)
  • MFC第十四天 BS_按钮属性与CButton类功能简介 、静态文本的穿透属性与显示密码开发、CS架构客户端的账号管理功能添加功能开发

    CButton类简介: a)CButton在VC6.0等早期版本,必须设置BS_BITMAP或BS_ICON才能设置图标(文字加图)。 b)近期VS版本即使不设置这两种属性,也直接可以设置文字加图的模式; c)近期VS版本如果设置以上两种属性,则不显示文字只显示图; 但凡你想接收全面的基础消息(控件内的基础

    2024年02月16日
    浏览(31)
  • 【MFC】01.MFC框架-笔记

    MFC Microsoft Fundation class 微软基础类库 框架 基于Win32 SDK进行的封装 属性:缓解库关闭 属性-C/C++/代码生成/运行库/MTD 属性-常规-MFC的使用:在静态库中使用MFC,默认是使用的共享DLL,运行时库 SDK版本:开发软件的套件 WSK:开发驱动的套件 MFC基于类的管理 预编译头: Demo01.h

    2024年02月14日
    浏览(27)
  • MFC——我的第一个MFC

    我的第一个MFC是在图像软件设计课程中创建的,使用Visual Studio 2022软件,基于C++语言,依赖freeimage图像库,实现在窗口应用中对一幅图像进行各种处理功能(如中值滤波等) 微软基础类库(Microsoft Foundation Classes,简称MFC)是微软公司提供的一个类库,以C++类的形式封装了W

    2024年02月06日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包