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

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_

#if _MSC_VER > 1000
#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)  
{  
    if ( CWnd::OnCreate(lpCreateStruct) == -1 )  
    {  
        return -1;  
    }  
  
    CenterWindow();  
    SetTimer(1, 3000, NULL);  
  
    return 0;  
}  
  
void CSplashWnd::OnTimer(UINT_PTR nIDEvent)  
{  
    if ( nIDEvent == 1 )  
    {  
        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(0, 0, bm.bmWidth, bm.bmHeight, &dcImg, 0, 0, SRCCOPY);  
    dcImg.SelectObject(pOldBit);  
}  
  
BOOL CSplashWnd::Create(CWnd* pParentWnd)  
{  
    if ( !m_bitmap.LoadBitmap(IDB_BITMAP_SPLASH) )  
    {  
        return FALSE;  
    }  
  
    BITMAP bm;  
    m_bitmap.GetBitmap(&bm);  
    return CreateEx(0,  
        AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),  
        NULL,  
        WS_POPUP | WS_VISIBLE,  
        0, 0,  
        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);  

转载于:https://www.cnblogs.com/MakeView660/p/6915975.html

VC++ 轻松实现“闪屏” SplashWnd相关推荐

  1. Macbook出现闪屏现象怎么办?

    在使用Macbook的过程中,总会出现一些小问题.你的Macbook苹果笔记本出现过闪屏现象吗?Macbook笔记本在使用的时候屏幕总是闪烁,影响使用,该怎么办呢?不要急,macz小编教你几招,帮你轻 ...

  2. Macbook出现闪屏现象怎么办?macz小编帮你支招!

    在使用Macbook的过程中,总会出现一些小问题.你的Macbook苹果笔记本出现过闪屏现象吗?Macbook笔记本在使用的时候屏幕总是闪烁,影响使用,该怎么办呢?不要急,macz小编教你几招,帮你轻 ...

  3. vc关于dialog绘图闪屏和多层覆盖的处理方法

    1.加载背景图,刷新时闪屏: 用双缓存: CDC *pDC=GetDC();   CDC memDC;   memDC.CreateCompatibleDC(pDC);      CBitmap bi ...

  4. 计算机进到系统闪屏没有桌面,电脑闪屏了?几个步骤可以轻松解决

    在使用电脑的时候你有没有遇到过电脑屏幕突然闪屏的情况呢?关于电脑闪屏的现象在日常使用中也常有发生,这种现象一般是我们电脑显示器的显示问题,很多用户都会认为是电脑运行速度太过缓慢的原因,其实并不是这方面 ...

  5. 【转载】用外部程序启动AutoCAD方法的研究(启动闪屏制作与CreateProcess启动操控AutoCAD探索)

    第1 页 用外部程序启动AutoCAD 方法的研究 --- 启动闪屏制作与CreateProcess 启动操控AutoCAD 探索 作者:七彩云南(QQ) QQ:420304230 E-mail:Ay ...

  6. java闪屏怎么制作,Java Swing创建自定义闪屏:在闪屏下画进度条(一)

    Java Swing创建自定义闪屏:在闪屏上画进度条(一) 由于本人十分热爱Java Swing,所以平时闲暇之余总是喜欢极尽所能去搜藏一些自认为比较"酷"的Swing代码来研究揣 ...

  7. 251f与ips屏显示器对比_不闪屏,HDR,带鱼屏全都有,LG 29WK600宽屏显示器测评

    大家好,我是黄昏百分百,今天为大家带来的是LG 29WK600宽屏显示器的测评报告. 前言 这几年HDR的片源越来越多了,HDR技术能够给视频与游戏更出色的视觉体验,但是,享受HDR的前提条件就是拥有 ...

  8. 电脑显示器闪屏_时尚超薄可升降:华硕新品家用护眼显示器MZ27AQL

    据悉,华硕一款全新的家用护眼显示器即将上市了,该显示器为2018年发布的MZ27AQL,纤薄机身,窄边框设计,还有可升降的旋转支架,时尚中带着无比的实用性.还有大家最喜欢的专业护眼功能,时刻守护全家的 ...

  9. php闪屏程序,节日闪屏的两种构成方式

    > 摘要: 每逢节日到来,当你打开QQ浏览器,发现有什么不同吗?QQ浏览器已经悄悄的送出了节日的关怀,呈现在你眼前的是朴实而又温情的画面节日闪屏.她是浏览器和用户情感交流的窗口,也 每逢节日到来 ...

最新文章

  1. Java项目:平行志愿管理系统(java+Springboot+Maven+mybatis+Vue+Mysql)
  2. 思想实验(逻辑思维)解题
  3. Swift之深入解析可选链的功能和使用
  4. BZOJ3743 : [Coci2014]Kamp
  5. 中文-自然语言处理-开源工具-流行度调查+句法依存树可视化调研
  6. SQLServer常用系统视图
  7. 双11特刊|购物车实时显示到手价,看云原生内存数据库Tair如何提升用户体验?
  8. Struts+iBatis+Spring+mysql整合开发
  9. linux voip客户端,linux搭建VOIP
  10. 第二次冲刺阶段第三天
  11. Linux命令解释之head
  12. WP7模拟器使用技巧
  13. python函数式编程模式_Python 函数式编程
  14. 私塾在线java设计模式综合项目实战
  15. Drools规则引擎使用入门
  16. js读取服务器excel文件是否存在,js读取Excel文件
  17. 很多的计算机英语词汇是通过,计算机英语词汇隐喻分析
  18. 路由器虚拟服务器 数量,tp-link1660+路由器端口映射的数量有多少
  19. BLE MESH中的Secure Network beacon包
  20. 其实EXCEL也是一个很好的管理程序开发工具

热门文章

  1. 阿里云安全运营中心:DDoS攻击趁虚而入,通过代理攻击已成常态
  2. RTX3090 Super曝光:完整GA102核心加持、性能提升5%
  3. asp:DropDownList用法
  4. 微信小程序家庭记账本开发进度二
  5. linux c/c++ 文件是否存在
  6. 牛客网暑期ACM多校训练营(第三场)A.PACM Team(多重01背包)
  7. 杂项-QRCode:ZXing
  8. Mysql 中如何创建触发器
  9. 装饰器 and 闭包函数 未完。。。。。
  10. jquery一个控件绑定多个事件