封装类之CSplashWnd(应用程序的启动画面)

来源:互联网 发布:apache ab get参数 编辑:程序博客网 时间:2024/05/22 12:36

1XX.h文件

class CSplashWnd : public CWnd{    DECLARE_DYNAMIC(CSplashWnd)public:    CSplashWnd();    virtual ~CSplashWnd();protected:    virtual void PostNcDestroy();    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);    afx_msg void OnTimer(UINT_PTR nIDEvent);    afx_msg void OnPaint();    BOOL Create(CWnd* pParentWnd=NULL);    void HideSplashScreen(void);    DECLARE_MESSAGE_MAP()protected:    CBitmap m_bitmap;    static CSplashWnd* c_pSplashWnd;    static BOOL c_bShowSplashWnd;public:    static void EnableSplashScreen(BOOL bEnable=TRUE);    static void ShowSplashScreen(CWnd* pParentWnd=NULL);    static BOOL PreTranslateAppMessage(MSG* pMsg);};

2XX.cpp文件

// SplashWnd.cpp : 实现文件//#include "stdafx.h"#include "SplashScreen.h"#include "SplashWnd.h"#include "resource.h"// CSplashWndCSplashWnd* CSplashWnd::c_pSplashWnd;BOOL CSplashWnd::c_bShowSplashWnd;IMPLEMENT_DYNAMIC(CSplashWnd, CWnd)CSplashWnd::CSplashWnd(){}CSplashWnd::~CSplashWnd(){    ASSERT(c_pSplashWnd == this);    c_pSplashWnd = NULL;}BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)    ON_WM_CREATE()    ON_WM_TIMER()    ON_WM_PAINT()END_MESSAGE_MAP()// CSplashWnd 消息处理程序void CSplashWnd::EnableSplashScreen(BOOL bEnable){    c_bShowSplashWnd = bEnable;}void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd){    if ( !c_bShowSplashWnd || c_pSplashWnd != NULL )    {        return;    }    c_pSplashWnd = new CSplashWnd;    if ( !c_pSplashWnd->Create(pParentWnd) )    {        delete c_pSplashWnd;    }    else    {        c_pSplashWnd->UpdateWindow();    }}BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg){    if ( c_pSplashWnd == NULL )    {        return FALSE;    }    if ( pMsg->message == WM_KEYDOWN        || pMsg->message == WM_SYSKEYDOWN        || pMsg->message == WM_LBUTTONDOWN        || pMsg->message == WM_RBUTTONDOWN        || pMsg->message == WM_MBUTTONDOWN        || pMsg->message == WM_NCLBUTTONDOWN        || pMsg->message == WM_NCRBUTTONDOWN        || pMsg->message == WM_NCMBUTTONDOWN)    {        c_pSplashWnd->HideSplashScreen();        return TRUE;    }    return FALSE;}void CSplashWnd::PostNcDestroy(){    delete this;}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){    if ( nIDEvent == 1 )    {        HideSplashScreen();    }}void CSplashWnd::OnPaint(){    CPaintDC dc(this);    CDC dcImg;    if ( !dcImg.CreateCompatibleDC(&dc) )    {        return;    }    BITMAP bm;    m_bitmap.GetBitmap(&bm);    CBitmap* pOldBit = dcImg.SelectObject(&m_bitmap);    dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImg, 0, 0, SRCCOPY);    dcImg.SelectObject(pOldBit);}BOOL CSplashWnd::Create(CWnd* pParentWnd){    if ( !m_bitmap.LoadBitmap(IDB_SPLASH))    {        return FALSE;    }    BITMAP bm;    m_bitmap.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);}void CSplashWnd::HideSplashScreen(){    DestroyWindow();    AfxGetMainWnd()->UpdateWindow();}
0 0
原创粉丝点击