vc08添加启动画面

//启动画面代码


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)里面
 
在vc工程中加两个文件
SplashWnd.h
SplashWnd.cpp
 
SplashWnd.h
/
// SplashWnd.h
#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);
};
//
// SplashWnd.cpp : 实现文件
#include "stdafx.h"
#include "SplashWnd.h"
IMPLEMENT_DYNAMIC(CSplashWnd, CWnd)
 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(); //销毁初始画面窗口
}
//
 

你可能感兴趣的:(C++,C++)