VC2008中添加启动logo

vs++6.0中有splash screen控件,在VS2008中只能手动写。
头文件

/************************************************************************/
/*
Description: 实现程序启动时显示logo画面,(测试版本VS2008)
*/
/************************************************************************/

// 使用方法: 只需在MFC工程中的CMainFrame类中添加消息OnCreate,
// 并在函数定义中添加语句CSplashWnd::ShowSplashScreen(this);
// 同时把位图资源添加进去,并设置好logo消隐时间
// 还要再app和mainFram对应的cpp文件中包含头文件SplashWnd.h

#pragma once
#include"afxwin.h"

classCSplashWnd:
publicCWnd
{
public:
CSplashWnd(void);
~CSplashWnd(void);
CBitmap m_bitmap;
staticvoidShowSplashScreen(CWnd* pParentWnd = NULL);
protected:
BOOL Create(CWnd* pParentWnd = NULL);
staticCSplashWnd* c_pSplashWnd;
public:
DECLARE_MESSAGE_MAP()
afx_msg intOnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg voidOnPaint();
afx_msg voidOnTimer(UINT_PTR nIDEvent);
};

源文件

/************************************************************************/
/*
Description: 实现程序启动时显示logo画面,(测试版本VS2008)
*/
/************************************************************************/
#include"StdAfx.h"
#include"SplashWnd.h"
#include"resource.h"

CSplashWnd*CSplashWnd::c_pSplashWnd;

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

CSplashWnd::CSplashWnd(void)
/*: c_pSplashWnd(NULL)*/
{
}

CSplashWnd::~CSplashWnd(void)
{
}

voidCSplashWnd::ShowSplashScreen(CWnd* pParentWnd)
{
c_pSplashWnd =newCSplashWnd;
if(!c_pSplashWnd->Create(pParentWnd))
delete c_pSplashWnd;
else
c_pSplashWnd->UpdateWindow();
}

BOOL CSplashWnd::Create(CWnd* pParentWnd)
{
if(!m_bitmap.LoadBitmap(IDB_BITMAP1))/*加载位图资源,需在资源文件中添加*/
return FALSE;

BITMAP bm;
m_bitmap.GetBitmap(&bm);

returnCreateEx(0,
AfxRegisterWndClass(0,AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
NULL, WS_POPUP | WS_VISIBLE,0,0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
return0;
}

intCSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct)==-1)
return-1;

// TODO: 在此添加您专用的创建代码
// Center the window.
CenterWindow();

// Set a timer to destroy the splash screen.
SetTimer(1,3000, NULL);/*设置消隐时间*/

return0;
}

voidCSplashWnd::OnPaint()
{
CPaintDC dc(this);// device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CWnd::OnPaint()
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);
}

voidCSplashWnd::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
DestroyWindow();
AfxGetMainWnd()->UpdateWindow();

CWnd::OnTimer(nIDEvent);
}

posted @ 2013-09-13 15:06  ★末日3000  阅读(218)  评论(0)    收藏  举报