MFC vs2008,vs2010,vs2012,vs2013启动页的实现

1、添加类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(void);  
    void Create(UINT nBitmapID);  
    afx_msg void OnPaint();  
    afx_msg void OnTimer(UINT_PTR nIDEvent);  
};  

(2)CWzdSplash.cpp

// WzdSplash.cpp : 实现文件  
//  


#include "stdafx.h"  
//#include "TinyPlusCompiler.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)  
{  
    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);  
    CreateEx(0,  
            AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),  
            NULL, WS_POPUP | WS_VISIBLE, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NULL , 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(); //销毁初始画面窗口  


2、添加这些代码之后,在主程序中:

SetRegistryKey(_T("应用程序向导生成的本地应用程序"));


///显示Splash,添加的代码///  
CWzdSplash wndSplash;                 //创建启动窗口类的实例  
wndSplash.Create(IDB_BITMAP1);  
wndSplash.CenterWindow();  
wndSplash.UpdateWindow();          //send WM_PAINT  
Sleep(4000);  
wndSplash.DestroyWindow();//销毁初始画面窗口  


CQDLogDlg dlg;
m_pMainWnd = &dlg;



你可能感兴趣的:(MFC vs2008,vs2010,vs2012,vs2013启动页的实现)