Click here to Skip to main content
15,897,704 members
Articles / Desktop Programming / MFC

FaderWnd - a Window Fader for Windows 2000

Rate me:
Please Sign up or sign in to vote.
4.65/5 (7 votes)
28 Jun 2000 164.3K   3K   56  
An MFC class to fade any window with only one line of code.
/*----------------------------------------------------------------------------*/
//
//	File:			ChildView.cpp
//	Author:		Phil J. Pearson
//	Created:	23 June 2000  19:10
//	Last Mod: 23 June 2000  19:11
//
/*----------------------------------------------------------------------------
/*
/* Copyright (C) 2000 by Real World Software
/* All Rights Reserved.
/*
/*----------------------------------------------------------------------------*/

#include "stdafx.h"
#include "FaderDemo.h"
#include "ChildView.h"

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


/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
{
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
	{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

	return TRUE;
	}


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

	static bool bLoaded = false;

	if (!bLoaded)
		{
		HBITMAP hBitmap = (HBITMAP)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_RWS),
																						IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
		m_Bitmap.Attach(hBitmap);
		bLoaded = true;
		}

	BITMAP	bm;
	CDC			dcMem;
	CRect		rc;

	GetClientRect(rc);

	m_Bitmap.GetBitmap(&bm);
	int x = (rc.Width() - bm.bmWidth) / 2;
	int y = (rc.Height() - bm.bmHeight) / 2;
	dcMem.CreateCompatibleDC(&dc);
	dcMem.SelectObject(m_Bitmap);
	dc.BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
	}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions