现在的位置: 首页 > 综合 > 正文

如何制作启动界面 C+/VC

2013年09月03日 ⁄ 综合 ⁄ 共 1552字 ⁄ 字号 评论关闭
 如何制作启动界面 C+/VC

实现闪屏
一、安装splash screen组件 
点击菜单project/add to project/component and control,然后双击”visual c++ components” , 
选中splash screen组件,接受默认id为 idb_splash.(笔者在此处有疑问,接受默认的id时当程序运行时总没有闪屏出现,重新取个id就可以了,试试看!)
二、插入位图
用一幅准备好的真彩位图替换刚才生成的即可。真彩位图在资源编辑器(它不能打开超过256色的图片)中是不可视的!或者,点击resouce view ,在bitmap上点击鼠标右键,选中“import…”菜单项,然后选你所要的真彩位图资源,把位图的id设置为idb_splash.。
  三、运行程序
编译、连接,漂亮的真彩启动位图就显示出来了。就这么简单!
四、几点说明
   1.如果你要改变启动画面的停留时间,就修改settime 中的第二个参数,这里是750毫秒。int csplashwnd::oncreate(lpcreatestruct lpcreatestruct)
{
     if (cwnd::oncreate(lpcreatestruct) == -1)
        return -1;

     // center the window.
     centerwindow();

     // set a timer to destroy the splash screen.
     settimer(1, 750, null);  此停留时间为0。75秒,可通过修改第二个参数来改变闪屏时间!    

     return 0;
}
2.基于对话框的程序不能插入闪屏,可如下设置:
首先创建一对话框工程,将刚才已经生成的splash.cpp和splash.h文件拷贝到工作文件夹,并将其加入到你的基于对话框的项目中(project->add to project->files...)。
在cdialogapp派生类的initinstance()中加入下列代码:
#include "splash.h"
bool cdialogapp::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 cdialogldlg::oncreate(lpcreatestruct lpcreatestruct)
{
    if (cdialog::oncreate(lpcreatestruct) == -1)
        return -1;
    // cg: the following line was added by thesplash 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;
        ......
}

抱歉!评论已关闭.