|
|
多媒体
如何用VC++ 5.0制作应用程序真彩色启动封面
利用Visual C++的组件库中的Splash Screen组件可以很方便的在应用程序中实现Splash Screen。但是由于这个组件缺省时使用16色位图,因此很多人误认为这个组件仅支持16色位图。其实,这个组件是可以支持真彩色位图的。
1.制作封面位图、开始音乐等资源文件
制作应用程序启动封面真彩位图,建立所需要播放的声音文件等。
2.在资源中插入位图资源
打开VC++的资源编辑器,用鼠标右键单击Resources文件夹,选择Import命令,插入你所制作的真彩位图。这时VC++会弹出一个对话框,显示下列信息:
“The bitmap has been imported correctly, however because it contains more than 256 colors it cannot be loaded in the bitmap editor”。
不用担心,你的真彩位图已经被成功地插入资源里了。将其ID改为IDB_SPLASH。
3.插入Splash Screen组件
从Project菜单选择Add To Project->Components and Controls...命令,选择Developer studio components中的Splash screen组件,将对话框中的位图资源ID改为你的真彩位图的ID。然后删除VC++自动加入到资源中的缺省16色启动封面位图(可选)。编译、连接,漂亮的真彩启动封面就显示出来了。
4.增强功能
*基于对话框的应用程序
基于对话框的应用程序不能插入Splash Screen组件。利用下面的方法可以实现基于对话框的应用程序启动画面:重复上面的第1,2步骤,将已经生成的Splash.cpp和Splash.h文件(可以使用其他项目的文件)拷贝到工作文件夹,并将其加入到你的基于对话框的项目中(使用Project菜单下的Add To Project->Files...命令)。
在CWinApp派生类的InitInstance()中加入下列代码:
#include "Splash.h"
BOOL CDialogsplApp::InitInstance()
{
// CG: The following block was added by the Splash Screen component.
{
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
}
......
}
使用Class Wizard为在CDialog派生类添加OnCreate()函数,并加入下列代码:
#include "Splash.h"
int CDialogsplDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// CG: The following line was added by the Splash Screen component.
CSplashWnd::ShowSplashScreen(this);
return 0;
}
最后将Splash.cpp文件中的CSplashWnd::Create()函数中的位图资源ID改为真彩位图的ID就可以了。
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
{
if (!m_bitmap.LoadBitmap(IDB_BITMAP1))
return FALSE;
......
}
*播放音乐
在MainFrm.cpp文件的开始部分加入下列语句:
#include "mmsystem.h"//多媒体
#pragma comment(lib,"winmm.lib")//多媒体
在CMainFrame::OnCreate()函数中的ShowSplashScreen之后加入下列语句即可:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
......
// CG: The following line was added by the Splash Screen component.
CSplashWnd::ShowSplashScreen(this);
BOOL r = sndPlaySound("start.wav",SND_ASYNC|SND_NODEFAULT);//播放WAV文件
ASSERT(r);
Sleep(4500);
r = sndPlaySound("",SND_ASYNC|SND_NODEFAULT);//停止播放
return 0;
}
|
|