CSplashWnd SplashWnd; //創建啓動窗口類的實例
SplashWnd.Create(IDB_BITMAP2);
SplashWnd.CenterWindow();
SplashWnd.UpdateWindow(); //send WM_PAINT
Sleep(1500);
SplashWnd.DestroyWindow();//銷燬初始畫面窗口
this->CenterWindow();
this->UpdateWindow();
加在了: CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)裏面
#pragma once
class CSplashWnd : public CWnd
{
DECLARE_DYNAMIC(CSplashWnd)
public:
CSplashWnd();
virtual ~CSplashWnd();
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);
};
#include "stdafx.h"
#include "SplashWnd.h"
CSplashWnd::CSplashWnd()
{
}
CSplashWnd::~CSplashWnd()
{
}
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
// CSplashWnd消息處理程序
void CSplashWnd::Create(UINT nBitmapID)
{
m_bitmap.LoadBitmap(nBitmapID);
BITMAP bitmap;
m_bitmap.GetBitmap(&bitmap);
CreateEx(0,
AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
NULL, WS_POPUP | WS_VISIBLE, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NULL , NULL);
}
void CSplashWnd::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);
dc.BitBlt(0,0,bitmap.bmWidth,bitmap.bmHeight,&dcComp,0,0,SRCCOPY);
}
void CSplashWnd::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息處理程序代碼和/或調用默認值
DestroyWindow(); //銷燬初始畫面窗口
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////