Click here to Skip to main content
15,915,319 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionIPX programming. Posible in windows? Pin
Markus25-May-00 9:12
Markus25-May-00 9:12 
AnswerRe: IPX programming. Posible in windows? Pin
Frank Deo25-May-00 10:29
Frank Deo25-May-00 10:29 
AnswerRe: IPX programming. Posible in windows? Pin
Alex Gorev25-May-00 10:29
Alex Gorev25-May-00 10:29 
AnswerRe: IPX programming. Posible in windows? Pin
Member 120896525-May-00 11:05
Member 120896525-May-00 11:05 
GeneralRe: IPX programming. Posible in windows? Pin
Markus25-May-00 12:24
Markus25-May-00 12:24 
GeneralRe: IPX programming. Posible in windows? Pin
Member 120896525-May-00 12:52
Member 120896525-May-00 12:52 
QuestionSplash screen on dialog-based? Pin
Member 1176625725-May-00 5:59
Member 1176625725-May-00 5:59 
AnswerRe: Splash screen on dialog-based? Pin
Andrebon25-May-00 15:21
Andrebon25-May-00 15:21 
Hello?

First, Make Bitmap Resource, for example IDB_SPLASH

Second, Add Next Class to your Project(Dialog-Based)
/////////////////////////////////////////////
MySplashWnd.h

#if !defined(AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_)
#define AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// MySplashWnd.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMySplashWnd window

class CMySplashWnd : public CWnd
{
// Construction
public:
CMySplashWnd(UINT nBitmapID, UINT nDuration = 2500);

// Attributes
public:
BOOL Create();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMySplashWnd)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL

// Implementation
public:

// Generated message map functions
protected:
//{{AFX_MSG(CMySplashWnd)
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

protected:
BOOL GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal);

protected:
UINT m_nBitmapID;
UINT m_nDuration;
UINT m_nTimerID;
CBitmap m_bitmap;
CPalette m_pal;
CWnd m_wndInvisible;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_)

MySplashWnd.cpp


// MySplashWnd.cpp : implementation file
//

#include "stdafx.h"
#include "RichEdit.h"
#include "SplashWnd.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMySplashWnd

CMySplashWnd::CMySplashWnd(UINT nBitmapID, UINT nDuration /*= 2500*/)
{
m_nBitmapID = nBitmapID;
m_nDuration = nDuration;
}

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



BOOL CMySplashWnd::Create()
{
if( !GetBitmapAndPalette(m_nBitmapID, m_bitmap, m_pal) )
{
TRACE1( "Could not load bitmap resource - %d\n", m_nBitmapID );
return FALSE;
}


BITMAP bm;
m_bitmap.GetObject(sizeof(BITMAP), &bm);

// First create an invisible window
m_wndInvisible.CreateEx(WS_EX_TOPMOST,
AfxRegisterWndClass(CS_CLASSDC),
_T(""), WS_POPUP, 0, 0,
bm.bmWidth, bm.bmHeight, NULL, NULL);

// Create the the splash window with invisible parent as parent
BOOL bRetVal = CWnd::CreateEx(WS_EX_TOPMOST,
AfxRegisterWndClass(CS_CLASSDC),
_T(""), WS_POPUP, 0, 0,
bm.bmWidth, bm.bmHeight, m_wndInvisible.m_hWnd, NULL);

CenterWindow();
ShowWindow(SW_SHOW);
UpdateWindow();

//Create the timer.
m_nTimerID = SetTimer(1, m_nDuration, NULL);
ASSERT(m_nTimerID);

return bRetVal;
}


BOOL CMySplashWnd::GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal)
{
LPCTSTR lpszResourceName = (LPCTSTR)nIDResource;

HBITMAP hBmp = (HBITMAP)::LoadImage( AfxGetInstanceHandle(),
lpszResourceName, IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION );

if( hBmp == NULL )
return FALSE;

bitmap.Attach( hBmp );

// Create a logical palette for the bitmap
DIBSECTION ds;
BITMAPINFOHEADER &bmInfo = ds.dsBmih;
bitmap.GetObject( sizeof(ds), &ds );

int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << bmInfo.biBitCount;

// Create a halftone palette if colors > 256.
CClientDC dc(NULL); // Desktop DC
if( nColors > 256 )
pal.CreateHalftonePalette( &dc );
else
{
// Create the palette

RGBQUAD *pRGB = new RGBQUAD[nColors];
CDC memDC;
memDC.CreateCompatibleDC(&dc);

memDC.SelectObject( &bitmap );
::GetDIBColorTable( memDC, 0, nColors, pRGB );

UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];

pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;

for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = pRGB[i].rgbRed;
pLP->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
pLP->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
}

pal.CreatePalette( pLP );

delete[] pLP;
delete[] pRGB;
}

return TRUE;
}

void CMySplashWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting

// Create a memory DC compatible with the paint DC
CDC memDC;
memDC.CreateCompatibleDC( &dc );

CBitmap *pBmpOld = memDC.SelectObject( &m_bitmap );

// Select and realize the palette
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && m_pal.m_hObject != NULL )
{
dc.SelectPalette( &m_pal, FALSE );
dc.RealizePalette();
}


// Window is same size as bitmap
CRect rcWnd;
GetWindowRect( &rcWnd );
dc.BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &memDC, 0, 0,SRCCOPY);

// Restore bitmap in memDC
memDC.SelectObject( pBmpOld );

// Do not call CWnd::OnPaint() for painting messages
}

void CMySplashWnd::OnTimer(UINT nIDEvent)
{
if (m_nTimerID == nIDEvent)
{
//Destroy the timer and splash window
KillTimer(m_nTimerID);
m_wndInvisible.DestroyWindow();
delete this;
return;
}

CWnd::OnTimer(nIDEvent);
}

BOOL CMySplashWnd::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);

if (pMsg->message == WM_KEYDOWN ||
pMsg->message == WM_SYSKEYDOWN ||
pMsg->message == WM_LBUTTONDOWN ||
pMsg->message == WM_RBUTTONDOWN ||
pMsg->message == WM_MBUTTONDOWN )
{
//Destroy the timer and splash window
KillTimer(m_nTimerID);
m_wndInvisible.DestroyWindow();
delete this;
return 1;
}

return CWnd::PreTranslateMessage(pMsg);
}






Third, Insert next code at Initinstance().

if( cmdInfo.m_bShowSplash ) {
CMySplashWnd * pSplashWnd = new CMySplashWnd(IDB_SPLASH, 3000);
pSplashWnd->Create();
}


It's All!!

Good Luck
GeneralDrawing from memoryDC to deviceDC using 256 colours only. Pin
David Bru25-May-00 5:15
David Bru25-May-00 5:15 
GeneralOn Top Pin
Member 434825-May-00 4:05
Member 434825-May-00 4:05 
GeneralRe: On Top Pin
Dmitriy25-May-00 9:30
Dmitriy25-May-00 9:30 
GeneralImplementation Magnetic effect to ControlBar Pin
Andrebon25-May-00 0:41
Andrebon25-May-00 0:41 
GeneralRe: Implementation Magnetic effect to ControlBar Pin
Cristi Posea26-May-00 19:12
Cristi Posea26-May-00 19:12 
GeneralDos command from mfc app Pin
Tim Hodgson24-May-00 11:48
Tim Hodgson24-May-00 11:48 
GeneralRe: Dos command from mfc app Pin
imsniper24-May-00 21:06
imsniper24-May-00 21:06 
GeneralRe: Dos command from mfc app Pin
Tim Hodgson25-May-00 3:34
Tim Hodgson25-May-00 3:34 
GeneralRe: Dos command from mfc app Pin
Peter Zajac25-May-00 4:41
Peter Zajac25-May-00 4:41 
GeneralRe: Dos command from mfc app Pin
Tim Hodgson25-May-00 7:07
Tim Hodgson25-May-00 7:07 
GeneralRe: Dos command from mfc app Pin
Konstantin Vasserman25-May-00 12:15
Konstantin Vasserman25-May-00 12:15 
GeneralRe: Dos command from mfc app Pin
Tim Deveaux25-May-00 13:46
Tim Deveaux25-May-00 13:46 
GeneralRe: Dos command from mfc app Pin
Mike Dunn25-May-00 16:42
Mike Dunn25-May-00 16:42 
GeneralFrom Visual C++ to Borland C++ Pin
James Khan24-May-00 9:10
James Khan24-May-00 9:10 
GeneralRe: From Visual C++ to Borland C++ Pin
Tim Deveaux24-May-00 14:05
Tim Deveaux24-May-00 14:05 
GeneralBorland C++ sites like code tools Pin
James Khan24-May-00 9:04
James Khan24-May-00 9:04 
GeneralRe: Borland C++ sites like code tools Pin
Arvind2324-May-00 13:55
Arvind2324-May-00 13:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.