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

📄 extpaintmanager.cpp

📁 FormEditor,模拟Visual Basic窗口编辑界面
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				bHorz,
				sTitle,
				hIcon,
				rectClient2,
				rectCaption,
				bPushed,
				bEnabled,
				bHover,
				eAlign
				);
		} // if( hIcon != NULL )
		else
		{
			PaintSysCmdGlyph(
				dc,
				nHelperSysCmdID,
				rectClient2,
				false,
				bPushed,
				bEnabled
				);
		}
	}

	if( rectCaption.bottom > rectCaption.top
		&& rectCaption.right > rectCaption.left
		)
	{ // if we have valid area for text & focus rect
		if( !sTitle.IsEmpty() )
		{
			if( bPushed )
			{
				CSize sizePushedOffset = GetPushedOffset();
				rectCaption.OffsetRect(sizePushedOffset);
			}
			dc.SetBkColor( bgColor );

			if( bEnabled )
			{
				if( bHover || bPushed ) 
					dc.SetTextColor(
						GetColor(COLOR_3DDKSHADOW)
						);
				else 
					dc.SetTextColor(
						GetColor(
							COLOR_BTNTEXT /// !?!?!COLOR_HIGHLIGHTTEXT
							)
						);
			} // if( bEnabled )
			else
			{
				dc.SetTextColor(
					GetColor(COLOR_3DFACE)
					);
			} // else from if( bEnabled )

/*
			// center text
			CRect centerRect = rectCaption;
*/

			CFont * pOldBtnFont = NULL;
			CFont * pCurrFont = NULL;
			CFont fontDummy;

			if( pFont != NULL )
			{
				ASSERT( pFont->GetSafeHandle() != NULL );
				if( bHorz )
					pCurrFont = pFont;
				else
				{
					LOGFONT lf;
					::memset(&lf,0,sizeof(LOGFONT));
					pFont->GetLogFont(&lf);
					if( lf.lfEscapement == 0 )
					{
						lf.lfEscapement = __VERT_FONT_ESCAPEMENT__;
						VERIFY(
							fontDummy.CreateFontIndirect(&lf)
							);
						pCurrFont = &fontDummy;
					}
					else
					{
						// suppose font already prepared
						pCurrFont = pFont;
					}
				}
			} // if( pFont != NULL )
			else
			{
				if( bHorz )
				{
					if( bDefaultPushButton )
						pCurrFont = &m_FontBold;
					else
						pCurrFont = &m_FontNormal;
				}
				else
				{
					if( bDefaultPushButton )
						pCurrFont = &m_FontBoldVert;
					else
						pCurrFont = &m_FontNormalVert;
				}
			} // else from if( pFont != NULL )
			ASSERT( pCurrFont != NULL );
			pOldBtnFont = dc.SelectObject( pCurrFont );
			ASSERT( pOldBtnFont != NULL );

			int nTextLength = sTitle.GetLength();
			int nAmpIndex = sTitle.Find( _T('&') );
			CString sBtn;
			if( nAmpIndex < 0 )
				sBtn = sTitle;
			else
				sBtn =
					sTitle.Left(nAmpIndex)
					+ sTitle.Right(nTextLength - (nAmpIndex+1)
					);
			ASSERT( sBtn.Find( _T('&') ) < 0 );

			CRect rcText(0,0,0,0);
			dc.DrawText(
				sBtn,
				-1,
				rcText,
				DT_SINGLELINE|DT_CALCRECT
				);
			CRect rcCenteredCaption(rectCaption);
			rcCenteredCaption.OffsetRect(
				(rectCaption.Width() - rcText.Width())/2,
				(rectCaption.Height() - rcText.Height())/2
				);

			if( bHorz )
			{
/*
				dc.DrawText(
					sTitle,
					-1,
					rectCaption,
					DT_SINGLELINE|DT_CENTER|DT_VCENTER
					);
*/
				dc.DrawState(
					rcCenteredCaption.TopLeft(),
					rcCenteredCaption.Size(),
					(LPCTSTR)sTitle,
					(bEnabled) ? DSS_NORMAL : m_DSS_DISABLED_style, 
					TRUE,
					0,
					(CBrush*)NULL
					);
			}
			else
			{
				LOGFONT lf;
				::memset(&lf,0,sizeof(LOGFONT));
				pCurrFont->GetLogFont(&lf);
				int _cyHorzFont = abs(lf.lfHeight);
				int _cyTextMargin =
					(rectCaption.Width() - _cyHorzFont)  / 2
					;

				CPoint
					ptLineFrom(0,0),
					ptLineTo(0,0);
				if( nAmpIndex >= 0 )
				{
					ptLineFrom =
						CPoint(
							_cyTextMargin,
							CXTEXTMARGIN
								+ stat_CalcTextWidth(
									dc,
									bDefaultPushButton ?
										m_FontBold : m_FontNormal,
									sBtn.Left(nAmpIndex)
									)
							);
					ptLineTo =
						CPoint(
							_cyTextMargin,
							CXTEXTMARGIN
								+ stat_CalcTextWidth(
									dc,
									bDefaultPushButton ?
										m_FontBold : m_FontNormal,
									sBtn.Left(nAmpIndex+1)
									)
							);
				} // if( nAmpIndex >= 0 )

				CRect rcString = 
					CRect(
						CPoint(
							rectCaption.right - _cyTextMargin,
							rectCaption.top + CXTEXTMARGIN
							),
						rectCaption.Size() //m_sizeHorz
						);
				rcString.DeflateRect(2,2);

				CSize ptFix(-rcString.Width()-1,0);
				ptLineFrom += rcString.TopLeft() + ptFix;
				ptLineTo += rcString.TopLeft() + ptFix;
				if( bEnabled )
				{
					dc.DrawText(
						sBtn,
						rcString,
						DT_SINGLELINE //|DT_CENTER|DT_VCENTER
							|DT_NOCLIP|DT_NOPREFIX
						); // don't forget DT_NOCLIP
					if( nAmpIndex >= 0 )
					{
						CPen pen(
							PS_SOLID,
							0,
							dc.GetTextColor()
							);
						CPen * pOldPen = dc.SelectObject( &pen );
						dc.MoveTo( ptLineFrom );
						dc.LineTo( ptLineTo );
						dc.SelectObject( pOldPen );
					} // if( nAmpIndex >= 0 )
				} // if( bEnabled )
				else
				{
					CPoint ptOffsetPre(1,1);
					CPoint ptOffsetPost(-1,-1);
					COLORREF clrText = GetColor(COLOR_3DSHADOW);
					COLORREF clrShadow = GetColor(COLOR_3DHILIGHT);
					rcString.OffsetRect(ptOffsetPre.x,ptOffsetPre.y);
					dc.SetTextColor( clrShadow );
					dc.DrawText(
						sBtn,
						rcString,
						DT_SINGLELINE //|DT_CENTER|DT_VCENTER
							|DT_NOCLIP|DT_NOPREFIX
						); // don't forget DT_NOCLIP
					rcString.OffsetRect(ptOffsetPost.x,ptOffsetPost.y);
					dc.SetTextColor( clrText );
					dc.DrawText(
						sBtn,
						rcString,
						DT_SINGLELINE //|DT_CENTER|DT_VCENTER
							|DT_NOCLIP|DT_NOPREFIX
						); // don't forget DT_NOCLIP
					if( nAmpIndex >= 0 )
					{
						CPen pen(
							PS_SOLID,
							0,
							clrShadow
							);
						CPen * pOldPen = dc.SelectObject( &pen );
						ptLineFrom += ptOffsetPre;
						ptLineTo += ptOffsetPre;
						dc.MoveTo( ptLineFrom );
						dc.LineTo( ptLineTo );
						pen.DeleteObject();
						pen.CreatePen(
							PS_SOLID,
							0,
							clrText
							);
						dc.SelectObject( &pen );
						ptLineFrom += ptOffsetPost;
						ptLineTo += ptOffsetPost;
						dc.MoveTo( ptLineFrom );
						dc.LineTo( ptLineTo );
						dc.SelectObject( pOldPen );
					} // if( nAmpIndex >= 0 )
				} // else from if( bEnabled )

			}

			dc.SelectObject(pOldBtnFont);
		} // if( !sTitle.IsEmpty() )

		if( bDrawFocusRect )
		{
			CRect focusRect = rectCaption; // rectClient
			focusRect.DeflateRect( 3, 3 );
			dc.DrawFocusRect(&focusRect);
		} // if( bDrawFocusRect )
	} // if we have valid area for text & focus rect


	dc.SetBkMode( nOldBkMode );
	dc.SetBkColor( clrOldBk );
	dc.SetTextColor( clrOldText );
}

CRect CExtPaintManager::stat_CalcTextDimension(
	CDC & dc,
	CFont & font,
	const CString & strText
	)
{
	ASSERT( dc.GetSafeHdc() != NULL );
	ASSERT( font.GetSafeHandle() != NULL );
CRect rcText(0,0,0,0);
CFont * pOldFont = dc.SelectObject(
		&font
		);
	ASSERT( pOldFont != NULL );
	dc.DrawText(
		strText,
		&rcText,
		DT_SINGLELINE | DT_CALCRECT
			| DT_LEFT | DT_VCENTER
		);
	dc.SelectObject(pOldFont);
	rcText.OffsetRect( -rcText.TopLeft() );
	return rcText;
}

int CExtPaintManager::stat_CalcTextWidth(
	CDC & dc,
	CFont & font,
	const CString & strText
	)
{
	return
		CExtPaintManager::stat_CalcTextDimension(
			dc,
			font,
			strText
			).Width();
}

void CExtPaintManager::PaintMenuSeparator(
	CDC & dc,
	CRect & rectItem,
	bool bRarelyUsed
	)
{
CRect rectItem2(rectItem);
	if( bRarelyUsed )
	{
		rectItem2.InflateRect(3,0,4,0);
		dc.FillRect(
			&rectItem2,
			&m_brushLight
			);
		rectItem2.DeflateRect(3,0,4,0);
	}
	else
		dc.FillSolidRect(
			&rectItem2,
			GetColor(CLR_3DFACE_OUT)
			);

int nFunnyDeflateMetric =
		::GetSystemMetrics(SM_CXSMICON) / 2;
	rectItem2.DeflateRect(
		nFunnyDeflateMetric,
		0
		);

COLORREF clrBtnShadow =
		GetColor(
			bRarelyUsed ?
				CLR_3DFACE_OUT : CLR_3DSHADOW_OUT
			);
COLORREF clrBtnHilight =
		GetColor(CLR_3DHILIGHT_OUT);
int y = (rectItem2.top+rectItem2.bottom)/2;
rectItem2.top = y-1; rectItem2.bottom = y+1;
	dc.Draw3dRect(
		rectItem2,
		clrBtnShadow,
		clrBtnHilight
		);
}

void CExtPaintManagerXP::PaintMenuSeparator(
	CDC & dc,
	CRect & rectItem,
	bool bRarelyUsed
	)
{
	if( rectItem.IsRectEmpty() )
		return;
COLORREF clr3dFace = // GetColor(CLR_3DFACE_OUT);
		GetColor(
			bRarelyUsed ?
				XPCLR_RARELY_BORDER : CLR_3DFACE_OUT
		);
CRect rc(rectItem);
	rc.right = rc.left+__DEF_MENU_ICON_AREA_DX;
	dc.FillSolidRect(
		rc,
		clr3dFace
		);
	rc = rectItem;
	rc.left += __DEF_MENU_ICON_AREA_DX;
	dc.FillSolidRect(
		rc,
		GetColor(XPCLR_3DFACE_NORMAL)
		);
	rc.left += __DEF_MENU_GAP;
	rc.top += rc.Height()/2;
	rc.bottom = rc.top+1;
	dc.FillSolidRect(
		rc,
		clr3dFace
		);
}

void CExtPaintManager::PaintSysCmdGlyph(
	CDC & dc,
	UINT nHelperSysCmdID,
	const CRect & rcItem,
	bool bHover,
	bool bPushed,
	bool bEnabled
	)
{
e_docking_caption_button_t eGlyph = __DCBT_EMPTY;
	switch( nHelperSysCmdID )
	{
	case SC_CLOSE:
		eGlyph = __DCBT_CLOSE;
	break;
	case SC_RESTORE:
		eGlyph = __DCBT_WND_RESTORE;
	break;
	case SC_MINIMIZE:
		eGlyph = __DCBT_WND_MINIMIZE;
	break;
	case SC_MAXIMIZE:
		eGlyph = __DCBT_WND_MAXIMIZE;
	break;
	case SC_CONTEXTHELP:
		eGlyph = __DCBT_WND_CONTEXTHELP;
	break;
	} // switch( nHelperSysCmdID )
	if( eGlyph == __DCBT_EMPTY )
		return;
COLORREF ColorValues[2] = {
	RGB(0,0,0),
	RGB(0,0,0),
};
CRect _rcItem( rcItem );
	if( bPushed )
		_rcItem.OffsetRect(
			GetPushedOffset()
			);
	if( bEnabled )
	{
		ColorValues[1] =
			GetColor(
				bHover ?
					COLOR_HIGHLIGHTTEXT : CLR_TEXT_OUT
				);
	} // if( bEnabled )
	else
	{
		ColorValues[1] =
			GetColor( CLR_3DHILIGHT_OUT );
		_rcItem.OffsetRect(1,1);
		PaintGlyphCentered(
			dc,
			_rcItem,
			*g_DockingCaptionGlyphs[eGlyph],
			ColorValues
			);
		_rcItem.OffsetRect(-1,-1);
		ColorValues[1] =
			GetColor( CLR_3DSHADOW_OUT );
	} // if( bEnabled )
	PaintGlyphCentered(
		dc,
		_rcItem,
		*g_DockingCaptionGlyphs[eGlyph],
		ColorValues
		);
}

void CExtPaintManagerXP::PaintSysCmdGlyph(
	CDC & dc,
	UINT nHelperSysCmdID,
	const CRect & rcItem,
	bool bHover,
	bool bPushed,
	bool bEnabled
	)
{
e_docking_caption_button_t eGlyph = __DCBT_EMPTY;
	switch( nHelperSysCmdID )
	{
	case SC_CLOSE:
		eGlyph = __DCBT_CLOSE;
	break;
	case SC_RESTORE:
		eGlyph = __DCBT_WND_RESTORE;
	break;
	case SC_MINIMIZE:
		eGlyph = __DCBT_WND_MINIMIZE;
	break;
	case SC_MAXIMIZE:
		eGlyph = __DCBT_WND_MAXIMIZE;
	break;
	case SC_CONTEXTHELP:
		eGlyph = __DCBT_WND_CONTEXTHELP;
	break;
	} // switch( nHelperSysCmdID )
	if( eGlyph == __DCBT_EMPTY )
		return;
COLORREF ColorValues[2] = {
	RGB(0,0,0),
	RGB(0,0,0),
};
CRect _rcItem( rcItem );
	if( bPushed )
		_rcItem.OffsetRect(
			GetPushedOffset()
			);
	if( bEnabled )
	{
//		if( bHover || bPushed )
//			ColorValues[1] =
//				GetColor( CLR_TEXT_IN );
		if( bHover & (!bPushed) )
		{
			ColorValues[1] =
				GetColor( COLOR_3DDKSHADOW );
			//_rcItem.OffsetRect(1,1);
			PaintGlyphCentered(
				dc,
				_rcItem,
				*g_DockingCaptionGlyphs[eGlyph],
				ColorValues
				);
			_rcItem.OffsetRect(-1,-1);
		}
		ColorValues[1] = GetColor( CLR_TEXT_OUT );
	} // if( bEnabled )
	else
	{
		ColorValues[1] = GetColor( COLOR_3DSHADOW );
	} // if( bEnabled )
	PaintGlyphCentered(
		dc,
		_rcItem,
		*g_DockingCaptionGlyphs[eGlyph],
		ColorValues
		);
}

void CExtPaintManager::PaintMenuItem(
	CDC & dc,
	const CRect & rectItem,
	LPCTSTR sText,
	LPCTSTR sAccelText,
	HICON hIcon,
	bool bPopup,
	bool bSelected,
	bool bPushedCheck,
	bool bPushedRadio,
	bool bIndeterminate,
	bool bEnabled,
	bool bRarelyUsed,
	bool bRarelyUsedPrev,
	bool bRarelyUsedNext,
	UINT nHelperSysCmdID // for painting system menu glyphs
	)
{
	bIndeterminate;
	if( rectItem.IsRectEmpty() )
		return;
CString _sText

⌨️ 快捷键说明

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