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

📄 theappdoc.cpp

📁 MFC DLL的编写和调用示例
💻 CPP
字号:
// TheAppDoc.cpp : implementation of the CTheAppDoc class
//

#include "stdafx.h"
#include "TheApp.h"

#include "Imports.h"
#include "TheAppDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTheAppDoc

IMPLEMENT_DYNCREATE(CTheAppDoc, CDocument)

BEGIN_MESSAGE_MAP(CTheAppDoc, CDocument)
	//{{AFX_MSG_MAP(CTheAppDoc)
	ON_COMMAND(ID_DIALOGS_DIALOGA, OnDialogsDialoga)
	ON_COMMAND(ID_DIALOGS_DIALOGA2, OnDialogsDialoga2)
	ON_COMMAND(ID_DIALOGS_DIALOGB, OnDialogsDialogb)
	ON_COMMAND(ID_DIALOGS_DIALOGC, OnDialogsDialogc)
	ON_COMMAND(ID_DIALOGS_DIALOGB2, OnDialogsDialogb2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTheAppDoc construction/destruction

CTheAppDoc::CTheAppDoc()
{
	// TODO: add one-time construction code here

}

CTheAppDoc::~CTheAppDoc()
{
}

BOOL CTheAppDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

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

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CTheAppDoc serialization

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

/////////////////////////////////////////////////////////////////////////////
// CTheAppDoc diagnostics

#ifdef _DEBUG
void CTheAppDoc::AssertValid() const
{
	CDocument::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CTheAppDoc commands

void CTheAppDoc::OnDialogsDialoga() 
{
	// This function does not need to have the CDialogA class exported, only
	// will need to see the ShowDialogA function exported from the dll.
	CString	sTheText = "Text String Stating in DialogA.";

	ShowDialogA( sTheText );
	// It should be different now if the user changed it.
}

void CTheAppDoc::OnDialogsDialoga2() 
{
	CDialogA	dlg;
	dlg.m_sEdit = "Text String Stating in DialogA using method 2.";
	// Typical Dialog usage can be done here.
	dlg.DoModal();	
}

void CTheAppDoc::OnDialogsDialogb() 
{
	// This function does not need to have the CDialogB class exported, only
	// will need to see the ShowDialogB function exported from the dll.
	CString	sTheText = "Text String Stating in DialogB.";

	ShowDialogB( sTheText );
}

void CTheAppDoc::OnDialogsDialogb2() 
{
	// This implementation of using the actual dialog fails. The reason 
	// is in the attempt to locate the resource template for the dialog
	// in the DLL.

	CDialogB	dlg;
	dlg.m_sText = "Text String Stating in DialogB using method 2.";
	// Typical Dialog usage can be done here.
	dlg.DoModal();	

	// Display a message telling the user that their attempt to
	// display the dialog box failed.
	AfxMessageBox( "This Calling method compiles but fails." );

}

void CTheAppDoc::OnDialogsDialogc() 
{
	CString	text = "Text String Stating in DialogC";
	ShowDialogC( text );
	
}

⌨️ 快捷键说明

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