⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shadow_dc.h

📁 一个完整的桌面日历程序
💻 H
字号:
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																					-
// - File:			shadow_dc.h.																														-
// -																																					-
// - Contents: 		Interface of class CShadowDC.																										-
// -																																					-
// - Purpose:  		A mem-dc class.																														-
// -																																					-
// - Remarks:    	'Shadow' meaning 'hidden' in the mem-dc sense.																						-
// -																																					-
// - Originator: 	Michael Mogensen, MM-IT Consult 2003.																								-
// -																																					-
// - Compiler:		MS Visual C++ ver6.0.																											    -
// -																																					-
// - Period:		00.00.00 - 00.00.00.																											    -
// -																																					-
// - Version:		1.00. 																																-
// -																																					-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Header(s).																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "geometryex.hpp"

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - CShadowDC.																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
class CShadowDC : public CDC
{
	public:
		// Data.
		bool m_bIsOk;
		CBitmap m_bmp_2DrawOn, 
				*m_pbmp_Orig;
		CDC *m_pdc;
		CPointEx m_ipOffset;
		CRectEx m_ir2DrawOn;
		// Object.
		inline CShadowDC(CDC *pdc, const CRectEx &ir2DrawOn = CRectEx(0, 0, 0, 0)) : 
			m_bIsOk(false), 
			m_ir2DrawOn(CRectEx(0, 0, ir2DrawOn.Width(), ir2DrawOn.Height())), 
			m_pbmp_Orig(NULL), 
			m_pdc(pdc), 
			CDC()
			{ Orig2This(pdc); }
		inline ~CShadowDC()
		{ This2Orig(); }
	    inline CShadowDC* operator->()
		{ return this; }
		inline operator CShadowDC*()
		{ return this; }
		inline const void Copy(CWnd *pWnd)
		{
			CRectEx irWindow;
			::GetClientRect(pWnd->GetSafeHwnd(), (LPRECT)&irWindow);
			CDC *pdc = pWnd->GetDC();
			BitBlt(
				0, 
				0, 
				irWindow.Width(), 
				irWindow.Height(), 
				pdc, 
				0, 
				0, 
				SRCCOPY);
			pWnd->ReleaseDC(pdc);
		}
		// Slaves.
		inline const CRectEx GetDrawRect()
		{ return m_ir2DrawOn; }
		inline const void SetOffset(const int iDelta_X, const int iDelta_Y)
		{ m_ipOffset.Set(iDelta_X, iDelta_Y); }
	protected:
		// Slaves.
		inline const void Orig2This(CDC *pdc)
		// Setup copy to work on.
		{
			ASSERT(m_pdc != NULL);
			m_bIsOk = !m_pdc->IsPrinting();
			if(m_bIsOk)
			{
				if(m_ir2DrawOn.IsRectEmpty())
		            m_pdc->GetClipBox(&m_ir2DrawOn);
				CreateCompatibleDC(pdc);
				m_bmp_2DrawOn.CreateCompatibleBitmap(
					pdc, 
					m_ir2DrawOn.Width(), 
					m_ir2DrawOn.Height());
				m_pbmp_Orig = SelectObject(&m_bmp_2DrawOn);
				SetWindowOrg(
					m_ir2DrawOn.left, 
					m_ir2DrawOn.top);
			}
			else
			{
				m_bPrinting = pdc->m_bPrinting;
				m_hDC = pdc->m_hDC;
				m_hAttribDC = pdc->m_hAttribDC;
			}
		}
		inline const void This2Orig()
		// Move copy back to orig. to make it show.
		{
			if(m_pdc) 
			{	
				m_pdc->BitBlt(
					m_ir2DrawOn.left, 
					m_ir2DrawOn.top, 
					m_ir2DrawOn.left + m_ir2DrawOn.right, 
					m_ir2DrawOn.top + m_ir2DrawOn.bottom, 
					this, 
					m_ipOffset.x, 
					m_ipOffset.y, 
					SRCCOPY);
				SelectObject(m_pbmp_Orig);
			}
			else
			{
				m_hDC = m_hAttribDC = NULL;
			}
		}
};

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																				  	-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// 0. Data. (alphabetical).
// 1. Object. (alphabetical).
// 2. Event's. (alphabetical).
// 3.0. Menu choice. (menu order).
// 3.1. Menu choice, enablers. (menu order).
// 4. Slaves. (alphabetical).
// 5. Other. (alphabetical).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -