纯C++打造的Splash Screen类(打造专业的启动画面)

Introduction

每一个应用程序可能都需要一个“about box”和程序启动时一个“splash screen”(启动画面),大多数开发者都使用自带的““about dialog””。我创建了一个类CSplashScreen,都可以处理这两者,使开发变的容易,有趣!从小的对话框组件程序到需要加在几分复杂程序,我都会使用这个类。


这个类有两个文件组成,SplashScreen.hSplashScreen.cpp。这个类不需要MFC和.NET的支持!


这个类可以从资源编辑器中获取很多信息包括位图,版本字符串等等,显示在“splash screen”上。因此,在程序版本改变的时候,你不需要修改splash screen。


当程序启动时splash screen就会显示,有键盘按下,或者设定时间已过,splash screen就会消失。


Splash Screen Example





Using the code

  • 包含SplashScreen.hSplashScreen.cpp.
  • 在资源编辑器中添加版本字符串
  • 在资源编辑器中添加位图IDB_SPLASH
  • 在连接库添加version.lib


ShowSplashScreen(HWND pParentWnd, LPCTSTR statusMessage, int millisecondsToDisplay) 函数有三个参数。

  • pParentWnd - splash screen的父窗口指针
  • statusMessage - 显示在splash screen状态栏里的字符串
  • millisecondsToDisplay - splash screen持续时间


为了显示splash screen,需要在程序初始化时,添加CSplashScreen::ShowSplashScreen();

#include "SplashScreen.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
    MSG msg;
    
    // display splash screen and have it turn off after 10 seconds
    CSplashScreen::ShowSplashScreen( hWnd, "http://applehome.com/", 10000);
  .
  .
  .
    while (GetMessage(&msg, NULL, 0, 0))  {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return msg.wParam;
}


为了显示about box,在 WndProc(…)中添加 CSplashScreen::ShowSplashScreen()

#include "SplashScreen.h"

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case WM_COMMAND:
        // Parse the menu selections:
        switch (LOWORD(wParam)) {
        case IDM_ABOUT:
            // display about box
            CSplashScreen::ShowSplashScreen( hWnd );
            break;
        }
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}


Under the hood

因为我是个顾问,为每一个客户需要创建指定的位图。一般我会特别放置公司的logo和应用程序的icon在 IDB_SPLASH位图上。能否创造一个专业的splash screen.取决于你们天才的设计师。版本字符串时写在位图之上的。

有三组字符串:Product Name,Body,和Status。Body是由company name, version, copyright, 和 comment strings一个或多个组成。


每一组 都有指定字符串在该组如何显示的静态变量:

  • m_xxxVerticalOffset - empty space between the top of the bitmap and the first string
  • m_xxxVerticalHeight - the maximum height of a group of strings
  • m_xxxLeftMargin - the distance from the left side to the place strings
  • m_xxxRightMargin - the distance from the right side to strings
  • m_xxxFontName - the name of the font for strings
  • m_xxxPointSize - the point size used for strings, (-1,-1) ==> Calculate point size
  • m_xxxTextColor - the color used for strings
Body有可以有0-4个字符串,设置其是否显示的变量:

  • m_displayCompanyName - true if displaying company name
  • m_displayVersion - true if displaying version
  • m_displayCopyright - true if displaying copyright
  • m_displayComments - true if displaying comments

CSplashScreen类是在CSplashScreen::ShowSplashScreen()被调用时实例化,键盘按下或者时间超过时,被删除。


最后,文章的例子代码,CSplashScreen代码下载地址:http://download.csdn.net/detail/chenjintaoxp/7634865


                
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值