comparison host/tools/configtool/standalone/win32/splash.cpp @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
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)
11 // any later version.
12 //
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
16 // more details.
17 //
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.
21 //
22 // ----------------------------------------------------------------------------
23 //
24 //####COPYRIGHTEND####
25 // CG: This file was added by the Splash Screen component.
26 // Splash.cpp : implementation file
27 //
28 //
29 //===========================================================================
30 //===========================================================================
31 //#####DESCRIPTIONBEGIN####
32 //
33 // Author(s): sdf
34 // Contact(s): sdf
35 // Date: 1998/08/11
36 // Version: 0.01
37 // Purpose:
38 // Description: This is the implementation of the splash screen class.
39 // Requires:
40 // Provides:
41 // See also:
42 // Known bugs:
43 // Usage:
44 //
45 //####DESCRIPTIONEND####
46 //
47 //===========================================================================
48
49 #include "stdafx.h"
50 #include "resource.h"
51 #include "Splash.h"
52
53 #ifdef _DEBUG
54 #define new DEBUG_NEW
55 #undef THIS_FILE
56 static char BASED_CODE THIS_FILE[] = __FILE__;
57 #endif
58
59 IMPLEMENT_DYNAMIC( CSplashWnd, CWnd )
60
61
62
63 /////////////////////////////////////////////////////////////////////////////
64 // Splash Screen class
65
66 BOOL CSplashWnd::c_bShowSplashWnd;
67 CSplashWnd* CSplashWnd::c_pSplashWnd;
68 CSplashWnd::CSplashWnd()
69 {
70 }
71
72 CSplashWnd::~CSplashWnd()
73 {
74 // Clear the static window pointer.
75 ASSERT(c_pSplashWnd == this);
76 c_pSplashWnd = NULL;
77 }
78
79 BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
80 //{{AFX_MSG_MAP(CSplashWnd)
81 ON_WM_CREATE()
82 ON_WM_PAINT()
83 ON_WM_TIMER()
84 //}}AFX_MSG_MAP
85 END_MESSAGE_MAP()
86
87 void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
88 {
89 if(c_pSplashWnd != NULL && !bEnable){
90 c_pSplashWnd->HideSplashScreen();
91 }
92 c_bShowSplashWnd = bEnable;
93 }
94
95 void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
96 {
97 if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
98 return;
99
100 // Allocate a new splash screen, and create the window.
101 c_pSplashWnd = new CSplashWnd;
102 if (!c_pSplashWnd->Create(pParentWnd))
103 {
104 deleteZ(c_pSplashWnd);
105 }
106 else
107 c_pSplashWnd->UpdateWindow();
108 }
109
110 BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
111 {
112 if (c_pSplashWnd == NULL)
113 return FALSE;
114
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)
124 {
125 c_pSplashWnd->HideSplashScreen();
126 return TRUE; // message handled here
127 }
128
129 return FALSE; // message not handled
130 }
131
132 BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
133 {
134 UINT image = IDB_SPLASH;
135 if (!m_bitmap.LoadBitmap(image))
136 return FALSE;
137
138 BITMAP bm;
139 m_bitmap.GetBitmap(&bm);
140
141 BOOL rc=CreateEx(0,
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);
146 return rc;
147 }
148
149 HBITMAP CSplashWnd::LoadResourceBitmap(HINSTANCE hInstance, LPCTSTR lpString)
150
151 {
152 HGLOBAL hGlobal;
153 HBITMAP hBitmapFinal = NULL;
154 LPBITMAPINFOHEADER lpbi;
155 HDC hdc;
156 CDC* dc;
157 int iNumColors;
158 HRSRC hRsrc = FindResource(hInstance, lpString, RT_BITMAP);
159
160 if (hRsrc)
161 {
162 hGlobal = LoadResource(hInstance, hRsrc);
163 lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);
164 CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
165
166 dc = GetDC();
167 hdc = dc->GetSafeHdc();
168 CPalette* oldpal = dc->SelectPalette(&Palette,FALSE);
169 dc->RealizePalette();
170 hBitmapFinal = CreateDIBitmap(hdc,
171 (LPBITMAPINFOHEADER)lpbi,
172 (LONG)CBM_INIT,
173 (LPSTR)lpbi + lpbi->biSize + iNumColors *
174 sizeof(RGBQUAD),
175 (LPBITMAPINFO)lpbi,
176 DIB_RGB_COLORS );
177 dc->SelectPalette(oldpal,FALSE);
178 dc->RealizePalette();
179
180 ReleaseDC( dc );
181 UnlockResource(hGlobal);
182 FreeResource(hGlobal);
183 }
184 return (hBitmapFinal);
185 }
186
187 void CSplashWnd::HideSplashScreen()
188 {
189 // Destroy the window, and update the mainframe.
190 DestroyWindow();
191 CWnd *pWnd=AfxGetMainWnd();
192 if(pWnd)
193 {
194 pWnd->UpdateWindow();
195 }
196 }
197
198 void CSplashWnd::PostNcDestroy()
199 {
200 // Free the C++ class.
201 delete this;
202 }
203
204 int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
205 {
206 if (CWnd::OnCreate(lpCreateStruct) == -1)
207 return -1;
208
209 // Center the window.
210 CenterWindow();
211
212 // Set a timer to destroy the splash screen.
213 SetTimer(1, 3000, NULL);
214
215 return 0;
216 }
217
218 void CSplashWnd::OnPaint()
219 {
220 CPaintDC dc(this);
221
222 CDC dcImage;
223 if (!dcImage.CreateCompatibleDC(&dc))
224 return;
225
226 BITMAP bm;
227 m_bitmap.GetBitmap(&bm);
228 // Paint the image.
229 CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
230 dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
231 dcImage.SelectObject(pOldBitmap);
232
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);
237 }
238 dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, MERGEPAINT);
239
240 }
241
242 void CSplashWnd::OnTimer(UINT nIDEvent)
243 {
244 // Destroy the splash screen window.
245 HideSplashScreen();
246 UNUSED_ALWAYS(nIDEvent);
247 }
248
249 void CSplashWnd::CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)
250 {
251 LPBITMAPINFOHEADER lpbi;
252 LPLOGPALETTE lpPal;
253 HANDLE hLogPal;
254 int i;
255
256 lpbi = (LPBITMAPINFOHEADER)lpbmi;
257 if (lpbi->biBitCount <= 8)
258 *lpiNumColors = (1 << lpbi->biBitCount);
259 else
260 *lpiNumColors = 0; // No palette needed for 24 BPP DIB
261
262 if (*lpiNumColors)
263 {
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;
269
270 for (i = 0; i < *lpiNumColors; i++)
271 {
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;
276 }
277 Palette.CreatePalette(lpPal);
278 GlobalUnlock (hLogPal);
279 GlobalFree (hLogPal);
280 }
281 return ;
282 }