Splash.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:6k
- /////////////////////////////////////////////////////////////////////////////
- // CG: This file was added by the Splash Screen component.
- // Splash.cpp : implementation of the CSplash class
- //
- // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1999
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h" // e.g. stdafx.h
- #include "resource.h" // e.g. resource.h
- #include "Splash.h" // e.g. splash.h
- #include "glOOP.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Splash Screen class
- BOOL CSplashWnd::c_bShowSplashWnd;
- CSplashWnd* CSplashWnd::c_pSplashWnd;
- CSplashWnd::CSplashWnd()
- {
- m_pDC = NULL;
- }
- CSplashWnd::~CSplashWnd()
- {
- // Clear the static window pointer.
- ASSERT(c_pSplashWnd == this);
- c_pSplashWnd = NULL;
- }
- BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
- //{{AFX_MSG_MAP(CSplashWnd)
- ON_WM_CREATE()
- ON_WM_PAINT()
- ON_WM_TIMER()
- ON_WM_PALETTECHANGED()
- ON_WM_QUERYNEWPALETTE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
- {
- c_bShowSplashWnd = bEnable;
- }
- 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();
- }
- BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
- {
- if (c_pSplashWnd == NULL)
- return FALSE;
- // If we get a keyboard or mouse message, hide the splash screen.
- 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; // message handled here
- }
- return FALSE; // message not handled
- }
- BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
- {
- if (!m_bitmap.LoadBitmap(IDB_SPLASH))
- return FALSE;
- BITMAP bm;
- m_bitmap.GetBitmap(&bm);
- return CreateEx(NULL, NULL, NULL,
- WS_POPUP | WS_VISIBLE,
- 0, 0, bm.bmWidth, bm.bmHeight,
- pParentWnd->GetSafeHwnd(), NULL);
- }
- BOOL CSplashWnd::PreCreateWindow(CREATESTRUCT& cs)
- {
- // Register a class with its own device context and the 'arrow' cursor
- cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | CS_VREDRAW,
- ::LoadCursor(NULL, IDC_ARROW));
- return CWnd::PreCreateWindow(cs);
- }
- void CSplashWnd::HideSplashScreen()
- {
- // Destroy the window, and update the mainframe.
- DestroyWindow();
- AfxGetMainWnd()->UpdateWindow();
- }
- void CSplashWnd::PostNcDestroy()
- {
- // Clean up rendering context stuff
- if(m_pDC)
- delete m_pDC;
- // Free the C++ class.
- delete this;
- }
- int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- // Get the Device context to our window
- m_pDC = new CClientDC (this);
- if (m_pDC == NULL)
- return (-1);
- // Center the window.
- CenterWindow();
- // Set a timer to destroy the splash screen.
- SetTimer(1, 2000, NULL);
- return 0;
- }
- void CSplashWnd::OnPaint()
- {
- CPaintDC dc(this);
- dc.m_ps.hdc = m_pDC->GetSafeHdc();
- 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();
- }
- void CSplashWnd::OnPaletteChanged(CWnd* pFocusWnd)
- {
- HPALETTE hPaletteOld; // Handle to the old palette
- int iNumEntries; // Number of entries in the logical palette were
- // mapped to different entries in the system palette.
- if((the3dEngine.GetPalette() != NULL) && (pFocusWnd != this))
- {
- // Select the palette into the device context
- hPaletteOld = SelectPalette(m_pDC->GetSafeHdc(), the3dEngine.GetPalette(), FALSE);
- // Map entries from the currently selected palette to
- // the system palette. The return value is the number
- // of palette entries modified.
- iNumEntries = RealizePalette(m_pDC->GetSafeHdc());
-
- // Remap the current colors to the newly realized palette
- UpdateColors(m_pDC->GetSafeHdc());
- return;
- }
- CWnd::OnPaletteChanged(pFocusWnd);
- }
- BOOL CSplashWnd::OnQueryNewPalette()
- {
- HPALETTE hPaletteOld; // Handle to the old palette
- int iNumEntries; // Number of entries in the logical palette were
- // mapped to different entries in the system palette.
- // If the palette was created.
- if(the3dEngine.GetPalette())
- {
- // Selects the palette into the current device context
- hPaletteOld = SelectPalette(m_pDC->GetSafeHdc(), the3dEngine.GetPalette(), FALSE);
- // Map entries from the currently selected palette to
- // the system palette. The return value is the number
- // of palette entries modified.
- iNumEntries = RealizePalette(m_pDC->GetSafeHdc());
- // Repaint, forces remap of palette in current window
- InvalidateRect(NULL, FALSE);
- return iNumEntries;
- }
-
- return CWnd::OnQueryNewPalette();
- }