community.cpp

来自「深入浅出Visual C++入门进阶与应用实例 随书光盘 作者 何志丹」· C++ 代码 · 共 206 行

CPP
206
字号
// community.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "community.h"
#include "EditArticleChildFrame.h"

#include "EditArticle.h"
#include "ExportToHtmlChildFrame.h"
#include "ExportToHtmlView.h"
#include "ExportView.h"
#include "PreViewView.h"
#include "ExportChildFrame.h"
#include "MainFrm.h"



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

/////////////////////////////////////////////////////////////////////////////
// CCommunityApp

BEGIN_MESSAGE_MAP(CCommunityApp, CWinApp)
	//{{AFX_MSG_MAP(CCommunityApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	//}}AFX_MSG_MAP

	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCommunityApp construction

CCommunityApp::CCommunityApp()
{
	m_pArticleDocTem = NULL;
	m_pExportDocTem = NULL ;
	m_pExportHtmlDocTem = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CCommunityApp object

CCommunityApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CCommunityApp initialization

BOOL CCommunityApp::InitInstance()
{
	AfxEnableControlContainer();

	AfxInitRichEdit();
	// Standard initialization

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	//SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	//把相关信息记录在ini中

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	//动态配置数据源
	CString strDsn = "CommunityMDBBySpider" ;
	CString strMdbFileName = GetExePath() + "community.mdb" ;
	HDConfigFileTypeDataSource(strDsn,strMdbFileName);
	//加载数据库
	CDB::OpenDB();

	//从配置文件中读取
	CSetting::Init();

	CMultiDocTemplate* pDocTemplate;
	//编辑框架
	if(CSetting::IsUseDocTemplate(DOCTEMPLATE_TYPE_EDITARTICEL))
	{		
		pDocTemplate = new CMultiDocTemplate(
			IDR_EDIT_ARTICLE,
			RUNTIME_CLASS(CArticleDoc),
			RUNTIME_CLASS(CEditArticleChildFrame), // custom MDI child frame
			RUNTIME_CLASS(CEditArticleView));
		AddDocTemplate(pDocTemplate);
		m_pArticleDocTem = pDocTemplate ;
	}

	//导出框架
	if(CSetting::IsUseDocTemplate(DOCTEMPLATE_TYPE_EXPORT))
	{
		pDocTemplate = new CMultiDocTemplate(
			IDR_EXPORT,
			RUNTIME_CLASS(CArticleDoc),
			RUNTIME_CLASS(CExportChildFrame), // custom MDI child frame
			RUNTIME_CLASS(CExportView));
		AddDocTemplate(pDocTemplate);
		m_pExportDocTem = pDocTemplate ;
	}

	//导出HTML框架
	if(CSetting::IsUseDocTemplate(DOCTEMPLATE_TYPE_EXPORT_HTML))
	{
		pDocTemplate = new CMultiDocTemplate(
			IDR_EXPORTHTML,
			RUNTIME_CLASS(CArticleDoc),
			RUNTIME_CLASS(CExportToHtmlChildFrame), // custom MDI child frame
			RUNTIME_CLASS(CExportToHtmlView));
		AddDocTemplate(pDocTemplate);
		m_pExportHtmlDocTem = pDocTemplate ;
	}

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;
	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	//建立主框架的工具栏和状态栏
	pMainFrame->CreateControlBar();
	pMainFrame->ShowWindow(m_nCmdShow);	
	pMainFrame->UpdateWindow();



	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

/////////////////////////////////////////////////////////////////////////////
// CCommunityApp message handlers


int CCommunityApp::ExitInstance() 
{
	CDB::CloseDB();	
	return CWinApp::ExitInstance();
}

⌨️ 快捷键说明

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