Click here to Skip to main content
15,891,828 members
Articles / Desktop Programming / WTL

Outlook Bar for WTL (with XP support!!)

Rate me:
Please Sign up or sign in to vote.
4.73/5 (17 votes)
7 Nov 2007MIT10 min read 64.7K   2.4K   60  
A themed Outlook Bar for WTL (works even without themes).
/** \page wtlgdiex wtlgdiex.h
 *
 *  \section License License
 *  Copyright (c) 2005, 2006 Massimiliano Alberti <xanatos@geocities.com>
 *
 *  Permission is hereby granted, free of charge, to any person obtaining
 *  a copy of this software and associated documentation files (the
 *  "Software"), to deal in the Software without restriction, including
 *  without limitation the rights to use, copy, modify, merge, publish,
 *  distribute, sublicense, and/or sell copies of the Software, and to
 *  permit persons to whom the Software is furnished to do so, subject
 *  to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included
 *  in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 *  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 *  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *  \section VersionHistory Version History
 *  \li wtlgdiex.h   1.0	May 2006  Initial Release
 *
 */

/** \file
 *  This header contains various extended classes for WTL.
 */

#pragma once

#ifndef __CMEMORYSTRIPDC__
#define __CMEMORYSTRIPDC__

#ifndef __ATLGDI_H__
#error wtlgdiex.h requires atlgdi.h to be included first
#endif

//

namespace WTL
{

//

/// A variant of WTL::CMemoryDC usable to paint "strips" one at a time
/** ~CMemoryStripDC DOESN'T draw the cached DC. You must explicitally draw it with
 *  Draw(). When you want to move the strip you can use Move().
 *  Note that you can Draw(), Move() and Draw() again.
 */
class CMemoryStripDC : public CDC
{
public:
	HDC m_hDCOriginal;	///< The original DC
	RECT m_rcPaint;		///< The rectangle that CMemoryStripDC will cache
	CBitmap m_bmp;		///< The bitmap where the drawing will be cached
	HBITMAP m_hBmpOld;	///< The original bitmap (received from the SelectBitmap)

	/// Constructor
	/** \param hDC The original DC
	 *  \param rcPaint The rectangle that CMemoryStripDC will cache
	 */
	CMemoryStripDC(HDC hDC, RECT& rcPaint) : m_hDCOriginal(hDC), m_hBmpOld(NULL)
	{
		ATLASSERT(hDC != NULL);

		m_rcPaint = rcPaint;

		ATLVERIFY(CreateCompatibleDC(m_hDCOriginal));
		ATLVERIFY(m_bmp.CreateCompatibleBitmap(m_hDCOriginal, m_rcPaint.right - m_rcPaint.left, m_rcPaint.bottom - m_rcPaint.top));

		m_hBmpOld = SelectBitmap(m_bmp);

		ATLVERIFY(SetViewportOrg(-m_rcPaint.left, -m_rcPaint.top));
	}

	/// Destructor
	~CMemoryStripDC()
	{
		SelectBitmap(m_hBmpOld);
	}

	/// BitBlt the cached bitmap to the original DC. The cached bitmap is still valid after drawing
	void Draw()
	{
		ATLVERIFY(::BitBlt(m_hDCOriginal, m_rcPaint.left, m_rcPaint.top, m_rcPaint.right - m_rcPaint.left, m_rcPaint.bottom - m_rcPaint.top, m_hDC, m_rcPaint.left, m_rcPaint.top, SRCCOPY));
	}

	/// Moves the Viewport. The cached bitmap is still valid after calling this method
	/** \param ix New x coordinate of the rectangle (the width can't be changed and will be the same as before)
	 *  \param iy New y coordinate of the rectangle (the height can't be changed and will be the same as before)
	 */
	void Move(int ix, int iy)
	{
		m_rcPaint.bottom = (m_rcPaint.bottom - m_rcPaint.top) + iy;
		m_rcPaint.top = iy;
		m_rcPaint.right = (m_rcPaint.right - m_rcPaint.left) + ix;
		m_rcPaint.left = ix;

		ATLVERIFY(SetViewportOrg(-m_rcPaint.left, -m_rcPaint.top));
	}

	/// Zeroes the cached bitmap (the bitmap will then represent be a black rectangle)
	void Empty()
	{
		ATLVERIFY(::BitBlt(m_hDC, m_rcPaint.left, m_rcPaint.top, m_rcPaint.right - m_rcPaint.left, m_rcPaint.bottom - m_rcPaint.top, NULL, 0, 0, BLACKNESS));
	}
};

}; // namespace WTL

#endif // __CMEMORYSTRIPDC__

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, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions