15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Splash screen with 256 color bitmaps

Rene M. Laviolette -- mti@map.com
Monday, January 29, 1996

Has anyone modified the Splash component that comes with MSVC++ 4.0 to
handle 256 color bitmaps?  I've tried changing it to handle DIBs but I've
hadn't had any success.

Any suggestions will be appreciated.

Thanks,

Rene M. Laviolette




Terry Wellmann -- wellmatl@cs.purdue.edu
Tuesday, January 30, 1996

[Mini-digest: 3 responses]

>Has anyone modified the Splash component that comes with MSVC++ 4.0 to
>handle 256 color bitmaps?  I've tried changing it to handle DIBs but I've
>hadn't had any success.
>
>Any suggestions will be appreciated.
>
>Thanks,
>
>Rene M. Laviolette


Yes, I've done this!

I don't have the code here at home, but I'll bring it home from work
tomorrow.  I just added a member function to the CSplash class and it'll
load a DIB from the resource file of an app and display it.

Terry

-----------------------------------------------------------------------
|                          Terry Wellmann                             |
|                  CS Major - Purdue University                       |
|             Programmer/Systems Analyst - M.A.I.L.code Inc.          |
|                   E-Mail: wellmatl@cs.purdue.edu                    |
|              http://www.cs.purdue.edu/people/wellmatl               |
|=====================================================================|
|                                                                     |
| " ..655,360 bytes is more than enough for any application we could  |
|     ever develop."         - Bill Gates in PC Monthly, Aug. 1983    |
|                                                                     |
-----------------------------------------------------------------------



-----From: Brad Wilson 

Rene M. Laviolette wrote:
 
> Has anyone modified the Splash component that comes with MSVC++ 4.0 to
> handle 256 color bitmaps?  I've tried changing it to handle DIBs but I've
> hadn't had any success.

What color depth is your display running at?  If you're running in 256
color mode, you need to realize the pallete of the bitmap (the bitmap
should automagically look fine in high and true color mode).

--
class CBradWilson : public CWorldWatchProgrammingTeam {
  public:
    void GetInetAddr  ( CString& s ) { s = "bradw@exptech.com";      }
    void GetE164Addr  ( CString& s ) { s = "+1 (810) 620-9803";      }
    void GetURL       ( CString& s ) { s = "http://www.exptech.com"; }
    void GetDisclaimer( CString& s ) { s = "All I say is fact :-p";  }
};

//  QOTW:  "Don't think of yourself as the least intelligent creature in this
//          room ... if you consider the entire planet, you're smarter than
//          literally hundreds of people."  - Dogbert to Dilbert
-----From: Mario Contestabile 

>Has anyone modified the Splash component that comes with MSVC++ 4.0 to
>handle 256 color bitmaps?  I've tried changing it to handle DIBs but I've
>hadn't had any success.

See Q132705

" make sure 256 Colors is selected in the Color Palette combo box
in the Display Applet of the Control Panel."




Steve Goyette -- steveg@gemcom.bc.ca
Tuesday, January 30, 1996


------ =_NextPart_000_01BAEF0A.A8F43CC0
Content-Type: text/plain; charset="us-ascii"



Martin Wawrusch -- wawrusch@accs.co.at
Thursday, February 01, 1996

[Mini-digest: 2 responses]

On Jan 30, 12:01pm, Steve Goyette wrote:
> Subject: RE: Splash screen with 256 color bitmaps
>
> [ text/plain
>   Encoded with "quoted-printable" ] :
>
> Hi,
>
> Yeah, that 16 color splash screen wasn't very useful.  Here's my modified version which calls 2
functions to load the bitmap and create the palette.  These functions are almost verbatim from a
knowledge base article on how to load 256 color bitmaps from a resource (I can't remember the KB #)
>
> [[ SPLASH25.ZIP : 5137 in WINMAIL.DAT ]]
> B.T.W, you'll notice that I've commented out the HideSpashScreen() call in PreTranslateMessage.

This was a temporary fix for a problem where the program crashed if you closed the splash before
it's timer expired.  I never got around to fixing this, so if Anyone else has I would appreciate a
pointer.

You should change the HideSplashScreen function to the following:

void CSplashScreen::HideSplashScreen()
{
	DestroyWindow();
	if(AfxGetMainWnd()) // <-- new
		AfxGetMainWnd()->UpdateWindow();
}

This does the trick

Martin

-- 
Martin Wawrusch			| ESBMASAP, BNS  A. Einstein
ACCS Software			| Tel. : +43 1 983 46 91 
Huetteldorferstr. 163/23	| Fax. : +43 1 983 01 00
A-1140 Vienna, Austria		| EMail: wawrusch@accs.co.at
-----From: Steve Goyette 

Hi All,

I got quite a few requests to re-post this in ASCII as the MIME decoded one I sent from MS Exchange didn't quite work out.  Here you go:


<<<<<<<<<<<<<<<<<<<<  CUT HERE >>>>>>>>>>>>>>>>>>>>>>>>

// CG: This file was added by the Splash Screen component.
// Splash.cpp : implementation file
//

#include "stdafx.h"  // e. g. stdafx.h
#include "resource.h"  // e.g. resource.h

#include "Splash.h"  // e.g. splash.h

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
//   Splash Screen class

BOOL GSplashWnd::c_bShowSplashWnd;
GSplashWnd* GSplashWnd::c_pSplashWnd;
GSplashWnd::GSplashWnd()
	{
	m_pBitmap = NULL;
	}

GSplashWnd::~GSplashWnd()
	{
	// Clear the static window pointer.
	ASSERT(c_pSplashWnd == this);
	c_pSplashWnd = NULL;
	}

BEGIN_MESSAGE_MAP(GSplashWnd, CWnd)
	//{{AFX_MSG_MAP(GSplashWnd)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void GSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
	{
	c_bShowSplashWnd = bEnable;
	}

void GSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
	{
	if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
		return;

	// Allocate a new splash screen, and create the window.
	c_pSplashWnd = new GSplashWnd;
	if (!c_pSplashWnd->Create(pParentWnd))
		delete c_pSplashWnd;
	else
		c_pSplashWnd->UpdateWindow();
	}

void GSplashWnd::PreTranslateAppMessage(MSG* pMsg)
	{
	if (c_pSplashWnd == NULL)
		return;

	// If we get a keyboard or mouse message, hide the splash screen.
	if (pMsg->message == WM_KEYDOWN ||
	    pMsg->message == WM_SYSKEYDOWN ||
	    pMsg->message == WM_LBUTTONDOWN ||
	    pMsg->message == WM_RBUTTONDOWN ||
	    pMsg->message == WM_MBUTTONDOWN ||
	    pMsg->message == WM_NCLBUTTONDOWN ||
	    pMsg->message == WM_NCRBUTTONDOWN ||
	    pMsg->message == WM_NCMBUTTONDOWN)
		{
//		c_pSplashWnd->HideSplashScreen();
		}
	}

BOOL GSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
	{
	HPALETTE hPalette;
	HBITMAP hSplash = LoadResourceBitmap(IDB_SPLASH, &hPalette);
	if (hSplash)
		{
		m_pBitmap = CBitmap::FromHandle(hSplash);
		}
	else 
		return FALSE;

	BITMAP bm;
	m_pBitmap->GetBitmap(&bm);

	return CreateEx(0,AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
		NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
	}

void GSplashWnd::HideSplashScreen()
	{
	// Destroy the window, and update the mainframe.
	DestroyWindow();
	AfxGetMainWnd()->UpdateWindow();
	}

void GSplashWnd::PostNcDestroy()
	{
	// Free the C++ class.
	delete this;
	}

int GSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
	{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	// Center the window.
	CenterWindow();

	// Set a timer to destroy the splash screen.
	SetTimer(1, 3000, NULL);

	return 0;
	}

void GSplashWnd::OnPaint()
	{
	CPaintDC dc(this);

	CDC dcImage;
	if (!dcImage.CreateCompatibleDC(&dc))
		return;

	::SelectPalette( dc.m_hDC, m_hPalette, FALSE );
	::RealizePalette( dc.m_hDC );
	::SelectPalette( dcImage.m_hDC, m_hPalette, FALSE); 
	::RealizePalette( dcImage.m_hDC);

	BITMAP bm;
	m_pBitmap->GetBitmap(&bm);

	// Paint the image.
	CBitmap* pOldBitmap = dcImage.SelectObject(m_pBitmap);
	dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
	dcImage.SelectObject(pOldBitmap);
	}

void GSplashWnd::OnTimer(UINT nIDEvent)
	{
	// Destroy the splash screen window.
	HideSplashScreen();
	}

HBITMAP GSplashWnd::LoadResourceBitmap(UINT uResrc, HPALETTE FAR* lphPalette) 
	{ 
	HINSTANCE hInstance = AfxGetInstanceHandle();
	HRSRC  hRsrc; 
	HGLOBAL hGlobal; 
	HBITMAP hBitmapFinal = NULL; 
	LPBITMAPINFOHEADER  lpbi; 
	HDC hdc; 
	int iNumColors; 

	if (hRsrc = FindResource(NULL, MAKEINTRESOURCE(uResrc), RT_BITMAP)) 
		{ 
		hGlobal = LoadResource(hInstance, hRsrc); 
		lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal); 
		hdc = ::GetDC(NULL); 
		*lphPalette =  CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors); 
		if (*lphPalette) 
			{ 
			SelectPalette(hdc,*lphPalette,FALSE); 
			RealizePalette(hdc); 
			} 
  
		hBitmapFinal = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi, 
												(LONG)CBM_INIT, 
												(LPSTR)lpbi + lpbi->biSize + iNumColors * 
												sizeof(RGBQUAD), 
												(LPBITMAPINFO)lpbi, 
												DIB_RGB_COLORS ); 
  
		::ReleaseDC(NULL,hdc); 
		UnlockResource(hGlobal); 
		FreeResource(hGlobal); 
		} 
	return (hBitmapFinal); 
	} 
  
HPALETTE GSplashWnd::CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors) 
	{ 
	LPBITMAPINFOHEADER  lpbi; 
	LPLOGPALETTE     lpPal; 
	HANDLE           hLogPal; 
	HPALETTE         hPal = NULL; 
	int              i; 
  
	lpbi = (LPBITMAPINFOHEADER)lpbmi; 
	if (lpbi->biBitCount <= 8) 
		*lpiNumColors = (1 << lpbi->biBitCount); 
	else 
		*lpiNumColors = 0;  // No palette needed for 24 BPP DIB 
  
	if (*lpiNumColors) 
		{ 
		hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) + 
									sizeof (PALETTEENTRY) * (*lpiNumColors)); 
		lpPal = (LPLOGPALETTE) GlobalLock (hLogPal); 
		lpPal->palVersion    = 0x300; 
		lpPal->palNumEntries = *lpiNumColors; 

		for (i = 0;  i < *lpiNumColors;  i++) 
			{ 
			lpPal->palPalEntry[i].peRed   = lpbmi->bmiColors[i].rgbRed; 
			lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen; 
			lpPal->palPalEntry[i].peBlue  = lpbmi->bmiColors[i].rgbBlue; 
			lpPal->palPalEntry[i].peFlags = 0; 
			} 
		hPal = CreatePalette (lpPal); 
		GlobalUnlock (hLogPal); 
		GlobalFree   (hLogPal); 
		} 
	return hPal; 
	} 

<<<<<<<<<<<<<<<<<<<<<<<<< CUT HERE >>>>>>>>>>>>>>>>>>>>>
// CG: This file was added by the Splash Screen component.

#ifndef _SPLASH_SCRN_
#define _SPLASH_SCRN_

// Splash.h : header file
//

/////////////////////////////////////////////////////////////////////////////
//   Splash Screen class

class GSplashWnd : public CWnd
{
// Construction
protected:
	GSplashWnd();

// Attributes:
public:
	CBitmap *m_pBitmap;
	HPALETTE m_hPalette;

// Operations
public:
	static void EnableSplashScreen(BOOL bEnable = TRUE);
	static void ShowSplashScreen(CWnd* pParentWnd = NULL);
	static void PreTranslateAppMessage(MSG* pMsg);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(GSplashWnd)
	//}}AFX_VIRTUAL

// Implementation
public:
	~GSplashWnd();
	virtual void PostNcDestroy();

protected:
	BOOL Create(CWnd* pParentWnd = NULL);
	void HideSplashScreen();
	static BOOL c_bShowSplashWnd;
	static GSplashWnd* c_pSplashWnd;
	HBITMAP LoadResourceBitmap(UINT uResrc, HPALETTE FAR* lphPalette); 
	HPALETTE CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors);

// Generated message map functions
protected:
	//{{AFX_MSG(GSplashWnd)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnPaint();
	afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


#endif



In Visio -- jnp12@calvanet.calvacom.fr
Monday, February 05, 1996

I think there's a problem with m_hPalette :

>BOOL GSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
>	{
>	HPALETTE hPalette;
>	HBITMAP hSplash = LoadResourceBitmap(IDB_SPLASH, &hPalette);
>

should be :

>BOOL GSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
>	{
>	HBITMAP hSplash = LoadResourceBitmap(IDB_SPLASH, &m_hPalette);

or else you select m_hPalette OnPaint, which has never been set.


-----------------------------------------------------------------------
Laurent Mouton
In Visio
21 av. Francois Favre
74000 ANNECY
FRANCE

Tel: +33 50-27-80-32
Fax: +33 50-23-35-07





Niels Ull Jacobsen -- nuj@kruger.dk
Wednesday, February 07, 1996

> 
> I think there's a problem with m_hPalette :
> 
> >BOOL GSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
> >	{
> >	HPALETTE hPalette;
> >	HBITMAP hSplash = LoadResourceBitmap(IDB_SPLASH, &hPalette);
> >
> 
> should be :
> 
> >BOOL GSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
> >	{
> >	HBITMAP hSplash = LoadResourceBitmap(IDB_SPLASH, &m_hPalette);
> 
> or else you select m_hPalette OnPaint, which has never been set.
> 

There are a few other problems with the code.

The palette created isn't deleted.

Also, the CBitmap* m_pBitmap is initialised from a
CBitmap::FromHandle().  It is thus a temporary bitmap which will be
freed next time the application is idle, which means it will be
invalid if OnPaint is called later on. If your splash window only
stays up for a brief period, you won't notice it (until you get a
faster machine) but you can try setting it to stay up for 30 seconds
and force it to repaint (e.g. by dragging dragging another window over
it).

The simplest solution is probably to add a CPalette member and a
CBitmap member to the dialog and then Attach them to the appropriate
handles. This will also take care of freeing them in the destructor.


> Laurent Mouton

--
Niels Ull Jacobsen, Kruger A/S

Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
group and should be taken as legally binding in every respect. Pigs
will grow wings and fly.









| Вернуться в корень Архива |