您的位置:首页 > 其它

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

2011-07-26 18:59 344 查看
#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函数即可.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐