我们平时使用的好多软件在运行启动时都会有一个“闪屏”画面显示,一般用于标识软件的一些信息,如软件版本名称、公司等,通过查找资料发现,其实实现起来很简单,一个类就能搞定!

SplashWnd.h

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
#if !defined(AFX_SPLASHWND_H__18C1CB0F_1CFF_483B_872E_E5A78BC1239E__INCLUDED_)
#define AFX_SPLASHWND_H__18C1CB0F_1CFF_483B_872E_E5A78BC1239E__INCLUDED_

#pragma once
#endif // _MSC_VER > 1000
// SplashWnd.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CSplashWnd window

class CSplashWnd : public CWnd
{
    DECLARE_DYNAMIC(CSplashWnd)  
  
public:  
    CSplashWnd();  
    virtual ~CSplashWnd();  
  
protected:  
    virtual void PostNcDestroy();  
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);  
    afx_msg void OnTimer(UINT_PTR nIDEvent);  
    afx_msg void OnPaint();  
    BOOL Create(CWnd* pParentWnd=NULL);  
    void HideSplashScreen(void);  
    DECLARE_MESSAGE_MAP()  
  
protected:  
    CBitmap m_bitmap;  
    static CSplashWnd* c_pSplashWnd;  
    static BOOL c_bShowSplashWnd;  
  
public:  
    static void EnableSplashScreen(BOOL bEnable=TRUE);  
    static void ShowSplashScreen(CWnd* pParentWnd=NULL);  
    static BOOL PreTranslateAppMessage(MSG* pMsg); 
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SPLASHWND_H__18C1CB0F_1CFF_483B_872E_E5A78BC1239E__INCLUDED_)

SplashWnd.cpp

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
 
// SplashWnd.cpp : implementation file
//
#include "stdafx.h"  
#include "SplashWnd.h"  
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif  
  
/////////////////////////////////////////////////////////////////////////////
// CSplashWnd
CSplashWnd* CSplashWnd::c_pSplashWnd;  
BOOL CSplashWnd::c_bShowSplashWnd;  
IMPLEMENT_DYNAMIC(CSplashWnd, CWnd)  
  
CSplashWnd::CSplashWnd()  
{  
  
}  
  
CSplashWnd::~CSplashWnd()  
{  
    ASSERT(c_pSplashWnd == this);  
    c_pSplashWnd = NULL;  
}  
  
  
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)  
    ON_WM_CREATE()  
    ON_WM_TIMER()  
    ON_WM_PAINT()  
END_MESSAGE_MAP()  
  
  
  
// CSplashWnd Message handler 
  
void CSplashWnd::EnableSplashScreen(BOOL bEnable)  
{  
    c_bShowSplashWnd = bEnable;  
}  
  
void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd)  
{  
    if ( !c_bShowSplashWnd || c_pSplashWnd != NULL )  
    {  
        return;  
    }  
  
    c_pSplashWnd = new CSplashWnd;  
    if ( !c_pSplashWnd->Create(pParentWnd) )  
    {  
        delete c_pSplashWnd;  
    }  
    else  
    {  
        c_pSplashWnd->UpdateWindow();  
    }  
}  
  
BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)  
{  
    if ( c_pSplashWnd == NULL )  
    {  
        return FALSE;  
    }  
      
    if ( pMsg->message == WM_KEYDOWN  
        || pMsg->message == WM_SYSKEYDOWN  
        || pMsg->message == WM_LBUTTONDOWN  
        || pMsg->message == WM_RBUTTONDOWN  
        || pMsg->message == WM_MBUTTONDOWN  
        || pMsg->message == WM_NCLBUTTONDOWN  
        || pMsg->message == WM_NCRBUTTONDOWN  
        || pMsg->message == WM_NCMBUTTONDOWN)  
    {  
        c_pSplashWnd->HideSplashScreen();  
        return TRUE;  
    }  
  
    return FALSE;  
}  
  
void CSplashWnd::PostNcDestroy()  
{  
    delete this;  
}  
  
int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{  
     )  
    {  
        ;  
    }  
  
    CenterWindow();  
    SetTimer(, NULL);  
  
    ;  
}  
  
void CSplashWnd::OnTimer(UINT_PTR nIDEvent)  
{  
     )  
    {  
        HideSplashScreen();  
    }  
}  
  
void CSplashWnd::OnPaint()  
{  
    CPaintDC dc(this);  
    CDC dcImg;  
    if ( !dcImg.CreateCompatibleDC(&dc) )  
    {  
        return;  
    }  
  
    BITMAP bm;  
    m_bitmap.GetBitmap(&bm);  
  
    CBitmap* pOldBit = dcImg.SelectObject(&m_bitmap);  
    dc.BitBlt(, SRCCOPY);  
    dcImg.SelectObject(pOldBit);  
}  
  
BOOL CSplashWnd::Create(CWnd* pParentWnd)  
{  
    if ( !m_bitmap.LoadBitmap(IDB_BITMAP_SPLASH) )  
    {  
        return FALSE;  
    }  
  
    BITMAP bm;  
    m_bitmap.GetBitmap(&bm);  
    ,  
        AfxRegisterWndClass(, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),  
        NULL,  
        WS_POPUP | WS_VISIBLE,  
        ,  
        bm.bmWidth,  
        bm.bmHeight,  
        pParentWnd->GetSafeHwnd(),  
        NULL);  
}  
  
void CSplashWnd::HideSplashScreen()  
{  
    DestroyWindow();  
    AfxGetMainWnd()->UpdateWindow();  
}  

  在应用程序类的InitInstance中添加代码:

 C++ Code 
1
2
3
4
 
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// add EnableSplashScreen
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);

  在应用程序主框架窗口OnCreate中返回之前添加代码:

 C++ Code 
1
2
 
// Show Splash Window 
CSplashWnd::ShowSplashScreen(this);  

VC++ 轻松实现“闪屏” SplashWnd的更多相关文章

  1. win32 窗口缩放时出现闪屏

    今天无意发现之前写的一个小工具在缩放窗口的时候,出现闪屏,主要有两个位置: 工具栏出一闪屏 右侧的控制面板出现闪屏 (这个控制面板与多层元件组合而成) 之前真没注意到这个问题,平时都是最大化/恢复窗口 ...

  2. 在DevExpress程序中使用SplashScreenManager控件实现启动闪屏和等待信息窗口

    在我很早的WInform随笔<WinForm界面开发之"SplashScreen控件">有介绍如何使用闪屏的处理操作,不过那种是普通WInform和DevExpress ...

  3. IOS客户端UIwebview下web页面闪屏问题

    基于ios客户端uiwebview下的web页面,在其内容高度大于视窗高度时,如果点击超过视窗下文档的底部按钮,收缩内容高度,会发生闪屏问题. 外因是由文档的高度大于视窗的高度所致,本质原因未知. 解 ...

  4. 设置 phoneGap/Cordova 3.4 应用程序启动动画闪屏 SplashScreen

    当Cordova 程序打包并安装到手机中后,我们会发现启动程序时,会有数秒的黑屏现象,常见的解决方法则是设置闪屏后面. 这里以 Android 程序为例,介绍Cordova设置启动画面的方法. 1. ...

  5. android 的闪屏效果

    android的闪屏效果,就是我们刚开始启动应用的时候弹出的界面或者动画,过2秒之后自动的跳转到主界面. 其实,实现这个效果很简单,使用Handler对象的postDelayed方法就可以实现.在这个 ...

  6. Android如何避免切换至SurfaceView时闪屏(黑屏闪一下)以及黑屏移动问题

    1.最近的项目中,有一个Activity用到Fragment+ViewPager,其中一个fragment中实现了视频播放的功能,包含有SurfaceView.结果,每次打开程序第一次进入到该Acti ...

  7. Phonegap之ios对iPhone6和Plus的闪屏适配 -- xmTan

    故事的发生起于,由于老板强烈要求app在iPhone6和5有一样的工具栏,然后前端妹子用@media为iPhone6和Plus做了样式适配.然后问题来了,竟然奇葩的发现@media样式只对iPhone ...

  8. jquery mobile 转场闪屏的解决

     jqm转场闪屏是用phonegap生成apk非常容易遇到的问题,暂时貌似还是没有完美的解决方案,网上暂时有一些方案,个人都尝试了一下发现还是改背景比较有效,总结如下: 改变默认css文件: .ui- ...

  9. Android 实现闪屏页和右上角的倒计时跳转

    效果图: 闪屏页用到了handler和CountDownTimer类,还需配置一下Activity的主题,这里是:android:theme="@android:style/Theme.No ...

随机推荐

  1. 关于为什么要在项目中使用FTP文件服务器

    传统的上传一般做法是http上传,后台接收文件流,然后写入到服务器本地硬盘的某个位置. 如果我们想把文件单独存放在别的服务器上,那就可以借助ftp服务器了. 上传的流程则变为,http上传,后台接收文 ...

  2. Mysql导入大SQL文件数据问题

    如果sql文件过大,会出现mysql out of memory  (Needed XXX bytes) ,或者 "MySQL server has gone away"问题; 另 ...

  3. POJ 2750 Potted Flower (单点改动求线段树上最大子序列和)

    题目大意: 在一个序列上每次改动一个值,然后求出它的最大的子序列和. 思路分析: 首先我们不考虑不成环的问题.那就是直接求每一个区间的最大值就好了. 可是此处成环,那么看一下以下例子. 5 1 -2 ...

  4. quartz cron表达式在线生成

    近期使用了quartz定时器,有感于起cron表达式有点复杂.且无法实时推断定时时间是否正确,因此写了个在线表达式及依据表达式获得前10次运行时间. 訪问地址例如以下:http://cron.g2ro ...

  5. Javascript中window.opener的一点小总结

    以前一直认为window.opener只有在window.open方法打开下的窗口才可以访问,没想到即使是a链接打开的页面的照样可以访问.window.opener指向父窗口,也就是来源窗口.可以利用 ...

  6. plink参数说明

    Plink: command-line connection utilityRelease 0.67Usage: plink [options] [user@]host [command]       ...

  7. Delphi 全局画点TCanvas.Pixels[X,Y]

    procedure TForm1.btnChangePixelClick(Sender: TObject); var baseX : integer ; baseY : integer ; i,j : ...

  8. gdb前端: VIM+Pyclewn 调试C/C++

    (gdb) mapkeys C-B : break "${fname}":${lnum} # set breakpoint at current line C-D : down C ...

  9. svn lock 锁定文件

    [root@NGINX-APACHE-SVN pro]# svn lock zh_CN.UTF-8 'zh_CN.UTF-8' locked by user 'svnroot'. [root@NGIN ...

  10. Spring学习11-Spring使用proxool连接池 管理数据源

    Spring 一.Proxool连接池简介及其配置属性概述   Proxool是一种Java数据库连接池技术.是sourceforge下的一个开源项目,这个项目提供一个健壮.易用的连接池,最为关键的是 ...