基于对话框的工程实现。
1. 手动添加CSplashWnd类
SplashWnd.h
#ifndef _SPLASH_HEADER_
#define _SPLASH_HEADER_
#pragma once
//#include "afxwin.h"
// CSplashWnd
class CSplashWnd : public CWnd
{
//DECLARE_DYNAMIC(CSplashWnd)
public:
CSplashWnd();
virtual ~CSplashWnd();
virtual void PostNcDestroy();
public:
CBitmap m_bitmap;
protected:
static BOOL c_bShowSplashWnd;
static CSplashWnd* c_pSplashWnd;
public:
static void EnableSplashScreen(BOOL bEnable = TRUE);
static void ShowSplashScreen(CWnd* pParentWnd = NULL);
static BOOL PreTranslateAppMessage(MSG* pMsg);
protected:
BOOL Create(CWnd* pParentWnd = NULL);
void HideSplashScreen();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
protected:
DECLARE_MESSAGE_MAP()
};
#endif
SplashWnd.cpp
#include "stdafx.h"
#include "resource.h"
#include "SplashWnd.h"
// CSplashWnd
//IMPLEMENT_DYNAMIC(CSplashWnd, CWnd)
BOOL CSplashWnd::c_bShowSplashWnd = FALSE;
CSplashWnd* CSplashWnd::c_pSplashWnd;
CSplashWnd::CSplashWnd()
{
}
CSplashWnd::~CSplashWnd()
{
// Clear the static window pointer.
ASSERT(c_pSplashWnd == this);
c_pSplashWnd = NULL;
}
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
void CSplashWnd::EnableSplashScreen(BOOL bEnable )
{
c_bShowSplashWnd = bEnable;
}
void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd )
{
if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
return;
// Allocate a new splash screen, and create the window.
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 we get a keyboard or mouse message, hide the splash screen.
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; // message handled here
}
return FALSE; // message not handled
}
BOOL CSplashWnd::Create(CWnd* pParentWnd )
{
if (!m_bitmap.LoadBitmap(IDB_SPLASH)) //IDB_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()
{
// Destroy the window, and update the mainframe.
DestroyWindow();
AfxGetMainWnd()->UpdateWindow();
}
void CSplashWnd::PostNcDestroy()
{
// Free the C++ class.
delete this;
}
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, 1000, NULL);
return 0;
}
void CSplashWnd::OnPaint()
{
CPaintDC dc(this);
CDC dcImage;
if (!dcImage.CreateCompatibleDC(&dc))
return;
BITMAP bm;
m_bitmap.GetBitmap(&bm);
// Paint the image.
CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
dcImage.SelectObject(pOldBitmap);
}
void CSplashWnd::OnTimer(UINT nIDEvent)
{
// Destroy the splash screen window.
HideSplashScreen();
}
2. 为CSplashWnd类 的Oncreate 函数添加如下代码 //WM_CREATE
CenterWindow();
// Set a timer to destroy the splash screen.
SetTimer(1, 1000, NULL);//1000 表画面停止时间
3.为CSplashWnd类 的OnTimer函数添加如下代码//WM_TIMER
HideSplashScreen();
4. 为CNetTesterDlg的 Oncreate函数添加如下代码//WM_CREATE
CenterWindow();
CSplashWnd::ShowSplashScreen(this);
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
// this->MoveWindow(0,0,0,0);
// this->SetTimer(1,2000,NULL);//注意这个2000一点要等于步骤1中的2000
Sleep(1000);//使得 画面停止约 1s后 启动主画面,貌似可以用定时器,希望大虾指教。 1000 要与SetTimer中1000 同步,使画面链接流畅
return 0;
5. 完毕
分享到:
相关推荐
Splash screen组件是添加启动画面的时候要用到的,但是在基于对话框的工程下是不能直接添加的,如果把这个文件添加到工程目录下酒能用这个组件了
20.8.2 在基于对话框程序中实现打印及打印预览 20.9 异常处理 20.10 程序设计清单 20.11 技术、经验总结 20.11.1 技术总结 20.11.2 经验总结 20.12 系统的编译与发行 第21章 Visual C++ 6.0在学生管理系统中的应用 ...
20.8.2 在基于对话框程序中实现打印及打印预览 20.9 异常处理 20.10 程序设计清单 20.11 技术、经验总结 20.11.1 技术总结 20.11.2 经验总结 20.12 系统的编译与发行 第21章 Visual C++ 6.0在学生管理系统中的应用 ...
Android 一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导开发 IOS 由苹果公司开发的移动操作系统 Webkit 一个开源的浏览器引擎,在手机上的...
支持单画面、4画面、9画面、16画面、20画面、25画面显示,可全屏显示,支持自动 翻页; 多画面实时显示/录像/回放功能,支持多协议云镜控制,支持多种报警盒实现联动报警; 手动录像、连续录像、定时录像、动态...
2 项目参数设置 ME是基于项目管理的编辑产品,启动系统时需要选择或新建项目,设置相应的视频制 式标准和视音频模板。初次启动项目时,系统会提示是否需要修改项目设置,选择"是" ,则可进入项目参数设置窗口. 在...
基于PCX的传真图像;宏 DIR:MacromediaDirector文件 DLL:动态链接库 DOC:FrameMaker或FrameBuilder文档;Word Star文档、Word Perfect文档、Microsoft:Word文档;DisplayWrite文档 DOT:Microsoft Word文档...
使用AD Explorer,用户可以快捷地浏览AD数据库,自定义快速入口,无需打开对话框即可查看对象属性、编辑权限、浏览一个对象的模式、 进行精确搜寻等。 AdRestore Server 2003 引入了还原已删除(“已逻辑删除的...