www.gusucode.com > 基于VC编程界面编程高级应用技术源码程序 > VC界面编程高级应用技术/code/2/TaxExpert/TaxExpert.cpp

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

#include "stdafx.h"
#include "TaxExpert.h"

#include "MainFrm.h"
#include "TaxExpertDoc.h"
#include "TaxExpertView.h"
#include "Splash.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTaxExpertApp

BEGIN_MESSAGE_MAP(CTaxExpertApp, CWinApp)
	//{{AFX_MSG_MAP(CTaxExpertApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// 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()

/////////////////////////////////////////////////////////////////////////////
// CTaxExpertApp construction

CTaxExpertApp::CTaxExpertApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTaxExpertApp object

CTaxExpertApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTaxExpertApp initialization
/*
InitInstance:程序初始化函数
1、检查软件运行环境
2、限制程序运行实例
3、启用开始画面
*/

BOOL CTaxExpertApp::InitInstance()
{
	//进行数据库访问环境的测试,进行错误捕获	
	try{
		AfxDaoInit();
	}
	catch( CDaoException*e )
	{
		CString error;
		error.Format("在当前的软件环境配置不能够运行本程序! \r\n\r\n");
		error+="导致该错误的原因可能是以下几方面:\r\n\r\n";
		error+="1、未安装DAO数据组件,请安装\"安装MS-Jet 数据引擎\"!\r\n\t\
		(提示:可以在www.microsoft.com下载Mdac_typ.exe、Ddcom95.exe等相关数据库组件)\r\n";
		error+="2、如果已经安装了数据组件,请在系统中查找dao3?0.dll,\
		并使用下面的方法将之注册:\r\n";
		error+="\tregsvr32.exe /i X:\XXX\dao3?0.dll\r\n\r\n";
		error+="如果不能解决此问题,你也可以和zhoumingyang@163.net\
			联系以解决此问题。";
		MessageBox(NULL,error,"抱歉",MB_ICONSTOP|MB_OK );
		e ->Delete();
		return 0;
	}
	//确保只有一个本程序只能有一个实例在运行
	HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
	//从桌面窗口开始检查,查看在内存中的窗口有没有“税务师”窗口
	while (::IsWindow(hWndPrevious))
	{
		if (::GetProp(hWndPrevious, "660E72B2-6BF7-4897-8EF2-9C33FBC49564"))
		{
			AfxMessageBox("该程序已经有实例在运行!\n请使用任务管理器切换到该程序");
			return 0;
		}
		hWndPrevious = ::GetWindow(hWndPrevious,GW_HWNDNEXT);
		
	};
	// CG: The following block was added by the Splash Screen component.
	{
			CCommandLineInfo cmdInfo;
			ParseCommandLine(cmdInfo);
			CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
	}
	AfxEnableControlContainer();
	
#ifdef _AFXDLL
	Enable3dControls();
#else
	Enable3dControlsStatic();
#endif
	
	SetRegistryKey(_T("税务师"));
	LoadStdProfileSettings();
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CTaxExpertDoc),
		RUNTIME_CLASS(CMainFrame),     
		RUNTIME_CLASS(CTaxExpertView));
	AddDocTemplate(pDocTemplate);
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}

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

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

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CCJHyperLink	m_staticEmail;
	CCJHyperLink	m_staticAddress;
	CStatic     	m_staticDisclaimer,m_static;
	CString			m_editDisclaimer;
	CAnimateCtrl avi;
	//}}AFX_DATA

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

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_editDisclaimer = _T("");
	//}}AFX_DATA_INIT

	m_editDisclaimer.LoadString(IDS_DISCLAIMER);
	UpdateFont();
}

 int CAboutDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
 {
if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
avi.Create(WS_CHILD|WS_VISIBLE|ACS_TRANSPARENT   |ACS_CENTER   |
		WS_TABSTOP|CBS_AUTOHSCROLL,CRect(0,0,200,200),this, 888888888888);
	
	return 0;

 }
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_STATIC_MAILME, m_staticEmail);
	DDX_Control(pDX, IDC_STATIC_DISCLAIMER, m_staticDisclaimer);
	DDX_Control(pDX, IDC_STATIC_ADDRESS, m_staticAddress);
	DDX_Text(pDX, IDC_EDIT_DISCLAIMER, m_editDisclaimer);
	DDX_Control(pDX, IDC_STATIC1, m_static);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		ON_WM_CREATE()
	
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CAboutDlg::UpdateFont()
{
	NONCLIENTMETRICS ncm;
	memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
	ncm.cbSize = sizeof(NONCLIENTMETRICS);
	VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
		sizeof(NONCLIENTMETRICS), &ncm, 0));
	ncm.lfMessageFont.lfWeight = 700;
	m_Font.CreateFontIndirect(&ncm.lfMessageFont);
		
}





BOOL CAboutDlg::OnInitDialog() 
{
	
CDialog::OnInitDialog();	
	
	// set the hyperlinks and static font.
	m_staticEmail.SetURL(_T("mailto:zhoumingyang@163.net?subject=税务师软件"));
	m_staticAddress.SetURL(_T("http://nationaltax.home.chinaren.com"));
	//m_staticDisclaimer.SetFont(&m_Font);
	CString k;
	this->m_staticDisclaimer.SetWindowText("尊敬的朋友:");
	m_editDisclaimer.LoadString(IDS_STRING1);
 this->m_static.SetWindowText("联系方式");
//m_staticDisclaimer=k;

	this->RedrawWindow();
 avi.Open(IDR_AVI1);



	avi.Play(0,-1,-1);









	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

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

/////////////////////////////////////////////////////////////////////////////
// CTaxExpertApp commands

void CTaxExpertApp::UpdateFont(CFont& font, LONG lfWeight)
{
	font.DeleteObject();
	NONCLIENTMETRICS info;
	info.cbSize = sizeof(info);
	SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
	info.lfMessageFont.lfWeight = lfWeight;
	VERIFY(font.CreateFontIndirect(&info.lfMenuFont));
}

BOOL CTaxExpertApp::PreTranslateMessage(MSG* pMsg)
{
	// CG: The following lines were added by the Splash Screen component.
	if (CSplashWnd::PreTranslateAppMessage(pMsg))
		return TRUE;

	return CWinApp::PreTranslateMessage(pMsg);
}