1、添加图片资源到工程中,如IDB_BITMAP_LOGIN
2、添加自定义启动画面类CWzdSplash
(1)CWzdSplash.h文件内容:
#pragma once
// CWzdSplash
class CWzdSplash : public CWnd
{
DECLARE_DYNAMIC(CWzdSplash)
public:
CWzdSplash();
virtual ~CWzdSplash();
protected:
DECLARE_MESSAGE_MAP()
public:
CBitmap m_bitmap;
void Create(UINT nBitmapID, CWnd* pParentWnd = NULL);
afx_msg void OnPaint();
afx_msg void OnTimer(UINT_PTR nIDEvent);
};
(2)CWzdSplash.cpp文件内容:
#include "stdafx.h"
#include "CWzdSplash.h"
// CwzdSplash
IMPLEMENT_DYNAMIC(CWzdSplash, CWnd)
CWzdSplash::CWzdSplash()
{
}
CWzdSplash::~CWzdSplash()
{
}
BEGIN_MESSAGE_MAP(CWzdSplash, CWnd)
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
// CWzdSplash 消息处理程序
void CWzdSplash::Create(UINT nBitmapID, CWnd* pParentWnd)
{
m_bitmap.LoadBitmap(nBitmapID);
BITMAP bitmap;
m_bitmap.GetBitmap(&bitmap);
//CreateEx(0,AfxRegisterWndClass(0),"",WS_POPUP|WS_VISIBLE|WS_BORDER,0,0,bitmap.bmWidth,bitmap.bmHeight,NULL,0);
HWND hParentWnd = NULL;
if (NULL != pParentWnd)
{
hParentWnd = pParentWnd->m_hWnd;
}
CreateEx(0,
AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
NULL, WS_POPUP | WS_VISIBLE, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hParentWnd, NULL);
}
void CWzdSplash::OnPaint()
{
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CWnd::OnPaint()
CPaintDC dc(this); // device context forpainting
BITMAP bitmap;
m_bitmap.GetBitmap(&bitmap);
CDC dcComp;
dcComp.CreateCompatibleDC(&dc);
dcComp.SelectObject(&m_bitmap);
// draw bitmap
dc.BitBlt(0,0,bitmap.bmWidth,bitmap.bmHeight,&dcComp,0,0,SRCCOPY);
}
void CWzdSplash::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//CWnd::OnTimer(nIDEvent);
DestroyWindow(); //销毁初始画面窗口
}
3、在APP类的InitInstance函数中添加
/*启动画面*/
CWzdSplash wndSplash; //创建启动窗口类的实例
wndSplash.Create(IDB_BITMAP_LOGIN, pMainFrame);
wndSplash.CenterWindow();
wndSplash.UpdateWindow();