| 1 | // CG: This file was added by the Splash Screen component. | 
|---|
| 2 | // Splash.cpp : implementation file | 
|---|
| 3 | // | 
|---|
| 4 |  | 
|---|
| 5 | #include "stdafx.h"  // e. g. stdafx.h | 
|---|
| 6 | #include "resource.h"  // e.g. resource.h | 
|---|
| 7 |  | 
|---|
| 8 | #include "Splash.h"  // e.g. splash.h | 
|---|
| 9 |  | 
|---|
| 10 | #ifdef _DEBUG | 
|---|
| 11 | #define new DEBUG_NEW | 
|---|
| 12 | #undef THIS_FILE | 
|---|
| 13 | static char BASED_CODE THIS_FILE[] = __FILE__; | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 17 | //   Splash Screen class | 
|---|
| 18 |  | 
|---|
| 19 | BOOL CSplashWnd::c_bShowSplashWnd; | 
|---|
| 20 | CSplashWnd* CSplashWnd::c_pSplashWnd; | 
|---|
| 21 | CSplashWnd::CSplashWnd() | 
|---|
| 22 | { | 
|---|
| 23 | } | 
|---|
| 24 |  | 
|---|
| 25 | CSplashWnd::~CSplashWnd() | 
|---|
| 26 | { | 
|---|
| 27 | // Clear the static window pointer. | 
|---|
| 28 | ASSERT(c_pSplashWnd == this); | 
|---|
| 29 | c_pSplashWnd = NULL; | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | BEGIN_MESSAGE_MAP(CSplashWnd, CWnd) | 
|---|
| 33 | //{{AFX_MSG_MAP(CSplashWnd) | 
|---|
| 34 | ON_WM_CREATE() | 
|---|
| 35 | ON_WM_PAINT() | 
|---|
| 36 | ON_WM_TIMER() | 
|---|
| 37 | //}}AFX_MSG_MAP | 
|---|
| 38 | END_MESSAGE_MAP() | 
|---|
| 39 |  | 
|---|
| 40 | void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/) | 
|---|
| 41 | { | 
|---|
| 42 | c_bShowSplashWnd = bEnable; | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/) | 
|---|
| 46 | { | 
|---|
| 47 | if (!c_bShowSplashWnd || c_pSplashWnd != NULL) | 
|---|
| 48 | return; | 
|---|
| 49 |  | 
|---|
| 50 | // Allocate a new splash screen, and create the window. | 
|---|
| 51 | c_pSplashWnd = new CSplashWnd; | 
|---|
| 52 | if (!c_pSplashWnd->Create(pParentWnd)) | 
|---|
| 53 | delete c_pSplashWnd; | 
|---|
| 54 | else | 
|---|
| 55 | c_pSplashWnd->UpdateWindow(); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg) | 
|---|
| 59 | { | 
|---|
| 60 | if (c_pSplashWnd == NULL) | 
|---|
| 61 | return FALSE; | 
|---|
| 62 |  | 
|---|
| 63 | // If we get a keyboard or mouse message, hide the splash screen. | 
|---|
| 64 | if (pMsg->message == WM_KEYDOWN || | 
|---|
| 65 | pMsg->message == WM_SYSKEYDOWN || | 
|---|
| 66 | pMsg->message == WM_LBUTTONDOWN || | 
|---|
| 67 | pMsg->message == WM_RBUTTONDOWN || | 
|---|
| 68 | pMsg->message == WM_MBUTTONDOWN || | 
|---|
| 69 | pMsg->message == WM_NCLBUTTONDOWN || | 
|---|
| 70 | pMsg->message == WM_NCRBUTTONDOWN || | 
|---|
| 71 | pMsg->message == WM_NCMBUTTONDOWN) | 
|---|
| 72 | { | 
|---|
| 73 | c_pSplashWnd->HideSplashScreen(); | 
|---|
| 74 | return TRUE;    // message handled here | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | return FALSE;   // message not handled | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/) | 
|---|
| 81 | { | 
|---|
| 82 | if (!m_bitmap.LoadBitmap(IDB_SPLASH)) | 
|---|
| 83 | return FALSE; | 
|---|
| 84 |  | 
|---|
| 85 | BITMAP bm; | 
|---|
| 86 | m_bitmap.GetBitmap(&bm); | 
|---|
| 87 |  | 
|---|
| 88 | return CreateEx(0, | 
|---|
| 89 | AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)), | 
|---|
| 90 | NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL); | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | void CSplashWnd::HideSplashScreen() | 
|---|
| 94 | { | 
|---|
| 95 | // Destroy the window, and update the mainframe. | 
|---|
| 96 | DestroyWindow(); | 
|---|
| 97 | AfxGetMainWnd()->UpdateWindow(); | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | void CSplashWnd::PostNcDestroy() | 
|---|
| 101 | { | 
|---|
| 102 | // Free the C++ class. | 
|---|
| 103 | delete this; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) | 
|---|
| 107 | { | 
|---|
| 108 | if (CWnd::OnCreate(lpCreateStruct) == -1) | 
|---|
| 109 | return -1; | 
|---|
| 110 |  | 
|---|
| 111 | // Center the window. | 
|---|
| 112 | CenterWindow(); | 
|---|
| 113 |  | 
|---|
| 114 | // Set a timer to destroy the splash screen. | 
|---|
| 115 | SetTimer(1, 3000, NULL); | 
|---|
| 116 |  | 
|---|
| 117 | return 0; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | void CSplashWnd::OnPaint() | 
|---|
| 121 | { | 
|---|
| 122 | CPaintDC dc(this); | 
|---|
| 123 |  | 
|---|
| 124 | CDC dcImage; | 
|---|
| 125 | if (!dcImage.CreateCompatibleDC(&dc)) | 
|---|
| 126 | return; | 
|---|
| 127 |  | 
|---|
| 128 | BITMAP bm; | 
|---|
| 129 | m_bitmap.GetBitmap(&bm); | 
|---|
| 130 |  | 
|---|
| 131 | // Paint the image. | 
|---|
| 132 | CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap); | 
|---|
| 133 | dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY); | 
|---|
| 134 | dcImage.SelectObject(pOldBitmap); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | void CSplashWnd::OnTimer(UINT nIDEvent) | 
|---|
| 138 | { | 
|---|
| 139 | // Destroy the splash screen window. | 
|---|
| 140 | HideSplashScreen(); | 
|---|
| 141 | } | 
|---|