GME
13
|
00001 // CG: This file was added by the Splash Screen component. 00002 // Splash.cpp : implementation file 00003 // 00004 00005 #include "stdafx.h" // e. g. stdafx.h 00006 #include "resource.h" // e.g. resource.h 00007 00008 #include "Splash.h" // e.g. splash.h 00009 00010 #ifdef _DEBUG 00011 #define new DEBUG_NEW 00012 #undef THIS_FILE 00013 static char BASED_CODE THIS_FILE[] = __FILE__; 00014 #endif 00015 00017 // Splash Screen class 00018 00019 BOOL CSplashWnd::c_bShowSplashWnd; 00020 CSplashWnd* CSplashWnd::c_pSplashWnd; 00021 CSplashWnd::CSplashWnd() 00022 { 00023 } 00024 00025 CSplashWnd::~CSplashWnd() 00026 { 00027 // Clear the static window pointer. 00028 ASSERT(c_pSplashWnd == this); 00029 c_pSplashWnd = NULL; 00030 } 00031 00032 BEGIN_MESSAGE_MAP(CSplashWnd, CWnd) 00033 //{{AFX_MSG_MAP(CSplashWnd) 00034 ON_WM_CREATE() 00035 ON_WM_PAINT() 00036 ON_WM_TIMER() 00037 //}}AFX_MSG_MAP 00038 END_MESSAGE_MAP() 00039 00040 void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/) 00041 { 00042 c_bShowSplashWnd = bEnable; 00043 } 00044 00045 void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/) 00046 { 00047 if (!c_bShowSplashWnd || c_pSplashWnd != NULL) 00048 return; 00049 00050 // Allocate a new splash screen, and create the window. 00051 c_pSplashWnd = new CSplashWnd; 00052 if (!c_pSplashWnd->Create(pParentWnd)) 00053 delete c_pSplashWnd; 00054 else 00055 c_pSplashWnd->UpdateWindow(); 00056 } 00057 00058 BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg) 00059 { 00060 if (c_pSplashWnd == NULL) 00061 return FALSE; 00062 00063 // If we get a keyboard or mouse message, hide the splash screen. 00064 if (pMsg->message == WM_KEYDOWN || 00065 pMsg->message == WM_SYSKEYDOWN || 00066 pMsg->message == WM_LBUTTONDOWN || 00067 pMsg->message == WM_RBUTTONDOWN || 00068 pMsg->message == WM_MBUTTONDOWN || 00069 pMsg->message == WM_NCLBUTTONDOWN || 00070 pMsg->message == WM_NCRBUTTONDOWN || 00071 pMsg->message == WM_NCMBUTTONDOWN) 00072 { 00073 c_pSplashWnd->HideSplashScreen(); 00074 return TRUE; // message handled here 00075 } 00076 00077 return FALSE; // message not handled 00078 } 00079 00080 BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/) 00081 { 00082 if (!m_bitmap.LoadBitmap(IDB_SPLASH)) 00083 return FALSE; 00084 00085 BITMAP bm; 00086 m_bitmap.GetBitmap(&bm); 00087 00088 return CreateEx(0, 00089 AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)), 00090 NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL); 00091 } 00092 00093 void CSplashWnd::HideSplashScreen() 00094 { 00095 // Destroy the window, and update the mainframe. 00096 DestroyWindow(); 00097 AfxGetMainWnd()->UpdateWindow(); 00098 } 00099 00100 void CSplashWnd::PostNcDestroy() 00101 { 00102 // Free the C++ class. 00103 delete this; 00104 } 00105 00106 int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 00107 { 00108 if (CWnd::OnCreate(lpCreateStruct) == -1) 00109 return -1; 00110 00111 // Center the window. 00112 CenterWindow(); 00113 00114 // Set a timer to destroy the splash screen. 00115 m_timerID = SetTimer(1, 2000, NULL); 00116 00117 return 0; 00118 } 00119 00120 void CSplashWnd::OnPaint() 00121 { 00122 CPaintDC dc(this); 00123 00124 CDC dcImage; 00125 if (!dcImage.CreateCompatibleDC(&dc)) 00126 return; 00127 00128 BITMAP bm; 00129 m_bitmap.GetBitmap(&bm); 00130 00131 // Paint the image. 00132 CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap); 00133 dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY); 00134 dcImage.SelectObject(pOldBitmap); 00135 } 00136 00137 void CSplashWnd::OnTimer(UINT_PTR nIDEvent) 00138 { 00139 if (nIDEvent == 1) 00140 { 00141 // Destroy the splash screen window. 00142 VERIFY(KillTimer(m_timerID)); 00143 HideSplashScreen(); 00144 return; 00145 } 00146 __super::OnTimer(nIDEvent); 00147 }