OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [win32/] [splash.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// CG: This file was added by the Splash Screen component.
23
// Splash.cpp : implementation file
24
//
25
//
26
//===========================================================================
27
//===========================================================================
28
//#####DESCRIPTIONBEGIN####
29
//
30
// Author(s):   sdf
31
// Contact(s):  sdf
32
// Date:                1998/08/11
33
// Version:             0.01
34
// Purpose:     
35
// Description: This is the implementation of the splash screen class.
36
// Requires:    
37
// Provides:    
38
// See also:    
39
// Known bugs:  
40
// Usage:       
41
//
42
//####DESCRIPTIONEND####
43
//
44
//===========================================================================
45
 
46
#include "stdafx.h"
47
#include "resource.h"
48
#include "Splash.h"
49
 
50
#ifdef _DEBUG
51
#define new DEBUG_NEW
52
#undef THIS_FILE
53
static char BASED_CODE THIS_FILE[] = __FILE__;
54
#endif
55
 
56
IMPLEMENT_DYNAMIC( CSplashWnd, CWnd )
57
 
58
 
59
 
60
/////////////////////////////////////////////////////////////////////////////
61
//   Splash Screen class
62
 
63
BOOL CSplashWnd::c_bShowSplashWnd;
64
CSplashWnd* CSplashWnd::c_pSplashWnd;
65
CSplashWnd::CSplashWnd()
66
{
67
}
68
 
69
CSplashWnd::~CSplashWnd()
70
{
71
        // Clear the static window pointer.
72
        ASSERT(c_pSplashWnd == this);
73
        c_pSplashWnd = NULL;
74
}
75
 
76
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
77
        //{{AFX_MSG_MAP(CSplashWnd)
78
        ON_WM_CREATE()
79
        ON_WM_PAINT()
80
        ON_WM_TIMER()
81
        //}}AFX_MSG_MAP
82
END_MESSAGE_MAP()
83
 
84
void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
85
{
86
        if(c_pSplashWnd != NULL && !bEnable){
87
                c_pSplashWnd->HideSplashScreen();
88
        }
89
        c_bShowSplashWnd = bEnable;
90
}
91
 
92
void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
93
{
94
        if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
95
                return;
96
 
97
        // Allocate a new splash screen, and create the window.
98
        c_pSplashWnd = new CSplashWnd;
99
        if (!c_pSplashWnd->Create(pParentWnd))
100
        {
101
                deleteZ(c_pSplashWnd);
102
        }
103
        else
104
                c_pSplashWnd->UpdateWindow();
105
}
106
 
107
BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
108
{
109
        if (c_pSplashWnd == NULL)
110
                return FALSE;
111
 
112
        // If we get a keyboard or mouse message, hide the splash screen.
113
        if (pMsg->message == WM_KEYDOWN ||
114
            pMsg->message == WM_SYSKEYDOWN ||
115
            pMsg->message == WM_LBUTTONDOWN ||
116
            pMsg->message == WM_RBUTTONDOWN ||
117
            pMsg->message == WM_MBUTTONDOWN ||
118
            pMsg->message == WM_NCLBUTTONDOWN ||
119
            pMsg->message == WM_NCRBUTTONDOWN ||
120
            pMsg->message == WM_NCMBUTTONDOWN)
121
        {
122
                c_pSplashWnd->HideSplashScreen();
123
                return TRUE;    // message handled here
124
        }
125
 
126
        return FALSE;   // message not handled
127
}
128
 
129
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
130
{
131
        UINT image = IDB_SPLASH;
132
        if (!m_bitmap.LoadBitmap(image))
133
                return FALSE;
134
 
135
        BITMAP bm;
136
        m_bitmap.GetBitmap(&bm);
137
 
138
        BOOL rc=CreateEx(0,
139
                AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
140
                NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
141
        m_hBitmap = LoadResourceBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(image));
142
        m_pBitmap = CBitmap::FromHandle(m_hBitmap);
143
        return rc;
144
}
145
 
146
HBITMAP CSplashWnd::LoadResourceBitmap(HINSTANCE hInstance, LPCTSTR lpString)
147
 
148
{
149
    HGLOBAL hGlobal;
150
    HBITMAP hBitmapFinal = NULL;
151
    LPBITMAPINFOHEADER  lpbi;
152
    HDC hdc;
153
        CDC* dc;
154
    int iNumColors;
155
    HRSRC  hRsrc = FindResource(hInstance, lpString, RT_BITMAP);
156
 
157
    if (hRsrc)
158
       {
159
       hGlobal = LoadResource(hInstance, hRsrc);
160
       lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);
161
           CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
162
 
163
           dc = GetDC();
164
       hdc = dc->GetSafeHdc();
165
       CPalette* oldpal = dc->SelectPalette(&Palette,FALSE);
166
           dc->RealizePalette();
167
       hBitmapFinal = CreateDIBitmap(hdc,
168
                   (LPBITMAPINFOHEADER)lpbi,
169
                   (LONG)CBM_INIT,
170
                   (LPSTR)lpbi + lpbi->biSize + iNumColors *
171
                                        sizeof(RGBQUAD),
172
                    (LPBITMAPINFO)lpbi,
173
                   DIB_RGB_COLORS );
174
       dc->SelectPalette(oldpal,FALSE);
175
           dc->RealizePalette();
176
 
177
       ReleaseDC( dc );
178
       UnlockResource(hGlobal);
179
       FreeResource(hGlobal);
180
       }
181
    return (hBitmapFinal);
182
}
183
 
184
void CSplashWnd::HideSplashScreen()
185
{
186
        // Destroy the window, and update the mainframe.
187
        DestroyWindow();
188
        CWnd *pWnd=AfxGetMainWnd();
189
        if(pWnd)
190
        {
191
                pWnd->UpdateWindow();
192
        }
193
}
194
 
195
void CSplashWnd::PostNcDestroy()
196
{
197
        // Free the C++ class.
198
        delete this;
199
}
200
 
201
int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
202
{
203
        if (CWnd::OnCreate(lpCreateStruct) == -1)
204
                return -1;
205
 
206
        // Center the window.
207
        CenterWindow();
208
 
209
        // Set a timer to destroy the splash screen.
210
        SetTimer(1, 3000, NULL);
211
 
212
        return 0;
213
}
214
 
215
void CSplashWnd::OnPaint()
216
{
217
        CPaintDC dc(this);
218
 
219
        CDC dcImage;
220
        if (!dcImage.CreateCompatibleDC(&dc))
221
                return;
222
 
223
        BITMAP bm;
224
        m_bitmap.GetBitmap(&bm);
225
        // Paint the image.
226
        CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
227
        dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
228
        dcImage.SelectObject(pOldBitmap);
229
 
230
        for(int i=0;i<bm.bmHeight;i++){
231
                COLORREF col=PALETTERGB(0,0,(255*i)/bm.bmHeight);
232
                CRect rect(0,i,bm.bmWidth,i+2);
233
                dcImage.FillSolidRect(&rect, col);
234
        }
235
        dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, MERGEPAINT);
236
 
237
}
238
 
239
void CSplashWnd::OnTimer(UINT nIDEvent)
240
{
241
        // Destroy the splash screen window.
242
        HideSplashScreen();
243
        UNUSED_ALWAYS(nIDEvent);
244
}
245
 
246
void CSplashWnd::CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)
247
{
248
   LPBITMAPINFOHEADER   lpbi;
249
   LPLOGPALETTE                 lpPal;
250
   HANDLE                               hLogPal;
251
   int                                  i;
252
 
253
   lpbi = (LPBITMAPINFOHEADER)lpbmi;
254
   if (lpbi->biBitCount <= 8)
255
       *lpiNumColors = (1 << lpbi->biBitCount);
256
   else
257
       *lpiNumColors = 0;  // No palette needed for 24 BPP DIB
258
 
259
   if (*lpiNumColors)
260
      {
261
      hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) +
262
                             sizeof (PALETTEENTRY) * (*lpiNumColors));
263
      lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);
264
      lpPal->palVersion    = 0x300;
265
      lpPal->palNumEntries = (unsigned short)*lpiNumColors;
266
 
267
      for (i = 0;  i < *lpiNumColors;  i++)
268
         {
269
         lpPal->palPalEntry[i].peRed   = lpbmi->bmiColors[i].rgbRed;
270
         lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
271
         lpPal->palPalEntry[i].peBlue  = lpbmi->bmiColors[i].rgbBlue;
272
         lpPal->palPalEntry[i].peFlags = 0;
273
         }
274
      Palette.CreatePalette(lpPal);
275
          GlobalUnlock (hLogPal);
276
      GlobalFree   (hLogPal);
277
   }
278
   return ;
279
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.