1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // CG: This file was added by the Splash Screen component.
26 // Splash.cpp : implementation file
29 //===========================================================================
30 //===========================================================================
31 //#####DESCRIPTIONBEGIN####
38 // Description: This is the implementation of the splash screen class.
45 //####DESCRIPTIONEND####
47 //===========================================================================
56 static char BASED_CODE THIS_FILE[] = __FILE__;
59 IMPLEMENT_DYNAMIC( CSplashWnd, CWnd )
63 /////////////////////////////////////////////////////////////////////////////
64 // Splash Screen class
66 BOOL CSplashWnd::c_bShowSplashWnd;
67 CSplashWnd* CSplashWnd::c_pSplashWnd;
68 CSplashWnd::CSplashWnd()
72 CSplashWnd::~CSplashWnd()
74 // Clear the static window pointer.
75 ASSERT(c_pSplashWnd == this);
79 BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
80 //{{AFX_MSG_MAP(CSplashWnd)
87 void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
89 if(c_pSplashWnd != NULL && !bEnable){
90 c_pSplashWnd->HideSplashScreen();
92 c_bShowSplashWnd = bEnable;
95 void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
97 if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
100 // Allocate a new splash screen, and create the window.
101 c_pSplashWnd = new CSplashWnd;
102 if (!c_pSplashWnd->Create(pParentWnd))
104 deleteZ(c_pSplashWnd);
107 c_pSplashWnd->UpdateWindow();
110 BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
112 if (c_pSplashWnd == NULL)
115 // If we get a keyboard or mouse message, hide the splash screen.
116 if (pMsg->message == WM_KEYDOWN ||
117 pMsg->message == WM_SYSKEYDOWN ||
118 pMsg->message == WM_LBUTTONDOWN ||
119 pMsg->message == WM_RBUTTONDOWN ||
120 pMsg->message == WM_MBUTTONDOWN ||
121 pMsg->message == WM_NCLBUTTONDOWN ||
122 pMsg->message == WM_NCRBUTTONDOWN ||
123 pMsg->message == WM_NCMBUTTONDOWN)
125 c_pSplashWnd->HideSplashScreen();
126 return TRUE; // message handled here
129 return FALSE; // message not handled
132 BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
134 UINT image = IDB_SPLASH;
135 if (!m_bitmap.LoadBitmap(image))
139 m_bitmap.GetBitmap(&bm);
142 AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
143 NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
144 m_hBitmap = LoadResourceBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(image));
145 m_pBitmap = CBitmap::FromHandle(m_hBitmap);
149 HBITMAP CSplashWnd::LoadResourceBitmap(HINSTANCE hInstance, LPCTSTR lpString)
153 HBITMAP hBitmapFinal = NULL;
154 LPBITMAPINFOHEADER lpbi;
158 HRSRC hRsrc = FindResource(hInstance, lpString, RT_BITMAP);
162 hGlobal = LoadResource(hInstance, hRsrc);
163 lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);
164 CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
167 hdc = dc->GetSafeHdc();
168 CPalette* oldpal = dc->SelectPalette(&Palette,FALSE);
169 dc->RealizePalette();
170 hBitmapFinal = CreateDIBitmap(hdc,
171 (LPBITMAPINFOHEADER)lpbi,
173 (LPSTR)lpbi + lpbi->biSize + iNumColors *
177 dc->SelectPalette(oldpal,FALSE);
178 dc->RealizePalette();
181 UnlockResource(hGlobal);
182 FreeResource(hGlobal);
184 return (hBitmapFinal);
187 void CSplashWnd::HideSplashScreen()
189 // Destroy the window, and update the mainframe.
191 CWnd *pWnd=AfxGetMainWnd();
194 pWnd->UpdateWindow();
198 void CSplashWnd::PostNcDestroy()
200 // Free the C++ class.
204 int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
206 if (CWnd::OnCreate(lpCreateStruct) == -1)
209 // Center the window.
212 // Set a timer to destroy the splash screen.
213 SetTimer(1, 3000, NULL);
218 void CSplashWnd::OnPaint()
223 if (!dcImage.CreateCompatibleDC(&dc))
227 m_bitmap.GetBitmap(&bm);
229 CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
230 dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
231 dcImage.SelectObject(pOldBitmap);
233 for(int i=0;i<bm.bmHeight;i++){
234 COLORREF col=PALETTERGB(0,0,(255*i)/bm.bmHeight);
235 CRect rect(0,i,bm.bmWidth,i+2);
236 dcImage.FillSolidRect(&rect, col);
238 dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, MERGEPAINT);
242 void CSplashWnd::OnTimer(UINT nIDEvent)
244 // Destroy the splash screen window.
246 UNUSED_ALWAYS(nIDEvent);
249 void CSplashWnd::CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)
251 LPBITMAPINFOHEADER lpbi;
256 lpbi = (LPBITMAPINFOHEADER)lpbmi;
257 if (lpbi->biBitCount <= 8)
258 *lpiNumColors = (1 << lpbi->biBitCount);
260 *lpiNumColors = 0; // No palette needed for 24 BPP DIB
264 hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) +
265 sizeof (PALETTEENTRY) * (*lpiNumColors));
266 lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);
267 lpPal->palVersion = 0x300;
268 lpPal->palNumEntries = (unsigned short)*lpiNumColors;
270 for (i = 0; i < *lpiNumColors; i++)
272 lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
273 lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
274 lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
275 lpPal->palPalEntry[i].peFlags = 0;
277 Palette.CreatePalette(lpPal);
278 GlobalUnlock (hLogPal);
279 GlobalFree (hLogPal);