单文档应用程序
ResourseView-> import 命令-〉插入一个真彩色位图 (由于超过256色,所以不能再VC位图编辑器中显示)-〉ID 设为IDB_SPLASH
Project-> Add To Project| Components and Controls -> Visual C++ Components -> Splash Screen 组件-〉ID 设为IDB_SPLASH
P.S. 在CSplashWnd 类的Oncreate 函数中有以下代码:SetTimer(1, 750, NULL);
通过修改第二个参数可以设置启动封面显示的时间, 默认是750ms
基于对话框的程序
基于对话框的程序不能直接插入Splash Screen 组件
将单文档应用程序中生成的Splash.cpp 和Splash.h 文件拷贝到本对话框程序的文件夹中。 Project -> Add to Project|Files 将这两个文件加入到项目中。
在CWindApp的派生类(e.g. Client_Puzzle_V1.cpp) 的:InitInstance函数中加入
BOOL CClient_Puzzle_V1App::InitInstance()
{
AfxEnableControlContainer();
//这里开始添加我的东西, 使得启动封面变为有效状态
CCommandLineInfo cmdInfo;
ParseCommandLine (cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
。。。。。
}
使用MFC ClassWizard 为CDialog 派生类添加OnCreate 函数, 加入以下代码:
int CClient_Puzzle_V1Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CSplashWnd::ShowSplashScreen(this); //
显示启动封面
return 0;
}
将Splash.cpp 文件中的Create 函数中的位图资源ID 改为真彩位图的ID:
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
{
if (!m_bitmap.LoadBitmap(IDB_SPLASH)) //
要显示的真彩位图的
ID
return FALSE;
。。。。
}