Knowledge Base Nr: 00308 splashscreen.cpp - http://www.swe-kaiser.de
Downloads:
MFC: Win32: Splashscreen (Hinweisfenster während Programmstart)
//sample usage:
BOOL CDemoApp::InitInstance()
{
//splash screen
CSplashScreen wSplashScreen;
wSplashScreen.Create(IDB_SPLASHSCREEN);
wSplashScreen.UpdateWindow();
...
}
//in resource bitmap IDB_SPLASHSCREEN anlegen
// SplashScreen.h:
class CSplashScreen : public CWnd
{
DECLARE_DYNAMIC(CSplashScreen)
public:
CSplashScreen();
virtual ~CSplashScreen();
void Create(UINT nID);
protected:
CBitmap m_bitmap;
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPaint();
};
// SplashScreen.cpp: Implementierungsdatei
#include "stdafx.h"
#include "SplashScreen.h"
IMPLEMENT_DYNAMIC(CSplashScreen, CWnd)
CSplashScreen::CSplashScreen()
{
}
CSplashScreen::~CSplashScreen()
{
}
void CSplashScreen::Create(UINT nID)
{
m_bitmap.LoadBitmap(nID);
BITMAP bmInfo;
m_bitmap.GetObject(sizeof(bmInfo), &bmInfo);
int x = (::GetSystemMetrics(SM_CXSCREEN) - bmInfo.bmWidth) / 2;
int y = (::GetSystemMetrics(SM_CYSCREEN) - bmInfo.bmHeight) / 2;
CRect rect(x, y, x+bmInfo.bmWidth, y+bmInfo.bmHeight);
CreateEx(0, AfxRegisterWndClass(0), L"", WS_POPUP|WS_VISIBLE|WS_BORDER, rect, NULL, 0);
}
BEGIN_MESSAGE_MAP(CSplashScreen, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CSplashScreen::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC dcComp;
dcComp.CreateCompatibleDC(&dc);
dcComp.SelectObject(&m_bitmap);
BITMAP bmInfo;
m_bitmap.GetObject(sizeof(bmInfo), &bmInfo);
dc.BitBlt(0, 0, bmInfo.bmWidth, bmInfo.bmHeight, &dcComp, 0, 0, SRCCOPY);
}