启动画面关闭后才显示主程序...在这过程中进行程序的初始化.

#pragma once
#include "afxwin.h"
class CSplashWnd :
	public CWnd
{
public:
	CSplashWnd(void);
	~CSplashWnd(void);
	CBitmap mBitmap;//初始画面位图
	static CSplashWnd* c_pSplashWnd;
	//指向初始画面窗口的指针
/*	c_pSplashWnd为静态成员变量,应在类的实现文件(.cpp)开头说明:*/
	//	CSplashWnd* CSplashWnd::c_pSplashWnd;
		static void ShowSplashScreen(CWnd *pParentWnd);
		virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
		//BOOL CSplashWnd::Create(CWnd *pParentWnd)
		DECLARE_MESSAGE_MAP()
		afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
		afx_msg void OnTimer(UINT_PTR nIDEvent);
		virtual void PostNcDestroy();
		afx_msg void OnPaint();
};

  

#include "StdAfx.h"
#include "SplashWnd.h"
#include "resource.h"
CSplashWnd* CSplashWnd::c_pSplashWnd;
CSplashWnd::CSplashWnd(void)
{
}


CSplashWnd::~CSplashWnd(void)
{
}


BOOL CSplashWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
	// TODO: 在此添加专用代码和/或调用基类
	if(!mBitmap.LoadBitmap(IDB_SPLASH))
		//载入位图
		return FALSE;
	BITMAP bm;
	mBitmap.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);
	//return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
 void   CSplashWnd::ShowSplashScreen(CWnd *pParentWnd)
{ //此函数传递的参数是主框架窗口
	if(c_pSplashWnd!=NULL) return;
	c_pSplashWnd=new CSplashWnd;
	RECT rect={50,50,50,50};
	if(!c_pSplashWnd->Create(NULL,NULL,NULL,rect,pParentWnd,NULL,0))
	{
		delete c_pSplashWnd;
	}
	else
	{
		c_pSplashWnd->UpdateWindow();
	}
	//显示初始画面窗口
};

BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
	ON_WM_CREATE()
	ON_WM_TIMER()
	ON_WM_PAINT()
END_MESSAGE_MAP()


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)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	DestroyWindow(); //销毁初始画面窗口
	AfxGetMainWnd()->UpdateWindow();
	//CWnd::OnTimer(nIDEvent);
}


void CSplashWnd::PostNcDestroy()
{
	// TODO: 在此添加专用代码和/或调用基类
	DestroyWindow(); //销毁初始画面窗口

	AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL);

	CWnd::PostNcDestroy();
}


void CSplashWnd::OnPaint()
{
	CPaintDC dc(this);
	CDC dcImage;
	if(!dcImage.CreateCompatibleDC(&dc)) return;
	BITMAP bm;
	mBitmap.GetBitmap(&bm);
	CBitmap* pOldBitmap=dcImage.SelectObject(&mBitmap);
	dc.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&dcImage,0,0,SRCCOPY);
}

 1.在APP中instance把选择为hide  m_pMainWnd->ShowWindow(SW_HIDE);,这样就可以保证在显示启动画面的同时,程序在启动中,并且不显示出来;2.在启动画面摧毁之后将程序显现出来AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL); 3.在mainframe里面调用ShowSplashScreen函数即可.

转载于:https://www.cnblogs.com/evilmusclepeople/archive/2011/07/26/2117560.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值