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

📄 extpaintmanager.cpp

📁 FormEditor,模拟Visual Basic窗口编辑界面
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	dc.GetTextMetrics( &tm );
int nTextHeightHorz = tm.tmHeight + 2;
	dc.SelectObject( &m_FontNormal );
	dc.GetTextMetrics( &tm );
int nTextHeightVert = tm.tmHeight + 2;
	dc.SelectObject( pOldFont );
	return CSize(nTextHeightHorz,nTextHeightVert);
}

int CExtPaintManager::GetTextHeight(bool bHorz)
{
CSize _size = GetTextSizes();
	return bHorz ? _size.cx : _size.cy;
}

static const UINT stat_pixels_glyph_btn_expand_bottom[] =
{
	1,1,1,1,1,
	0,1,1,1,0,
	0,0,1,0,0,
};
const CExtPaintManager::glyph_t
	CExtPaintManager::g_glyph_btn_expand_bottom(
		5,3,2,
		stat_pixels_glyph_btn_expand_bottom
		);

static const UINT stat_pixels_glyph_btn_expand_right2[] =
{
	1,1,0,0,1,1,0,0,
	0,1,1,0,0,1,1,0,
	0,0,1,1,0,0,1,1,
	0,1,1,0,0,1,1,0,
	1,1,0,0,1,1,0,0,
};
const CExtPaintManager::glyph_t
	CExtPaintManager::g_glyph_btn_expand_right2(
		8,5,2,
		stat_pixels_glyph_btn_expand_right2
		);

const CExtPaintManager::glyph_t
	CExtPaintManager::g_glyph_btn_expand_left(
		CExtPaintManager::g_glyph_btn_expand_bottom,
		90
		);

const CExtPaintManager::glyph_t
	CExtPaintManager::g_glyph_btn_expand_right(
		CExtPaintManager::g_glyph_btn_expand_bottom,
		270
		);

const CExtPaintManager::glyph_t
	CExtPaintManager::g_glyph_btn_expand_bottom2(
		CExtPaintManager::g_glyph_btn_expand_right2,
		90
		);

void CExtPaintManager::PaintGlyph(
	CDC & dc,
	POINT ptDest,
	const glyph_t & glyph,
	COLORREF * pColorValues
	)
{
	ASSERT( dc.GetSafeHdc() != NULL );
	ASSERT( pColorValues != NULL );
	ASSERT( glyph.Size().cx > 0 );
	ASSERT( glyph.Size().cy > 0 );
CRect rcTestVisiblity(ptDest,glyph.Size());
	if( !dc.RectVisible(&rcTestVisiblity) )
		return;
int x_dest = ptDest.x + glyph.Size().cx;
int y_dest = ptDest.y + glyph.Size().cy;
const UINT * pColorIndex = glyph.GetSurface();
	ASSERT( pColorIndex != NULL );
	for( int y = ptDest.y; y < y_dest; y++ )
	{
		for( int x = ptDest.x; x < x_dest; x++, pColorIndex++ )
		{
			UINT nColorIndex = *pColorIndex;
			ASSERT( nColorIndex < glyph.GetColorsCount() );
			if( nColorIndex == 0 )
				continue;
			COLORREF clr = pColorValues[nColorIndex];
			dc.SetPixel( x, y, clr );
		}
	}
}

void CExtPaintManager::PaintGlyphCentered(
	CDC & dc,
	const RECT & rect,
	const glyph_t & glyph,
	COLORREF * pColorValues
	)
{
CRect _rect(rect);
	_rect.NormalizeRect();
	if( _rect.IsRectEmpty() )
		return;
	ASSERT( glyph.Size().cx > 0 );
	ASSERT( glyph.Size().cy > 0 );
CPoint ptDest = _rect.TopLeft();
	ptDest.x +=
		(_rect.Width() - glyph.Size().cx) / 2;
	ptDest.y +=
		(_rect.Height() - glyph.Size().cy) / 2;
	PaintGlyph(
		dc,
		ptDest,
		glyph,
		pColorValues
		);
}

void CExtPaintManager::PaintMenuExpandButton(
	CDC & dc,
	const CRect & rectButton,
	bool bPushed,
	bool bHover
	)
{
	bHover;
CRect rcGlyph(rectButton);
	if( bPushed )
	{
		dc.FillRect(
			&rcGlyph,
			&m_brushLight
			);
		dc.Draw3dRect(
			&rcGlyph,
			GetColor(CLR_3DHILIGHT_OUT),
			GetColor(CLR_3DSHADOW_OUT)
			);
	}
	else
	{
		PaintMenuItem(
			dc, rectButton, _T(""),
			_T(""), NULL,
			false, false, false,
			false, false, true, false, false, false,
			0
			);
	}
COLORREF ColorValues[] =
{
	RGB(0,0,0),
	GetColor(CLR_TEXT_OUT)
};
	PaintGlyphCentered(
		dc,
		rcGlyph,
		g_glyph_btn_expand_bottom2,
		ColorValues
		);
}

void CExtPaintManagerXP::PaintMenuExpandButton(
	CDC & dc,
	const CRect & rectButton,
	bool bPushed,
	bool bHover
	)
{
	bHover;
	if( !bPushed )
	{
		CRect rc(rectButton);
		rc.top--;
		PaintMenuItem(
			dc, rc, _T(""),
			_T(""), NULL,
			false, false, false,
			false, false, true, false, false, false,
			0
			);
	}
CRect rcGlyph(rectButton);
	if( bPushed )
	{
		PaintPushButton(
			dc,true,rectButton,_T(""),NULL,
			true,false/*bHover*/,bPushed,false,
			false,true,false,false,
			__ALIGN_HORIZ_CENTER|__ALIGN_VERT,
			NULL,
			false
			);
		rcGlyph.OffsetRect(
			GetPushedOffset()
			);
	}
	else
	{
		PaintMenuItem(
			dc, rectButton, _T(""),
			_T(""), NULL,
			false, false, false,
			false, false, true, false, false, false,
			0
			);
	}
COLORREF ColorValues[] =
{
	RGB(0,0,0),
	GetColor(CLR_TEXT_OUT)
};
	PaintGlyphCentered(
		dc,
		rcGlyph,
		g_glyph_btn_expand_bottom2,
		ColorValues
		);
}

void CExtPaintManager::PaintToolbarExpandButton(
	CDC & dc,
	const CRect & rectButton,
	bool bHorz, // if false - down
	bool bBarIsCompletelyVisible,
	bool bEnabled,
	bool bPushed,
	bool bHover,
	bool bTransparentBackground // = false
	)
{
	ASSERT( dc.GetSafeHdc() != NULL );
CRect rect(rectButton);
	rect.NormalizeRect();
	if( !dc.RectVisible( &rect ) )
		return;

//	ASSERT( bLeft ); // temporary
const glyph_t * pGlyph = NULL, * pGlyph2 = NULL;
	if( bHorz )
	{
		pGlyph = &g_glyph_btn_expand_bottom;
		if( !bBarIsCompletelyVisible )
			pGlyph2 = &g_glyph_btn_expand_right2;
	}
	else
	{
		pGlyph = &g_glyph_btn_expand_left;
		if( !bBarIsCompletelyVisible )
			pGlyph2 = &g_glyph_btn_expand_bottom2;
	}
	ASSERT( pGlyph != NULL );

	PaintPushButton(
		dc,true,rect,_T(""),NULL,true,
		bHover,bPushed,false,bEnabled,
		true,false,false,
		__ALIGN_HORIZ_CENTER|__ALIGN_VERT,
		NULL,false,0,bTransparentBackground
		);
COLORREF clr =
	GetColor(
		bEnabled? CLR_TEXT_OUT : COLOR_3DHILIGHT
		);
COLORREF ColorValues[] =
{
	0,
	clr
};
	if( bPushed )
		rect.OffsetRect(
			GetPushedOffset()
			);

CRect rectGlyph(rectButton.TopLeft(),pGlyph->Size());
CRect rectGlyph2(rectGlyph);
CSize sizePushedOffset = GetPushedOffset();
	if( bPushed )
	{
		rectGlyph.OffsetRect( sizePushedOffset );
		rectGlyph2.OffsetRect( sizePushedOffset );
	}

	if( bHorz )
	{
		int nGap = (max(sizePushedOffset.cy,1)) * 3;
		rectGlyph.OffsetRect(
			(rectButton.Size().cx - pGlyph->Size().cx) / 2,
			rectButton.Size().cy - pGlyph->Size().cy - nGap
			);
		if( !bBarIsCompletelyVisible )
		{
			ASSERT( pGlyph2 != NULL );
			rectGlyph2.OffsetRect(
				(rectButton.Size().cx - pGlyph2->Size().cx) / 2,
				nGap
				);
		}
	}
	else
	{
		int nGap = (max(sizePushedOffset.cx,1)) * 3;
		rectGlyph.OffsetRect(
			nGap,
			(rectButton.Size().cy - pGlyph->Size().cy)/2
			);
		if( !bBarIsCompletelyVisible )
		{
			ASSERT( pGlyph2 != NULL );
			rectGlyph2.OffsetRect(
				rectButton.Size().cx - pGlyph2->Size().cx - nGap,
				(rectButton.Size().cy - pGlyph2->Size().cy) / 2
				);
		}
	}

	if( bEnabled )
	{
		PaintGlyph(
			dc,rectGlyph.TopLeft(),*pGlyph,ColorValues
			);
		if( !bBarIsCompletelyVisible )
		{
			ASSERT( pGlyph2 != NULL );
			PaintGlyph(
				dc,rectGlyph2.TopLeft(),*pGlyph2,ColorValues
				);
		}
	} // if( bEnabled )
	else
	{
//		rect.OffsetRect(1,1);
//		PaintGlyphCentered(
//			dc,rect,*pGlyph,ColorValues
//			);
//		ColorValues[1] = GetColor(COLOR_3DSHADOW);
//		rect.OffsetRect(-1,-1);
//		PaintGlyphCentered(
//			dc,rect,*pGlyph,ColorValues
//			);
		rectGlyph.OffsetRect(1,1);
		PaintGlyph(
			dc,rectGlyph.TopLeft(),*pGlyph,ColorValues
			);
		rectGlyph.OffsetRect(-1,-1);
		ColorValues[1] = GetColor(COLOR_3DSHADOW);
		PaintGlyph(
			dc,rectGlyph.TopLeft(),*pGlyph,ColorValues
			);
	} // else from if( bEnabled )
}

void CExtPaintManagerXP::PaintToolbarExpandButton(
	CDC & dc,
	const CRect & rectButton,
	bool bHorz, // if false - down
	bool bBarIsCompletelyVisible,
	bool bEnabled,
	bool bPushed,
	bool bHover,
	bool bTransparentBackground // = false
	)
{
	ASSERT( dc.GetSafeHdc() != NULL );
CRect rect(rectButton);
	rect.NormalizeRect();
	if( !dc.RectVisible( &rect ) )
		return;

//	ASSERT( bLeft ); // temporary
const glyph_t * pGlyph = NULL, * pGlyph2 = NULL;
	if( bHorz )
	{
		pGlyph = &g_glyph_btn_expand_bottom;
		if( !bBarIsCompletelyVisible )
			pGlyph2 = &g_glyph_btn_expand_right2;
	}
	else
	{
		pGlyph = &g_glyph_btn_expand_left;
		if( !bBarIsCompletelyVisible )
			pGlyph2 = &g_glyph_btn_expand_bottom2;
	}
	ASSERT( pGlyph != NULL );

	PaintPushButton(
		dc,true,rect,_T(""),NULL,true,
		bHover,bPushed,false,bEnabled,
		true,false,false,
		__ALIGN_HORIZ_CENTER|__ALIGN_VERT,
		NULL,false,0,bTransparentBackground
		);
COLORREF clr =
	GetColor(
		bEnabled? CLR_TEXT_OUT : COLOR_3DHILIGHT
		);
COLORREF ColorValues[] =
{
	0,
	clr
};
	if( bPushed )
		rect.OffsetRect(
			GetPushedOffset()
			);

CRect rectGlyph(rectButton.TopLeft(),pGlyph->Size());
CRect rectGlyph2(rectGlyph);
CSize sizePushedOffset = GetPushedOffset();
	if( bPushed )
	{
		rectGlyph.OffsetRect( sizePushedOffset );
		rectGlyph2.OffsetRect( sizePushedOffset );
	}

	if( bHorz )
	{
		int nGap = (max(sizePushedOffset.cy,1)) * 3;
		rectGlyph.OffsetRect(
			(rectButton.Size().cx - pGlyph->Size().cx) / 2 + 1,
			rectButton.Size().cy - pGlyph->Size().cy - nGap
			);
		if( !bBarIsCompletelyVisible )
		{
			ASSERT( pGlyph2 != NULL );
			rectGlyph2.OffsetRect(
				(rectButton.Size().cx - pGlyph2->Size().cx) / 2 + 1,
				nGap
				);
		}
	}
	else
	{
		int nGap = (max(sizePushedOffset.cx,1)) * 3;
		rectGlyph.OffsetRect(
			nGap,
			(rectButton.Size().cy - pGlyph->Size().cy)/2 + 1
			);
		if( !bBarIsCompletelyVisible )
		{
			ASSERT( pGlyph2 != NULL );
			rectGlyph2.OffsetRect(
				rectButton.Size().cx - pGlyph2->Size().cx - nGap,
				(rectButton.Size().cy - pGlyph2->Size().cy) / 2 + 1
				);
		}
	}

	if( bEnabled )
	{
		if( bHover && (!bPushed) )
		{
			COLORREF ColorValuesHover[] =
			{
				0,
				GetColor(COLOR_3DDKSHADOW)
			};
			rectGlyph.OffsetRect(-1,-1);
			rectGlyph2.OffsetRect(-1,-1);
			PaintGlyph(
				dc,rectGlyph.TopLeft(),*pGlyph,ColorValuesHover
				);
			if( !bBarIsCompletelyVisible )
			{
				ASSERT( pGlyph2 != NULL );
				PaintGlyph(
					dc,rectGlyph2.TopLeft(),*pGlyph2,ColorValuesHover
					);
			}
			rectGlyph.OffsetRect(1,1);
			rectGlyph2.OffsetRect(1,1);
		}
		PaintGlyph(
			dc,rectGlyph.TopLeft(),*pGlyph,ColorValues
			);
		if( !bBarIsCompletelyVisible )
		{
			ASSERT( pGlyph2 != NULL );
			PaintGlyph(
				dc,rectGlyph2.TopLeft(),*pGlyph2,ColorValues
				);
		}
	} // if( bEnabled )
	else
	{
//		rect.OffsetRect(1,1);
//		PaintGlyphCentered(
//			dc,rect,*pGlyph,ColorValues
//			);
//		ColorValues[1] = GetColor(COLOR_3DSHADOW);
//		rect.OffsetRect(-1,-1);
//		PaintGlyphCentered(
//			dc,rect,*pGlyph,ColorValues
//			);
		ColorValues[1] = GetColor(COLOR_3DSHADOW);
		PaintGlyph(
			dc,rectGlyph.TopLeft(),*pGlyph,ColorValues
			);
	} // else from if( bEnabled )
}

void CExtPaintManager::stat_ExcludeChildAreas(
	HDC hDC,
	HWND hWnd,
	CExtPaintManager::pfnExcludeChildAreaCallback pCallback, // = NULL
	LPVOID pCallbackCookie // = NULL
	)
{
	if( hDC == NULL || !IsWindow(hWnd) )
		return;
HWND hWndChild = GetWindow(hWnd,GW_CHILD);
	for(; hWndChild != NULL; hWndChild = GetWindow(hWndChild,GW_HWNDNEXT))
	{
		if( !IsWindowVisible(hWndChild) )
			continue;
		DWORD dwChildStyle =
			DWORD( GetWindowLong(hWndChild,GWL_STYLE) );
		if( (dwChildStyle & WS_CHILD) == 0 )
			continue;
		RECT rc;
		if( !GetWindowRect(hWndChild,&rc) )
			continue;
		if( !ScreenToClient(hWnd, (LPPOINT)(&rc)) )
			continue;
		if( !ScreenToClient(hWnd, ((LPPOINT)(&rc))+1) )
			continue;
		if( pCallback != NULL )
		{
			if( pCallback(
					hDC,
					hWnd,
					hWndChild,
					pCallbackCookie
					)
				)
				continue;
		}
		ExcludeClipRect(
			hDC,
			rc.left,rc.top,
			rc.right,rc.bottom
			);
	} // for(; hWndChild != NULL; hWndChild = GetWindow(hWndChild,GW_HWNDNEXT))
}

//static volatile bool stat_bTrySysTransparentBlt = true;
//static volatile HMODULE stat_hModuleMsimg32 = NULL;
//typedef BOOL (*pMsimg32_TransparentBlt_t)(
//		HDC hdcDest,        // handle to destination DC
//		int nXOriginDest,   // x-coord of destination upper-left corner
//		int nYOriginDest,   // y-coord of destination upper-left corner
//		int nWidthDest,     // width of destination rectangle
//		int hHeightDest,    // height of destination rectangle
//		HDC hdcSrc,         // handle to source DC
//		int nXOriginSrc,    // x-coord of source upper-left corner
//		int nYOriginSrc,    // y-coord of source upper-left corner
//		int nWidthSrc,      // width of source rectangle
//		int nHeightSrc,     // height of source rectangle
//		UINT crTransparent  // color to make transparent
//	);
//static volatile pMsimg32_TransparentBlt_t pMsimg32_TransparentBlt = NULL;

void CExtPaintManager::stat_TransparentBlt(
	HDC hdcDest,        // handle to destination DC
	int nXOriginDest,   // x-coord of destination upper-left corner
	int nYOriginDest,   // y-coord of destination upper-left corner
	int nWidthDest,     // width of destination rectangle
	int hHeightDest,    // height of destination rectangle
	HDC hdcSrc,         // handle to source DC
	int nXOriginSrc,    // x-coord of source upper-left corner
	int nYOriginSrc,    // y-coord of source upper-left corner
	int nWidthSrc,      // width of source rectangle
	int nHeightSrc,     // height of source rectangle
	UINT crTransparent  // color to make transparent
	)
{
	ASSERT( hdcDest != NULL && hdcSrc != NULL );
//	if( stat_bTrySysTransparentBlt )
//	{
//		stat_bTrySysTransparentBlt = false;

⌨️ 快捷键说明

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