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

📄 aboutsplashdlg.cpp

📁 一些关于C++开发的多媒体制作书籍的源代码
💻 CPP
字号:
/*
* Copyright (c) 2002, Bcdliang
* All rights reserved.
*
* 文件名称:AboutSplashDlg.cpp
* 摘    要:::ShowAbout, 显示About Box
*           ::ShowSplash, 显示Splash Screen
*           AboutSplashThreadProc, 显示About Box或Splash Screen的工作者线程响应函数
*           类CAboutSplashDlg的实现
*
* 当前版本:1.01
* 作    者:LIANG Zheng
* 完成日期:2002年8月11日
*/

#include "stdafx.h"
#include "Resource.h"
#include "AboutSplashDlg.h"

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

const UINT ASD_SPLASHTIMER         = 1;
const UINT ASD_LOADINGTIMER        = 2;

// when signaled, specified the splash screen has been closed
HANDLE g_hSplashClosedFlag = ::CreateEvent(NULL, true, false, NULL);

// when true, demand the splash screen to be closed
BOOL g_bCloseSplashFlag = false;

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:::AboutSplashThreadProc
* 函数介绍:Thread proc to show the about box or splash screen
* 输入参数:LPVOID pParam, true=about, false=splash
* 输出参数:无
* 返回值  :无
*/
UINT AboutSplashThreadProc(LPVOID pParam)
{
	BOOL bAbout = (BOOL)pParam;
	CAboutSplashDlg dlg(bAbout)/*IDD_ABOUTBOX, wnd*/;
	dlg.DoModal();
	return 0;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:::ShowSplash
* 函数介绍:显示或隐藏Splash screen
* 输入参数:BOOL bShow, true=Show, false=hide
* 输出参数:无
* 返回值  :无
*/
void ShowSplash(BOOL bShow)
{
	if (bShow)
	{
		::g_bCloseSplashFlag = false;
		AfxBeginThread(AboutSplashThreadProc, (void *)false);	// Show Splash screen
	}
	else
	{
		::g_bCloseSplashFlag = true;
		// while (WaitForSingleObject(::g_hSplashClosedFlag, 0) == WAIT_TIMEOUT);
		// Hey! WaitForSingleObject is much better than the while loop above!
#ifndef _DEBUG
		// Wait until the splash screen has been close
		WaitForSingleObject(::g_hSplashClosedFlag, INFINITE);
#endif
	}
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:::ShowAbout
* 函数介绍:Show the about box
* 输入参数:无
* 输出参数:无
* 返回值  :无
*/
void ShowAbout()
{
	AfxBeginThread(AboutSplashThreadProc, (void *)true);	// Show Splash screen
/*	CAboutSplashDlg dlg(true);
	dlg.DoModal();
*/}

/////////////////////////////////////////////////////////////////////////////
// CAboutSplashDlg dialog


CAboutSplashDlg::CAboutSplashDlg(BOOL bAbout, CWnd* pParent /*=NULL*/)
	: CDialog(CAboutSplashDlg::IDD, pParent)
{
	this->m_bAbout = bAbout;
	//{{AFX_DATA_INIT(CAboutSplashDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bkBrush.CreateSolidBrush(RGB(185, 220, 255));
	m_fLoading.CreateFont(234,0,0,0,FW_BOLD,0,0,0,0,0,0,0,0,_T("宋体"));
}

CAboutSplashDlg::~CAboutSplashDlg()
{
	m_bkBrush.DeleteObject();
	m_fLoading.DeleteObject();
}

void CAboutSplashDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutSplashDlg)
	DDX_Control(pDX, IDC_LOADING, m_Loading);
	DDX_Control(pDX, IDC_EMAIL, m_Email);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAboutSplashDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutSplashDlg)
	ON_WM_TIMER()
	ON_WM_CTLCOLOR()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAboutSplashDlg message handlers


BOOL CAboutSplashDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	if (!this->m_bAbout)
	{
		this->SetTimer(::ASD_SPLASHTIMER, 100, NULL);
		this->SetTimer(::ASD_LOADINGTIMER, 200, NULL);
		(CButton *)GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
	}
	else
	{
		m_Loading.SetFont(&m_fLoading, FALSE);
		m_Loading.ShowWindow(SW_HIDE);
	}

	m_Email.Initialize();
	m_Email.SetTextVAlign(CScrollLabel::SL_TA_VCENTER);
	m_Email.SetTextColor(RGB(0, 255, 0));
	m_Email.SetScrollStyle(CScrollLabel::SL_HSCROLLBOTH);

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

void CAboutSplashDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (nIDEvent == ::ASD_SPLASHTIMER)
	{	static UINT nTime = 0;
		nTime += 100;
		// End the splash screen if it had been shown for 2000 ms
		if (nTime > 2000)
		{
			this->EndDialog(IDOK);
			return;
		}
	
		// End the splash screen if the close flag is set
		if (::g_bCloseSplashFlag)
		{
			// Can't be SendMessage(WM_CLOSE) or DestroyWindow() here
			this->EndDialog(IDOK);
			return;
		}
	}
	else if (nIDEvent == ::ASD_LOADINGTIMER)
	{	// add some dynamic effect
		static UINT nDots = 1;
		UINT i;
		CString str=_T("");
		for (i=0; i<nDots; i++)
			str += ".";
		m_Loading.SetWindowText("Loading" + str);
		nDots = nDots % 6 + 1;
	}
	
	CDialog::OnTimer(nIDEvent);
}

HBRUSH CAboutSplashDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if (pWnd == &m_Email)
		return hbr;
	// set bk color and text color if it's a static control
	if (nCtlColor == CTLCOLOR_STATIC)
	{
		pDC->SetBkColor(RGB(185, 220, 255));
		pDC->SetTextColor(RGB(0, 0, 128));
	}
/*	else if (nCtlColor == CTLCOLOR_DLG)
	{
		for (int i=0; i<1000; i++)
			for (int j=0; j<1000; j++)
				pDC->SetPixelV(i, j, RGB(22,1,1));
		return hbr;
	}
*/
	// paint the ctl with a different brush
	return this->m_bkBrush;
//	return hbr;
}

void CAboutSplashDlg::OnOK() 
{
	// TODO: Add extra validation here
	// if it's a splash screen, then the Enter key is disabled
	if (this->m_bAbout)
		CDialog::OnOK();
}

void CAboutSplashDlg::OnCancel() 
{
	// TODO: Add extra validation here
	// if it's a splash screen, then the Esc key is disabled
	if (this->m_bAbout)
		CDialog::OnCancel();
}

void CAboutSplashDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	// imform the caller that the splash is to be closed
	SetEvent(::g_hSplashClosedFlag);
}


⌨️ 快捷键说明

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