- ///
- // splashwnd.h
- #if !defined(AFX_SPLASHWND_H__24A0BA9F_A099_4AE2_81AE_76599D2DC19E__INCLUDED_)
- #define AFX_SPLASHWND_H__24A0BA9F_A099_4AE2_81AE_76599D2DC19E__INCLUDED_
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- // splashwnd.h : header file
- //
- /
- // CSplashWnd window
- class CSplashWnd : public CWnd
- {
- // Construction
- public:
- CSplashWnd();
- // Attributes
- private:
- CBitmap m_bitmap;
- // Operations
- public:
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CSplashWnd)
- //}}AFX_VIRTUAL
- // Implementation
- public:
- static void ShowSplashScreen(CWnd* pParentWnd = NULL);
- virtual ~CSplashWnd();
- // Generated message map functions
- protected:
- BOOL Create(CWnd* pParentWnd = NULL);
- void HideSplashScreen();
- static CSplashWnd* c_pSplashWnd;
- //{{AFX_MSG(CSplashWnd)
- afx_msg void OnPaint();
- afx_msg void OnTimer(UINT nIDEvent);
- afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- private:
- void PostNcDestroy();
- };
- /
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_SPLASHWND_H__24A0BA9F_A099_4AE2_81AE_76599D2DC19E__INCLUDED_)
论坛上某位兄弟移植的,刚刚用了,挺不错,共享一下
- // splashwnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "resource.h"
- #include "splashwnd.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /
- // CSplashWnd
- //BOOL CSplashWnd::c_bShowSplashWnd;
- CSplashWnd* CSplashWnd::c_pSplashWnd;
- CSplashWnd::CSplashWnd()
- {
- }
- CSplashWnd::~CSplashWnd()
- {
- ASSERT(c_pSplashWnd == this);
- c_pSplashWnd = NULL;
- }
- BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
- //{{AFX_MSG_MAP(CSplashWnd)
- ON_WM_PAINT()
- ON_WM_TIMER()
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /
- // CSplashWnd message handlers
- void CSplashWnd::OnPaint()
- {
- CPaintDC dc(this);
- 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);
- }
- void CSplashWnd::OnTimer(UINT nIDEvent)
- {
- // Destroy the splash screen window.
- HideSplashScreen();
- }
- int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- // Center the window.
- CenterWindow();
- // Set a timer to destroy the splash screen.
- SetTimer(1, 10000, NULL);
- return 0;
- }
- void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
- {
- if (/*!c_bShowSplashWnd || */c_pSplashWnd != NULL)
- return;
- // Allocate a new splash screen, and create the window.
- c_pSplashWnd = new CSplashWnd;
- if (!c_pSplashWnd->Create(pParentWnd))
- delete c_pSplashWnd;
- else
- c_pSplashWnd->UpdateWindow();
- }
- void CSplashWnd::HideSplashScreen()
- {
- // Destroy the window, and update the mainframe.
- DestroyWindow();
- AfxGetMainWnd()->UpdateWindow();
- }
- BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
- {
- if (!m_bitmap.LoadBitmap(IDB_START))
- 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::PostNcDestroy()
- {
- // Free the C++ class.
- delete this;
- }