Exemple #1
0
		void GDIPlus::DrawFilledRect( Gwen::Rect rect )
		{
			Translate( rect );

			Gdiplus::SolidBrush solidBrush( m_Colour );
			graphics->FillRectangle( &solidBrush, rect.x, rect.y, rect.w, rect.h );
		}
Exemple #2
0
void CCheckButton::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{
		UpdateMemDC(dc, nWidth * 6, nHeight);

		Graphics graphics(m_memDC);
		CRect  rcTemp(0, 0, nWidth, nHeight);

		for(int i = 0; i < 6; i++)
		{
			m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);

			graphics.DrawImage(m_pImage, Rect(rcTemp.left, rcTemp.top + (nHeight - m_sizeImage.cy) / 2,   m_sizeImage.cx, m_sizeImage.cy),
				i * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);

			rcTemp.OffsetRect(nWidth, 0);
		}
		
		if(!m_strTitle.IsEmpty())
		{
			m_memDC.SetBkMode(TRANSPARENT);

			rcTemp.SetRect(0, 0, nWidth, nHeight);

			FontFamily fontFamily(m_strFont.AllocSysString());
			Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
			graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );

			StringFormat strFormat;
			strFormat.SetAlignment(StringAlignmentNear);
			strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
			Size size = GetTextBounds(font, strFormat, m_strTitle);
			CPoint point = GetOriginPoint(nWidth - m_sizeImage.cx - 3, nHeight, size.Width, size.Height, m_uAlignment, m_uVAlignment);

			for(int i = 0; i < 6; i++)
			{
				SolidBrush solidBrush(enBSDisable == i ? Color(128, 128, 128) : m_clrText);

				RectF rect(m_sizeImage.cx + 3 + point.x + i * nWidth, point.y, nWidth - m_sizeImage.cx - 3 - point.x, size.Height);
				graphics.DrawString(m_strTitle.AllocSysString(), (INT)wcslen(m_strTitle.AllocSysString()), &font, 
					rect, &strFormat, &solidBrush);

				// 画焦点框(虚线框)
				if(m_bIsFocus)
				{
					Pen pen(Color(128, 128, 128), 1);
					pen.SetDashStyle(DashStyleDot);
					RectF rectFocus(point.x + i * nWidth, point.y, m_sizeImage.cx + 6 + size.Width, size.Height);
					graphics.DrawRectangle(&pen, rectFocus);
				}
			}
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY);
}
Exemple #3
0
void Label::onDraw(Gdiplus::Graphics& g, int x, int y)
{
	Gdiplus::FontFamily  fontFamily(fontFamily_.c_str());
	Gdiplus::Font        font(&fontFamily, fontSize_, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::PointF      pointF(float(x+x_), float(y+y_));
	Gdiplus::SolidBrush  solidBrush(fontColor_);

	g.DrawString(text_.c_str(), text_.length(), &font, pointF, &solidBrush);
}
void CHideButton::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{		
		UpdateMemDC(dc, nWidth * 5, nHeight);
		
		for(int i = 0; i < 4; i++)
		{
			m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);
		}
		
		Color clrText[4] = {m_clrTextNormal, m_clrTextHover, m_clrTextDown, m_clrTextDisable};

		Graphics graphics(m_memDC);
		BSTR bsFont = m_strFont.AllocSysString();
		FontFamily fontFamily(bsFont);
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
		::SysFreeString(bsFont);

		// 设置水平和垂直对齐方式
		DUI_STRING_ALIGN_DEFINE();

		strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
		Size sizeTip = GetTextBounds(font, strFormat, m_strTip);
		Size sizeText = GetTextBounds(font, strFormat, m_strTitle);
		
		m_rcText.SetRect(m_rc.left + sizeTip.Width + 10, m_rc.top, m_rc.left + sizeTip.Width + 10 + sizeText.Width, m_rc.top + sizeText.Height);
		
		SolidBrush solidBrushTip(m_clrTip);

		for(int i = 0; i < 4; i++)
		{
			RectF rect((Gdiplus::REAL)(i * nWidth), (Gdiplus::REAL)0, (Gdiplus::REAL)(sizeTip.Width + 10), (Gdiplus::REAL)sizeTip.Height);

			BSTR bsTip = m_strTip.AllocSysString();
			graphics.DrawString(bsTip, (INT)wcslen(bsTip), &font, rect, &strFormat, &solidBrushTip);
			::SysFreeString(bsTip);

			if(i > 0)
			{
				SolidBrush solidBrush(clrText[i - 1]);	
				RectF rect((Gdiplus::REAL)(sizeTip.Width + 10 + i * nWidth), (Gdiplus::REAL)0, (Gdiplus::REAL)(nWidth - (sizeTip.Width + 10)), (Gdiplus::REAL)sizeText.Height);
				BSTR bsTitle = m_strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
				::SysFreeString(bsTitle);
			}
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_bShowButton ? (1 + m_enButtonState) * nWidth : 0, 0, SRCCOPY);
}
Exemple #5
0
// 表格绘制.
void DataGrids::DrawGrids(HDC _hdc)
{
	// 绘制x/y的箭头.
	WideString xStr = "电压(V)";
	WideString yStr = "时间(S)";

	m_stGrp = new Gdiplus::Graphics(_hdc);
	m_stGrp->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);

	/*FontFamily fontFamily(L"楷体_GB2312");
	Font font(&fontFamily, 30, FontStyleRegular, UnitPixel);
	*/
	Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 0, 0, 255));
	Gdiplus::Pen p(Gdiplus::Color(255, 0, 0, 0),1);
	Gdiplus::AdjustableArrowCap cap(8,4,true);
	Gdiplus::Font font(L"楷体",12);
	Gdiplus::SolidBrush s( Gdiplus::Color(255, 0, 0, 0));

#define X(_x) UserX((_x)+xAxisOffset)
#define Y(_y) UserY((_y)+yAxisOffset)
	// 刻度线.Y轴.
	p.SetColor(Gdiplus::Color(255, 0, 0, 255));
	for(int i = 0; i * yMarkSpace < m_iHeight-yMarkSpace-8;i++)
	{
		m_stGrp->DrawLine(&p,X(0),Y(0+i*yMarkSpace),X(yMarkHeight+(((i%5)==0)?yMarkHeight:0)),Y(0+i*yMarkSpace));
	}

	for(int i = 0; i * yMarkSpace < m_iWidth-xMarkSpace-8;i++)
	{
		m_stGrp->DrawLine(&p,X(i*xMarkSpace),Y(0),X(i*xMarkSpace),Y(xMarkHeight+((i%5)==0?xMarkHeight:0)));
	}
	p.SetColor(Gdiplus::Color(255, 0, 0, 0));
	// Draw X,Y axises.
	p.SetCustomEndCap(&cap);
	m_stGrp->DrawLine(&p,X(0),Y(0),X(0),Y(m_iHeight)); // Draw Y axis
	m_stGrp->DrawLine(&p,X(0),Y(0),X(m_iWidth),Y(0));  // Draw X axis

	m_stGrp->DrawString(xStr.c_bstr(),xStr.Length(),&font,Gdiplus::PointF(30,10),&s);
	m_stGrp->DrawString(yStr.c_bstr(),yStr.Length(),&font,Gdiplus::PointF(m_iWidth-80,m_iHeight-50),&s);

#undef X(_x)
#undef Y(_y)

	DrawCurve();

	delete m_stGrp;
}
Exemple #6
0
		void GDIPlus::RenderText( gwen::Font* pFont, gwen::Point pos, const gwen::UnicodeString & text )
		{
			Translate( pos.x, pos.y );

			// If the font doesn't exist, or the font size should be changed
			if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
			{
				FreeFont( pFont );
				LoadFont( pFont );
			}

			Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() );
			Gdiplus::SolidBrush solidBrush( m_Colour );
			Gdiplus::RectF r( pos.x, pos.y, 1000, 1000 );
			Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data;
			graphics->DrawString( text.c_str(), text.length() + 1, pGDIFont, r, &strFormat, &solidBrush );
		}
void CLinkButton::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{		
		UpdateMemDC(dc, nWidth * 4, nHeight);

		for(int i = 0; i < 4; i++)
		{
			m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);
		}
		
		Color clrText[4] = {m_clrTextNormal, m_clrTextHover, m_clrTextDown, m_clrTextDisable};

		Graphics graphics(m_memDC);
		BSTR bsFont = m_strFont.AllocSysString();
		FontFamily fontFamily(bsFont);
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
		::SysFreeString(bsFont);

		StringFormat strFormat;
		strFormat.SetAlignment(StringAlignmentNear);
		strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
		Size sizeText = GetTextBounds(font, strFormat, m_strTitle);
		CPoint point = GetOriginPoint(nWidth, nHeight, sizeText.Width, sizeText.Height,
						GetGDIAlignment(m_uAlignment), GetGDIVAlignment(m_uVAlignment));
		
		m_rcText.SetRect(m_rc.left, m_rc.top + point.y, m_rc.left + sizeText.Width, m_rc.top + point.y + sizeText.Height);

		for(int i = 0; i < 4; i++)
		{
			SolidBrush solidBrush(clrText[i]);	
			RectF rect((Gdiplus::REAL)(i * nWidth), (Gdiplus::REAL)point.y, (Gdiplus::REAL)nWidth, (Gdiplus::REAL)sizeText.Height);
			BSTR bsTitle = m_strTitle.AllocSysString();
			graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
			::SysFreeString(bsTitle);
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY);
}
Exemple #8
0
BOOL GDIPluseExt::DrawRoundRect(Graphics&  gp,CRect rect,Color boardscolor,Color FillPathcolor,int radius)
{

	//边框路径
	GraphicsPath Path;
	MakeRoundRectPath(&Path,rect,radius);
	SolidBrush solidBrush(FillPathcolor);
	gp.SetSmoothingMode(SmoothingModeAntiAlias);
	gp.SetInterpolationMode(InterpolationModeHighQualityBicubic);
	gp.FillPath(&solidBrush, &Path);
	//画边框
	for(int i=1; i < 4; ++i)
	{
		Pen pen(boardscolor, (REAL)i);
		pen.SetLineJoin(LineJoinRound);
		gp.DrawPath(&pen, &Path);
	}
	return TRUE;
}
Exemple #9
0
void CTextButton::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{		
		UpdateMemDC(dc, nWidth * 4, nHeight);
		
		for(int i = 0; i < 4; i++)
		{
			m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);
		}
		
		Color clrText[4] = {m_clrTextNormal, m_clrTextHover, m_clrTextDown, m_clrTextDisable};

		Graphics graphics(m_memDC);
		FontFamily fontFamily(m_strFont.AllocSysString());
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );

		// 设置水平和垂直对齐方式
		DUI_STRING_ALIGN_DEFINE();

		strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
		Size size = GetTextBounds(font, strFormat, m_strTitle);
		CPoint point = GetOriginPoint(nWidth, nHeight, size.Width, size.Height, m_uAlignment, m_uVAlignment);

		for(int i = 0; i < 4; i++)
		{
			SolidBrush solidBrush(clrText[i]);		
			RectF rect(point.x + i * nWidth, point.y, nWidth - point.x, size.Height);
			graphics.DrawString(m_strTitle.AllocSysString(), (INT)wcslen(m_strTitle.AllocSysString()), &font, 
				rect, &strFormat, &solidBrush);	
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY);
}
void CHSBWindow::OnPaint(HDC hdc)
{
	Graphics g(hdc);
	SolidBrush backBrush(0xFFFFFFFF);
	g.FillRectangle(&backBrush, 0, 0, SELECT_WIDTH, SELECT_HEIGHT);
	for(int i = 0; i < m_ControlCount; i++)
	{
		m_Controls[i]->Paint(&g);
	}

	Gdiplus::Pen grayPen1(0xFFB0B0B0, 1);
	Gdiplus::Pen grayPen2(0xFFE7EAEA, 1);
	g.DrawLine(&grayPen1, 2, 27 * 5 + 8, 102, 27 * 5 + 8);
	g.DrawLine(&grayPen2, 3, 27 * 5 + 9, 102, 27 * 5 + 9);

	SolidBrush solidBrush(0xFF000000); 
	StringFormat stringFormat;
	stringFormat.SetAlignment(StringAlignmentCenter);
	g.DrawString(L"Recent", -1, g_pFont, RectF(2, 27 * 5 + 2, 100, 24), &stringFormat, &solidBrush);

	g.DrawLine(&grayPen1, 105, 2, 105, SELECT_HEIGHT - 5);
	g.DrawLine(&grayPen2, 106, 3, 106, SELECT_HEIGHT - 4);
}
Exemple #11
0
// 画控件
void CMenuItem::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{
		int nImageCount = m_bSelect ? 6 : 4;
		if(m_bIsSeparator)
		{
			nImageCount = 1;
		}
		UpdateMemDC(dc, nWidth * nImageCount, nHeight);

		// 刷新图片的大小(因为m_bSelect选项有可能在SetBitmap之后有变化)
		if(m_pImage != NULL)
		{
			if(m_bIsPopup && (m_pImagePopupArrow == NULL))
			{
				// 弹出菜单的箭头,固定是两个小图片
				m_sizeImage.SetSize(m_pImage->GetWidth() / 2, m_pImage->GetHeight());
			}else
			if(m_bIsSeparator)
			{
				// 分隔线,只有一个图片
				m_sizeImage.SetSize(m_pImage->GetWidth(), m_pImage->GetHeight());
			}else
			if(m_bSelect)
			{
				// checkbox或radiobutton,固定为6个小图片
				m_sizeImage.SetSize(m_pImage->GetWidth() / 6, m_pImage->GetHeight());
			}else
			{
				// 按照设置的小图片个数计算
				m_sizeImage.SetSize(m_pImage->GetWidth() / m_nImagePicCount, m_pImage->GetHeight());
			}
		}

		Graphics graphics(m_memDC);
		CRect  rcTemp(0, 0, nWidth, nHeight);

		for(int i = 0; i < nImageCount; i++)
		{
			m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);

			if(enBSHover == i || (enBSDown == i && !m_bSelect) || enBSHoverDown == i)
			{
				// 画菜单项背景
				if(m_pImageHover != NULL)
				{
					// 使用拉伸模式属性画图
					graphics.DrawImage(m_pImageHover, RectF((Gdiplus::REAL)(i * nWidth+m_nFrameWidth), 0, (Gdiplus::REAL)(nWidth-m_nFrameWidth*2), (Gdiplus::REAL)nHeight),
							0, 0, (Gdiplus::REAL)m_sizeHover.cx, (Gdiplus::REAL)m_sizeHover.cy, UnitPixel);
				}else
				{
					// 使用颜色填充
					SolidBrush brush(m_clrHover);//Color(254, 71, 156, 235));
					graphics.FillRectangle(&brush, i * nWidth+m_nFrameWidth, 0, nWidth-m_nFrameWidth*2, nHeight);
				}
			}

			// 画菜单项图片
			if(m_pImage != NULL)
			{
				if(m_bIsSeparator)
				{
					// 如果是分隔线,则采用平铺方式画图
					TextureBrush tileBrush(m_pImage, WrapModeTile);
					graphics.FillRectangle(&tileBrush, RectF((Gdiplus::REAL)rcTemp.left, (Gdiplus::REAL)(rcTemp.top + (nHeight - m_sizeImage.cy) / 2), (Gdiplus::REAL)(nWidth-m_nFrameWidth*2), (Gdiplus::REAL)m_sizeImage.cy));
				}else
				if(m_bIsPopup && (m_pImagePopupArrow == NULL))
				{
					// 如果是弹出菜单,并且没有设置菜单的箭头图片,则用菜单图片作为右侧的箭头图片
					graphics.DrawImage(m_pImage, Rect(rcTemp.right - m_sizeImage.cx - 6, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy),
						(i % 2) * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
				}else
				if(m_bSelect)
				{
					// checkbox或radiobutton
					graphics.DrawImage(m_pImage, Rect(rcTemp.left + (m_nLeft - m_sizeImage.cx) / 2, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy),
						i * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
				}else
				{
					// 普通菜单项的图片,如果小图片个数不足,则使用第一个小图片
					graphics.DrawImage(m_pImage, Rect(rcTemp.left + (m_nLeft - m_sizeImage.cx) / 2, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy),
						((m_nImagePicCount-1 < i) ? 0 : i) * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
				}
			}

			// 如果是弹出菜单,并且设置了菜单的箭头图片,则画右侧的箭头图片
			if(m_bIsPopup && (m_pImagePopupArrow != NULL))
			{
				graphics.DrawImage(m_pImagePopupArrow, Rect(rcTemp.right - m_sizePopupArrow.cx - 6, rcTemp.top + (nHeight - m_sizePopupArrow.cy) / 2, m_sizePopupArrow.cx, m_sizePopupArrow.cy),
					(i % 2) * m_sizePopupArrow.cx, 0, m_sizePopupArrow.cx, m_sizePopupArrow.cy, UnitPixel);
			}

			rcTemp.OffsetRect(nWidth, 0);
		}
		
		// 画菜单项文字
		if(!m_strTitle.IsEmpty())
		{
			m_memDC.SetBkMode(TRANSPARENT);

			rcTemp.SetRect(0, 0, nWidth, nHeight);

			BSTR bsFont = m_strFont.AllocSysString();
			FontFamily fontFamily(bsFont);
			Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
			graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
			::SysFreeString(bsFont);

			// 设置菜单文字的水平和垂直对齐方式,默认是水平方向左对齐,垂直方向中间对齐
			DUI_STRING_ALIGN_DEFINE();
			strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);

			for(int i = 0; i < nImageCount; i++)
			{
				SolidBrush solidBrush(enBSDisable == i ? Color(254, 128, 128, 128) : (enBSHover == i || (enBSDown == i && !m_bSelect) || enBSHoverDown == i ? Color(254, 255, 255, 255) : Color(254, 56, 56, 56)));

				RectF rect((Gdiplus::REAL)(m_nLeft + i * nWidth), (Gdiplus::REAL)0, (Gdiplus::REAL)(nWidth - m_nLeft), (Gdiplus::REAL)nHeight);
				BSTR bsTitle = m_strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
				::SysFreeString(bsTitle);
			}
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY);
}
Exemple #12
0
void CDuiTabCtrl::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{
		UpdateMemDC(dc, nWidth, nHeight * 3);

		Graphics graphics(m_memDC);

		BSTR bsFont = m_strFont.AllocSysString();
		FontFamily fontFamily(bsFont);
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		::SysFreeString(bsFont);

		SolidBrush solidBrush(m_clrText);			// 正常文字画刷

		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );

		// 文字的对齐方式
		StringFormat strFormat;
		strFormat.SetAlignment(StringAlignmentCenter);		// 水平方向中间对齐
		strFormat.SetLineAlignment(StringAlignmentCenter);	// 垂直方向中间对齐
		//strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);
		
		for(int i = 0; i < 3; i++)
		{
			m_memDC.BitBlt(0, i * nHeight, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);

			int nXPos = 0;
			int nYPos = i * nHeight;
			for(size_t j = 0; j < m_vecItemInfo.size(); j++)
			{
				TabItemInfo &itemInfo = m_vecItemInfo.at(j);
				
				if(!itemInfo.bVisible)
				{
					continue;
				}

				if(itemInfo.pImage != NULL)	// 使用tab页指定的图片
				{
					int nImageIndex = i;
					if(itemInfo.nImageCount == 1)
					{
						nImageIndex = 0;
					}
					int nX = (itemInfo.rc.Width() - itemInfo.sizeImage.cx) / 2;
					graphics.DrawImage(itemInfo.pImage, Rect(nXPos + nX, nYPos,  itemInfo.sizeImage.cx, itemInfo.sizeImage.cy),
						itemInfo.sizeImage.cx * nImageIndex, 0, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy, UnitPixel);
				}else
				if((m_pImage != NULL) && (itemInfo.nImageIndex != -1))	// 使用tabctrl的索引图片
				{
					// 画底图
					int nX = (itemInfo.rc.Width() - itemInfo.sizeImage.cx) / 2;
					graphics.DrawImage(m_pImage, Rect(nXPos + nX, nYPos,  itemInfo.sizeImage.cx, itemInfo.sizeImage.cy),
						itemInfo.sizeImage.cx * itemInfo.nImageIndex, 0, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy, UnitPixel);
				}

				// 画热点图(如果存在tabctrl设置的热点图的话)
				if((m_pImageHover != NULL) && (i > 0))
				{
					int nX = (itemInfo.rc.Width() - m_sizeHover.cx) / 2;
					if(nX < 0)
					{
						nX = 0;
					}
					graphics.DrawImage(m_pImageHover, Rect(nXPos + nX, nYPos,  m_sizeHover.cx, m_sizeHover.cy),
						m_sizeHover.cx * (i-1), 0, m_sizeHover.cx, m_sizeHover.cy, UnitPixel);
				}

				// 文字
				if(!itemInfo.strText.IsEmpty())
				{
					RectF rectText((Gdiplus::REAL)nXPos, (Gdiplus::REAL)(nYPos + itemInfo.sizeImage.cy + 1), (Gdiplus::REAL)itemInfo.rc.Width(),(Gdiplus::REAL)(m_nTabCtrlHeight - itemInfo.sizeImage.cy - 1));
					if(m_nTabCtrlHeight <= itemInfo.sizeImage.cy)
					{
						// 如果tabctrl高度小于图片高度,则文字直接居中显示
						rectText.Y = (Gdiplus::REAL)nYPos;
						rectText.Height = (Gdiplus::REAL)m_nTabCtrlHeight;
					}
					BSTR bsText = itemInfo.strText.AllocSysString();
					graphics.DrawString(bsText, (INT)wcslen(bsText), &font, rectText, &strFormat, &solidBrush);
					::SysFreeString(bsText);
				}

				nXPos += itemInfo.rc.Width();

				// 画分隔图片(采用拉伸方式)
				if(j < m_vecItemInfo.size() - 1 && m_pImageSeperator != NULL)
				{
					CRect &rc = m_vecRcSeperator.at(j);
					int nSepHeight = itemInfo.rc.Height();	// m_sizeSeperator.cy
					graphics.DrawImage(m_pImageSeperator, Rect(nXPos, nYPos, m_sizeSeperator.cx, nSepHeight),
						0, 0, m_sizeSeperator.cx, m_sizeSeperator.cy, UnitPixel);

					nXPos += m_sizeSeperator.cx;
				}
			}
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, 0, 0, SRCCOPY);

	if((m_nHoverItem != -1) && (m_nHoverItem < (int)m_vecItemInfo.size()))
	{
		TabItemInfo &itemInfo = m_vecItemInfo.at(m_nHoverItem);

		dc.BitBlt(itemInfo.rc.left,itemInfo.rc.top, itemInfo.rc.Width(), itemInfo.rc.Height(), &m_memDC, itemInfo.rc.left - m_rc.left,itemInfo.rc.top - m_rc.top + m_rc.Height(), SRCCOPY);
	}

	if((m_nDownItem != -1) && (m_nDownItem < (int)m_vecItemInfo.size()))
	{
		TabItemInfo &itemInfo = m_vecItemInfo.at(m_nDownItem);

		dc.BitBlt(itemInfo.rc.left,itemInfo.rc.top, itemInfo.rc.Width(), itemInfo.rc.Height(), &m_memDC, itemInfo.rc.left - m_rc.left,itemInfo.rc.top - m_rc.top + m_rc.Height() * 2, SRCCOPY);
	}
}
void CDuiGridCtrl::DrawControl(CDC &dc, CRect rcUpdate)
{
	// 列表画图方法:
	// 1.列表的虚拟高度为每一行高度*行数
	// 2.列表显示的top坐标由scroll控件记录
	// 3.重画时候,根据top坐标位置计算出显示的第一行的序号,根据显示高度计算出显示的最后一行的序号
	// 4.根据计算出的显示的行,画相应的内容到内存dc中
	// 5.计算出显示的top坐标进行内存dc的拷贝
	int nTotalColumnWidth = GetTotalColumnWidth();	// 总的列宽度
	int nViewWidth = m_rc.Width() - m_nScrollWidth;	// 减去滚动条的显示区域宽度
	CDuiScrollHorizontal* pScrollH = (CDuiScrollHorizontal*)m_pControScrollH;
	int nCurPosH = pScrollH->GetScrollCurrentPos();	// 当前left位置
	int nMaxRangeH = pScrollH->GetScrollMaxRange();
	int nContentWidth = (nTotalColumnWidth > nViewWidth) ? nTotalColumnWidth : nViewWidth;	// 内容部分的宽度(如果总的列宽小于显示区域宽度,则使用显示区域宽度)
	m_nVirtualLeft = (nMaxRangeH > 0) ? (int)((double)nCurPosH*(nContentWidth-nViewWidth)/nMaxRangeH) : 0;	// 当前滚动条位置对应的虚拟的left位置

	int nHeightAll = m_vecRowInfo.size()*m_nRowHeight; // 总的虚拟高度 //m_rc.Height();
	CDuiScrollVertical* pScrollV = (CDuiScrollVertical*)m_pControScrollV;
	int nCurPosV = pScrollV->GetScrollCurrentPos();	// 当前top位置
	int nMaxRangeV = pScrollV->GetScrollMaxRange();
	m_nVirtualTop = (nMaxRangeV > 0) ? (int)((double)nCurPosV*(nHeightAll-m_rc.Height())/nMaxRangeV) : 0;	// 当前滚动条位置对应的虚拟的top位置
	if(m_nVirtualTop < 0)
	{
		m_nVirtualTop = 0;
		pScrollV->SetScrollCurrentPos(0);
	}
	m_nFirstViewRow = m_nVirtualTop / m_nRowHeight;					// 显示的第一行序号
	m_nLastViewRow = (m_nVirtualTop + m_rc.Height() - m_nHeaderHeight) / m_nRowHeight;	// 显示的最后一行序号
	if(m_nLastViewRow >= (int)m_vecRowInfo.size())
	{
		m_nLastViewRow = m_vecRowInfo.size() - 1;
	}
	if(m_nLastViewRow < 0)
	{
		m_nLastViewRow = 0;
	}
	int nHeightView = (m_nLastViewRow - m_nFirstViewRow +1) * m_nRowHeight;	// 显示涉及到的虚拟高度
	int nYViewPos = m_nVirtualTop - (m_nFirstViewRow * m_nRowHeight);		// 内存dc显示到屏幕时候的top位置
	if(nYViewPos < 0)
	{
		nYViewPos = 0;
	}

	if(!m_bUpdate)
	{
		UpdateMemDC(dc, nTotalColumnWidth, nHeightView);

		Graphics graphics(m_memDC);
		
		m_memDC.BitBlt(m_nVirtualLeft, 0, nViewWidth, nHeightView, &dc, m_rc.left, m_rc.top, WHITENESS);	// 画白色背景
		DrawVerticalTransition(m_memDC, dc, CRect(m_nVirtualLeft, nYViewPos, nViewWidth+m_nVirtualLeft, m_rc.Height()+nYViewPos-m_nHeaderHeight),	// 背景透明度
				m_rc, m_nBkTransparent, m_nBkTransparent);
		
		BSTR bsFontTitle = m_strFontTitle.AllocSysString();
		FontFamily fontFamilyTitle(bsFontTitle);
		Font fontTitle(&fontFamilyTitle, (REAL)m_nFontTitleWidth, m_fontTitleStyle, UnitPixel);
		::SysFreeString(bsFontTitle);

		BSTR bsFont = m_strFont.AllocSysString();
		FontFamily fontFamily(bsFont);
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		::SysFreeString(bsFont);

		SolidBrush solidBrush(m_clrText);			// 正常文字画刷
		SolidBrush solidBrushH(m_clrTextHover);		// 热点文字画刷
		SolidBrush solidBrushD(m_clrTextDown);		// 当前行画刷
		SolidBrush solidBrushT(m_clrTitle);			// 标题文字画刷
		SolidBrush solidBrushS(m_clrSeperator);		// 分割线画刷

		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );

		// 设置普通文字的水平和垂直对齐方式
		DUI_STRING_ALIGN_DEFINE();

		strFormat.SetTrimming(StringTrimmingEllipsisWord);	// 以单词为单位去尾,略去部分使用省略号
		//strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);
		if(!m_bTextWrap)
		{
			strFormat.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);	// 不换行
		}

		// 标题字段采用中间对齐
		StringFormat strFormatHeader;
		strFormatHeader.SetAlignment(StringAlignmentCenter);	// 中间对齐
		strFormatHeader.SetLineAlignment(StringAlignmentCenter);	// 中间对齐
		if(!m_bTextWrap)
		{
			strFormatHeader.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);	// 不换行
		}

		// 画标题行
		if((m_nHeaderHeight > 0) && (m_vecColumnInfo.size() > 0))
		{
			// 画单元格内容
			int nPosItemX = 0;
			for(size_t j = 0; j < m_vecColumnInfo.size(); j++)
			{
				GridColumnInfo &columnInfo = m_vecColumnInfo.at(j);
				int nWidth = columnInfo.nWidth;
				if(j == 0)
				{
					nWidth += m_nLeftPos;
				}
				RectF rect((Gdiplus::REAL)nPosItemX, 0, (Gdiplus::REAL)nWidth, (Gdiplus::REAL)(m_nHeaderHeight-1));

				// 画列标题
				CString strTitle = columnInfo.strTitle;
				BSTR bsTitle = strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormatHeader, &solidBrushT);
				::SysFreeString(bsTitle);

				nPosItemX += nWidth;
			}
		}
		
		if(m_vecRowInfo.size() > 0)
		{
			for(int i = m_nFirstViewRow; i <= m_nLastViewRow && i < (int)m_vecRowInfo.size(); i++)
			{
				GridRowInfo &rowInfo = m_vecRowInfo.at(i);
				SolidBrush solidBrushRow(rowInfo.clrText);	// 行定义的颜色

				int nXPos = 0;
				int nVI = i - m_nFirstViewRow;

				// 鼠标移动到行时候显示的背景颜色(如果设置为全0,则不显示行背景颜色)
				if((m_nHoverRow == i) && (m_clrRowHover.GetValue() != Color(0, 0, 0, 0).GetValue()))
				{
					SolidBrush brush(m_clrRowHover);
					graphics.FillRectangle(&brush, 0, m_nHeaderHeight + nVI*m_nRowHeight, nContentWidth, m_nRowHeight);
				}

				// 画检查框
				int nCheckImgY = 3;
				if((m_sizeCheckBox.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
				{
					nCheckImgY = (m_nRowHeight - m_sizeCheckBox.cy) / 2 + 1;
				}
				if((rowInfo.nCheck != -1) && (m_pImageCheckBox != NULL))
				{
					int nCheckImageIndex = ((m_nHoverRow == i) ? ((rowInfo.nCheck==1) ? 4 : 1) : ((rowInfo.nCheck==1) ? 2 : 0));
					graphics.DrawImage(m_pImageCheckBox, Rect(nXPos, m_nHeaderHeight + nVI*m_nRowHeight + nCheckImgY, m_sizeCheckBox.cx, m_sizeCheckBox.cy),
						nCheckImageIndex * m_sizeCheckBox.cx, 0, m_sizeCheckBox.cx, m_sizeCheckBox.cy, UnitPixel);
					rowInfo.rcCheck.SetRect(nXPos, i*m_nRowHeight + nCheckImgY, nXPos + m_sizeCheckBox.cx, i*m_nRowHeight + nCheckImgY + m_sizeCheckBox.cy);
					nXPos += (m_sizeCheckBox.cx + 3);
				}

				// 画行左边图片
				int nImgY = 3;
				if(rowInfo.pImage != NULL)
				{
					if((rowInfo.sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - rowInfo.sizeImage.cy) / 2 + 1;
					}
					// 使用行数据指定的图片
					graphics.DrawImage(rowInfo.pImage, Rect(nXPos, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy),
						0, 0, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy, UnitPixel);
					nXPos += (rowInfo.sizeImage.cx + 3);
				}else
				if((rowInfo.nImageIndex != -1) && (m_pImage != NULL))
				{
					if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1;
					}
					// 使用索引图片
					graphics.DrawImage(m_pImage, Rect(nXPos, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy),
						rowInfo.nImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
					nXPos += (m_sizeImage.cx + 3);
				}

				// 画行右边图片
				int nRightImageWidth = 0;
				nImgY = 3;
				if(rowInfo.pRightImage != NULL)
				{
					if((rowInfo.sizeRightImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - rowInfo.sizeRightImage.cy) / 2 + 1;
					}
					// 使用行数据指定的图片
					graphics.DrawImage(rowInfo.pRightImage, Rect(nContentWidth-rowInfo.sizeRightImage.cx-1, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy),
						0, 0, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy, UnitPixel);
					nRightImageWidth = rowInfo.sizeRightImage.cx + 1;
				}else
				if((rowInfo.nRightImageIndex != -1) && (m_pImage != NULL))
				{
					if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1;
					}
					// 使用索引图片
					graphics.DrawImage(m_pImage, Rect(nContentWidth-m_sizeImage.cx-1, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy),
						rowInfo.nRightImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
					nRightImageWidth = m_sizeImage.cx + 1;
				}

				// 画单元格内容
				int nPosItemX = (m_nLeftPos != 0) ? m_nLeftPos : nXPos;
				for(size_t j = 0; j < rowInfo.vecItemInfo.size(); j++)
				{
					GridColumnInfo &columnInfo = m_vecColumnInfo.at(j);
					GridItemInfo &itemInfo = rowInfo.vecItemInfo.at(j);
					BOOL bSingleLine = (itemInfo.strContent.IsEmpty() || !itemInfo.strLink.IsEmpty());
					RectF rect((Gdiplus::REAL)nPosItemX,
						(Gdiplus::REAL)(m_nHeaderHeight + nVI*m_nRowHeight + 1),
						(Gdiplus::REAL)((j == 0) ? (itemInfo.rcItem.Width() - nPosItemX): itemInfo.rcItem.Width()),
						(Gdiplus::REAL)(bSingleLine ? (m_nRowHeight - 2) : (m_nRowHeight / 2 - 2)));
					if((int)(rect.GetRight()) > nContentWidth)
					{
						// 最后一列需要减去滚动条宽度
						rect.Width -= m_nScrollWidth;
					}

					// 画单元格图片
					int nItemImageX = 0;
					int nImgY = 3;
					if(itemInfo.pImage != NULL)
					{
						if((itemInfo.sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
						{
							nImgY = (m_nRowHeight - rowInfo.sizeImage.cy) / 2 + 1;
						}
						// 使用单元格指定的图片
						graphics.DrawImage(itemInfo.pImage, Rect(nPosItemX+nItemImageX, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy),
							0, 0, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy, UnitPixel);
						nItemImageX += (itemInfo.sizeImage.cx + 3);
					}else
					if((itemInfo.nImageIndex != -1) && (m_pImage != NULL))
					{
						if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
						{
							nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1;
						}
						// 使用索引图片
						graphics.DrawImage(m_pImage, Rect(nPosItemX+nItemImageX, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy),
							itemInfo.nImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
						nItemImageX += (m_sizeImage.cx + 3);
					}
					rect.Offset((Gdiplus::REAL)nItemImageX, 0);
					rect.Width -= (Gdiplus::REAL)nItemImageX;

					// 画单元格标题或链接内容
					SolidBrush solidBrushItem(m_clrText);
					if((m_nHoverRow == i) && (m_clrTextHover.GetValue() != Color(0, 0, 0, 0).GetValue()))	// 设置了鼠标移动颜色,则使用
					{
						solidBrushItem.SetColor(m_clrTextHover);
					}else
					if((m_nDownRow == i) && (m_clrTextDown.GetValue() != Color(0, 0, 0, 0).GetValue()))	// 设置了鼠标按下颜色,则使用
					{
						solidBrushItem.SetColor(m_clrTextDown);
					}else
					if(itemInfo.clrText.GetValue() != Color(0, 0, 0, 0).GetValue())	// 设置了单元格颜色,则使用
					{
						solidBrushItem.SetColor(itemInfo.clrText);
					}else
					if(rowInfo.bRowColor)	// 设置了行颜色,则使用
					{
						solidBrushItem.SetColor(rowInfo.clrText);
					}
					CString strItemTitle = itemInfo.strTitle;
					// 计算是否需要显示tip
					itemInfo.bNeedTitleTip = rect.Width < GetTextBounds(font, strItemTitle).Width;
					itemInfo.bNeedContentTip = rect.Width < GetTextBounds(font, itemInfo.strContent).Width;
					if(!itemInfo.strLink.IsEmpty())
					{
						strItemTitle = itemInfo.strLink;
						if((m_nHoverRow == i) && (rowInfo.nHoverItem == j))
						{
							solidBrushItem.SetColor(m_clrTextHover);
						}else
						{
							solidBrushItem.SetColor((itemInfo.clrText.GetValue() != Color(0, 0, 0, 0).GetValue()) ? itemInfo.clrText : m_clrText);
						}
					}

					// 设置单元格文字对齐方式,使用列的对齐方式
					StringFormat strFormatColumn;
					UINT uAlignment = m_uAlignment;
					if(columnInfo.uAlignment != 0xFFFFUL)
					{
						uAlignment = columnInfo.uAlignment;
					}
					if(uAlignment == Align_Left)
					{
						strFormatColumn.SetAlignment(StringAlignmentNear);
					}else
					if(uAlignment == Align_Center)
					{
						strFormatColumn.SetAlignment(StringAlignmentCenter);
					}else
					if(uAlignment == Align_Right)
					{
						strFormatColumn.SetAlignment(StringAlignmentFar);
					}
					UINT uVAlignment = m_uVAlignment;
					if(columnInfo.uVAlignment != 0xFFFFUL)
					{
						uVAlignment = columnInfo.uVAlignment;
					}
					if(uVAlignment == VAlign_Top)
					{
						strFormatColumn.SetLineAlignment(StringAlignmentNear);
					}else
					if(uVAlignment == VAlign_Middle)
					{
						strFormatColumn.SetLineAlignment(StringAlignmentCenter);
					}else
					if(uVAlignment == VAlign_Bottom)
					{
						strFormatColumn.SetLineAlignment(StringAlignmentFar);
					}
					if(!m_bTextWrap)
					{
						strFormatColumn.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);	// 不换行
					}

					// 根据bUseTitleFont决定用标题字体还是普通字体
					BSTR bsItemTitle = strItemTitle.AllocSysString();
					graphics.DrawString(bsItemTitle, (INT)wcslen(bsItemTitle),
						itemInfo.bUseTitleFont ? &fontTitle : &font, rect, &strFormatColumn, itemInfo.bUseTitleFont ? &solidBrushT : &solidBrushItem);
					::SysFreeString(bsItemTitle);

					// 画单元格内容
					if(!bSingleLine)
					{
						rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2);
						rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4;
						BSTR bsItemContent = itemInfo.strContent.AllocSysString();
						graphics.DrawString(bsItemContent, (INT)wcslen(bsItemContent), &font, rect, &strFormatColumn, &solidBrushItem);
						::SysFreeString(bsItemContent);
					}

					// 设置单元格子控件的位置
					for(size_t k = 0; k < itemInfo.vecControl.size(); k++)
					{
						CControlBase* pControl = itemInfo.vecControl.at(k);
						if(pControl)
						{
							CRect rcParent = CRect(nPosItemX, m_nHeaderHeight + nVI*m_nRowHeight + 1,
								(int)(rect.X+rect.Width), (nVI+1)*m_nRowHeight - 1);
							if((int)(rect.GetRight()) > nContentWidth)
							{
								// 最后一列需要减去滚动条宽度
								rcParent.right -= m_nScrollWidth;
							}
							rcParent.OffsetRect(m_rc.left - m_nVirtualLeft, m_rc.top - (nYViewPos + m_nHeaderHeight));
							pControl->SetPositionWithParent(rcParent);
							CRect rcControl = pControl->GetRect();
							// 只有当前在显示范围内的控件设置为可见
							if( (rcControl.top < m_rc.top) || (rcControl.bottom > m_rc.bottom) ||
								(rcControl.left < m_rc.left) || (rcControl.right > m_rc.right) )
							{
								pControl->SetVisible(FALSE);
							}else
							{
								pControl->SetVisible(TRUE);
							}
						}
					}

					if(j == 0)
					{
						// 为了使第二列开始是对齐的,所以第二列开始位置按照第一列的宽度计算
						nPosItemX = itemInfo.rcItem.right;
					}else
					{
						nPosItemX += itemInfo.rcItem.Width();
					}
				}

				// 画分隔线(采用拉伸模式)
				if(m_pImageSeperator != NULL)
				{
					// 使用拉伸模式画图
					graphics.DrawImage(m_pImageSeperator, RectF(0, (Gdiplus::REAL)(m_nHeaderHeight + (nVI+1)*m_nRowHeight), (Gdiplus::REAL)(nContentWidth-2), (Gdiplus::REAL)m_sizeSeperator.cy),
							0, 0, (Gdiplus::REAL)m_sizeSeperator.cx, (Gdiplus::REAL)m_sizeSeperator.cy, UnitPixel);
				}else
				if(m_clrSeperator.GetValue() != Color(0, 0, 0, 0).GetValue())
				{
					// 未指定图片,并且分隔线显色不是全0,则画矩形
					graphics.FillRectangle(&solidBrushS, 0, m_nHeaderHeight + (nVI+1)*m_nRowHeight, nContentWidth-2, 1);
				}
			}

			// 把不在显示范围内的单元格的控件都设置为不可见
			for(int i = 0; i < (int)m_vecRowInfo.size(); i++)
			{
				if((i < m_nFirstViewRow) || (i > m_nLastViewRow))
				{
					GridRowInfo &rowInfo = m_vecRowInfo.at(i);
					for(size_t j = 0; j < rowInfo.vecItemInfo.size(); j++)
					{
						GridItemInfo &itemInfo = rowInfo.vecItemInfo.at(j);
						for(size_t k = 0; k < itemInfo.vecControl.size(); k++)
						{
							CControlBase* pControl = itemInfo.vecControl.at(k);
							if(pControl)
							{
								pControl->SetVisible(FALSE);
							}
						}
					}
				}
			}
		}
	}

	// 输出到界面DC,使用与的方式合并背景
	// 标题行输出
	if(m_nHeaderHeight > 0)
	{
		dc.BitBlt(m_rc.left,m_rc.top, nViewWidth, m_nHeaderHeight, &m_memDC, m_nVirtualLeft, 0, SRCCOPY);//SRCAND);
	}
	// 内容部分输出
	int nContentHeight = m_rc.Height() - m_nHeaderHeight;
	if(nTotalColumnWidth > m_rc.Width())
	{
		nContentHeight -= m_nScrollWidth;
	}
	dc.BitBlt(m_rc.left,m_rc.top + m_nHeaderHeight, nViewWidth, nContentHeight, &m_memDC, m_nVirtualLeft, nYViewPos + m_nHeaderHeight, SRCCOPY);//SRCAND);
}
Exemple #14
0
void CDuiText::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();
	
	// 计算显示位置
	CDuiScrollVertical* pScrollV = (CDuiScrollVertical*)m_pControScrollV;
	int nCurPos = pScrollV->GetScrollCurrentPos();	// 当前top位置
	int nMaxRange = pScrollV->GetScrollMaxRange();
	int nVirtualTop = 0;	// 当前显示的是虚拟图片中什么位置开始的图片
	m_nVirtualHeight = GetVirtualHeight();
	if(m_nVirtualHeight > m_rc.Height())
	{
		nVirtualTop = (nMaxRange > 0) ? nCurPos*(m_nVirtualHeight-m_rc.Height())/nMaxRange : 0;
	}else
	{
		nVirtualTop = 0;
	}

	if(!m_bUpdate)
	{
		UpdateMemDC(dc, nWidth, m_nVirtualHeight);

		Graphics graphics(m_memDC);
		
		if(m_bBack)
		{
			SolidBrush brush(m_clrBack);
			graphics.FillRectangle(&brush, 0, 0, nWidth, nHeight);
		}
		else
		{
			//m_memDC.BitBlt(0, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);
			m_memDC.BitBlt(0, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, WHITENESS);	// 画白色背景
			DrawVerticalTransition(m_memDC, dc, CRect(0, 0+nVirtualTop, nWidth, nHeight+nVirtualTop),	// 背景透明度
					m_rc, m_nBkTransparent, m_nBkTransparent);
		}
		
		BSTR bsFont = m_strFont.AllocSysString();
		FontFamily fontFamily(bsFont);
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		::SysFreeString(bsFont);

		SolidBrush solidBrush(m_clrText);
		
		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );

		// 设置水平和垂直对齐方式
		DUI_STRING_ALIGN_DEFINE();

		//strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
		strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);
		//strFormat.SetTrimming(StringTrimmingEllipsisWord);	// 以单词为单位去尾,略去部分使用省略号

		int nXPos = 0;
		if(m_pImage != NULL)
		{
			graphics.DrawImage(m_pImage, Rect(0, (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy),
				0, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
			nXPos += m_sizeImage.cx + 5;
		}
		
		Size size = GetTextBounds(font, strFormat, nWidth, m_strTitle);
		
		int nStart = m_strTitle.Find(m_strMark, m_nStart);
		if(m_strMark.IsEmpty() || (nStart == -1))
		{
			int nTextWidth = nWidth - nXPos;
			if(m_bScrollV)
			{
				nTextWidth -= m_nScrollWidth;
			}

			// 先画阴影
			if(m_bEnableShadow)
			{
				RectF rectShadow((Gdiplus::REAL)(nXPos  + 1), (Gdiplus::REAL)1, (Gdiplus::REAL)nTextWidth, (Gdiplus::REAL)max(size.Height, nHeight));
				SolidBrush solidBrushS(m_clrTextShadow);
				BSTR bsTitle = m_strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rectShadow, &strFormat, &solidBrushS);
				::SysFreeString(bsTitle);
			}

			// 再画正常的文字
			RectF rect((Gdiplus::REAL)(nXPos), (Gdiplus::REAL)0, (Gdiplus::REAL)nTextWidth, (Gdiplus::REAL)(max(size.Height, nHeight)));
			if((m_enButtonState == enBSHover) && m_bEnableHover)
			{
				SolidBrush solidBrushH(m_clrTextHover);
				BSTR bsTitle = m_strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrushH);
				::SysFreeString(bsTitle);
			}else
			{
				BSTR bsTitle = m_strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
				::SysFreeString(bsTitle);
			}
		}
		else
		{
			SolidBrush solidBrushM(m_clrMark);
			SolidBrush solidBrushS(m_clrTextShadow);

			CString srtL = m_strTitle.Left(nStart);
			CString srtR  = m_strTitle.Right(m_strTitle.GetLength() - m_strMark.GetLength() - nStart);
			Size sizeL = GetTextBounds(font, strFormat, srtL);
			Size sizeM = GetTextBounds(font, strFormat, m_strMark);
			Size sizeR = GetTextBounds(font, strFormat, srtR);

			if(m_bEnableShadow)
			{
				BSTR bsL = srtL.AllocSysString();
				graphics.DrawString(bsL, (INT)wcslen(bsL), &font, 
					PointF((Gdiplus::REAL)(nXPos + 1), (Gdiplus::REAL)1), &strFormat, &solidBrushS);
				::SysFreeString(bsL);
				BSTR bsMark = m_strMark.AllocSysString();
				graphics.DrawString(bsMark, (INT)wcslen(bsMark), &font, 
					PointF((Gdiplus::REAL)(nXPos + sizeL.Width + 2 + 1), (Gdiplus::REAL)1), &strFormat, &solidBrushS);
				::SysFreeString(bsMark);
			}
			BSTR bsL = srtL.AllocSysString();
			graphics.DrawString(bsL, (INT)wcslen(bsL), &font, 
				PointF((Gdiplus::REAL)(nXPos), (Gdiplus::REAL)0), &strFormat, &solidBrush);
			::SysFreeString(bsL);
			BSTR bsMark = m_strMark.AllocSysString();
			graphics.DrawString(bsMark, (INT)wcslen(bsMark), &font, 
				PointF((Gdiplus::REAL)(nXPos + sizeL.Width + 2), (Gdiplus::REAL)0), &strFormat, &solidBrushM);
			::SysFreeString(bsMark);

			if(m_bEnableShadow)
			{
				RectF rect((Gdiplus::REAL)(nXPos + sizeL.Width + sizeM.Width + 4 + 1), (Gdiplus::REAL)(1), (Gdiplus::REAL)(nWidth - (nXPos + sizeL.Width + sizeM.Width + 4)), (Gdiplus::REAL)nHeight);
				BSTR bsR = srtR.AllocSysString();
				graphics.DrawString(bsR, (INT)wcslen(bsR), &font, 
					PointF((Gdiplus::REAL)(nXPos + sizeL.Width + sizeM.Width + 4), (Gdiplus::REAL)0), &strFormat, &solidBrushS);
				::SysFreeString(bsR);
			}
			//RectF rect(nXPos + point.x + sizeL.Width + sizeM.Width + 4, point.y, nWidth - (nXPos + sizeL.Width + sizeM.Width + 4 + point.x), size.Height);
			RectF rect((Gdiplus::REAL)(nXPos + sizeL.Width + sizeM.Width + 4), (Gdiplus::REAL)0, (Gdiplus::REAL)(nWidth - (nXPos + sizeL.Width + sizeM.Width + 4)), (Gdiplus::REAL)nHeight);
			BSTR bsR = srtR.AllocSysString();
			graphics.DrawString(bsR, (INT)wcslen(bsR), &font, 
				PointF((Gdiplus::REAL)(nXPos + sizeL.Width + sizeM.Width + 4), (Gdiplus::REAL)0), &strFormat, &solidBrush);
			::SysFreeString(bsR);
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, 0, nVirtualTop, SRCCOPY);
}
Exemple #15
0
void CDuiEdit::DrawControl(CDC &dc, CRect rcUpdate)
{
	Graphics graphics(dc);

	DrawImageFrame(graphics, m_pImage, m_rc, m_EditState * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, 4);

	if(m_pLeftImage)
	{
		CRect  rc;
		rc.left = m_rc.left + 2;
		rc.top = m_rc.top + (m_rc.Height() - m_sizeLeftImage.cy) / 2;
		rc.right = rc.left + m_sizeLeftImage.cx;
		rc.bottom = rc.top + m_sizeLeftImage.cy;
		
		if(m_nLeftImageCount > m_buttonState)
		{
			graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
				(Gdiplus::REAL)(m_buttonState * m_sizeLeftImage.cx), 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel);
		}else
		{
			graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
				0, 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel);
		}
	}

	if(m_pSmallImage)
	{
		CRect  rc;
		rc.left = m_rc.right - m_sizeSmallImage.cx - 2;
		rc.top = m_rc.top + (m_rc.Height() - m_sizeSmallImage.cy) / 2;
		rc.right = rc.left + m_sizeSmallImage.cx;
		rc.bottom = rc.top + m_sizeSmallImage.cy;
		
		if(m_nSmallImageCount > m_buttonState)
		{
			graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
				(Gdiplus::REAL)(m_buttonState * m_sizeSmallImage.cx), 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel);
		}else
		{
			graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
				0, 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel);
		}
	}

	BSTR bsFont = m_strFont.AllocSysString();
	FontFamily fontFamily(bsFont);
	Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
	SolidBrush solidBrush(m_clrText);
	SolidBrush solidBrushTip(m_clrTooltip);
	graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
	::SysFreeString(bsFont);
	StringFormat strFormat;
	strFormat.SetAlignment(StringAlignmentNear);		// 水平方向左对齐
	if(!m_bMultiLine)
	{
		// 单行文字
		strFormat.SetLineAlignment(StringAlignmentCenter);	// 垂直方向中间对齐
		strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
	}else
	{
		strFormat.SetLineAlignment(StringAlignmentNear);	// 垂直方向上对齐
	}

	RectF rect((Gdiplus::REAL)m_rcText.left, (Gdiplus::REAL)(m_rcText.top+2), (Gdiplus::REAL)m_rcText.Width(), (Gdiplus::REAL)(m_rcText.Height()-2));

	if(!m_strTitle.IsEmpty())
	{
		// 文字非空
		CString strTitle = m_strTitle;
		if(m_bPassWord)
		{
			int nlen = strTitle.GetLength();
			strTitle = "";
			for(int i = 0; i < nlen; i++)
			{
				strTitle += '*';
			}
		}

		BSTR bsTitle = strTitle.AllocSysString();
		graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
		::SysFreeString(bsTitle);
	}else
	if(!m_strTooltip.IsEmpty())
	{
		// 如果没有文字,但设置了tooltip,则显示tooltip
		BSTR bsTooltip = m_strTooltip.AllocSysString();
		graphics.DrawString(bsTooltip, (INT)wcslen(bsTooltip), &font, rect, &strFormat, &solidBrushTip);
		::SysFreeString(bsTooltip);
	}
}
Exemple #16
0
void CDuiListCtrl::DrawControl(CDC &dc, CRect rcUpdate)
{
	// 列表画图方法:
	// 1.列表的虚拟高度为每一行高度*行数
	// 2.列表显示的top坐标由scroll控件记录
	// 3.重画时候,根据top坐标位置计算出显示的第一行的序号,根据显示高度计算出显示的最后一行的序号
	// 4.根据计算出的显示的行,画相应的内容到内存dc中
	// 5.计算出显示的top坐标进行内存dc的拷贝
	int nWidth = m_rc.Width() - m_nScrollWidth;	// 减去滚动条的宽度
	int nHeightAll = (int)m_vecRowInfo.size()*m_nRowHeight; // 总的虚拟高度 //m_rc.Height();
	CScrollV* pScrollV = (CScrollV*)m_pControScrollV;
	int nCurPos = pScrollV->GetScrollCurrentPos();	// 当前top位置
	int nMaxRange = pScrollV->GetScrollMaxRange();

	m_nVirtualTop = (nMaxRange > 0) ? nCurPos*(nHeightAll-m_rc.Height())/nMaxRange : 0;	// 当前滚动条位置对应的虚拟的top位置
	if(m_nVirtualTop < 0)
	{
		m_nVirtualTop = 0;
		pScrollV->SetScrollCurrentPos(0);
	}
	m_nFirstViewRow = m_nVirtualTop / m_nRowHeight;					// 显示的第一行序号
	m_nLastViewRow = (m_nVirtualTop + m_rc.Height()) / m_nRowHeight;	// 显示的最后一行序号
	if(m_nLastViewRow >= (int)m_vecRowInfo.size())
	{
		m_nLastViewRow = (int)m_vecRowInfo.size() - 1;
	}
	if(m_nLastViewRow < 0)
	{
		m_nLastViewRow = 0;
	}
	int nHeightView = (m_nLastViewRow - m_nFirstViewRow +1) * m_nRowHeight;	// 显示涉及到的虚拟高度
	int nYViewPos = m_nVirtualTop - (m_nFirstViewRow * m_nRowHeight);		// 内存dc显示到屏幕时候的top位置
	if(nYViewPos < 0)
	{
		nYViewPos = 0;
	}

	if(!m_bUpdate)
	{
		UpdateMemDC(dc, nWidth, nHeightView);

		Graphics graphics(m_memDC);
		
		m_memDC.BitBlt(0, 0, nWidth, nHeightView, &dc, m_rc.left ,m_rc.top, WHITENESS);	// 画白色背景
		DrawVerticalTransition(m_memDC, dc, CRect(0, nYViewPos, nWidth, m_rc.Height()+nYViewPos),	// 背景透明度
				m_rc, m_nBkTransparent, m_nBkTransparent);
		
		BSTR bsFontTitle = m_strFontTitle.AllocSysString();
		FontFamily fontFamilyTitle(bsFontTitle);
		Font fontTitle(&fontFamilyTitle, (REAL)m_nFontTitleWidth, m_fontTitleStyle, UnitPixel);
		::SysFreeString(bsFontTitle);

		BSTR bsFont = m_strFont.AllocSysString();
		FontFamily fontFamily(bsFont);
		Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
		::SysFreeString(bsFont);

		SolidBrush solidBrush(m_clrText);			// 正常文字画刷
		SolidBrush solidBrushH(m_clrTextHover);		// 热点文字画刷
		SolidBrush solidBrushD(m_clrTextDown);		// 当前行画刷
		SolidBrush solidBrushT(m_clrTitle);			// 标题文字画刷
		SolidBrush solidBrushS(m_clrSeperator);		// 分割线画刷

		graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );

		// 普通文字的对齐方式
		StringFormat strFormat;
		strFormat.SetAlignment(StringAlignmentNear);	// 左对齐
		if(m_uVAlignment == VAlign_Top)
		{
			strFormat.SetLineAlignment(StringAlignmentNear);	// 上对其
		}else
		if(m_uVAlignment == VAlign_Middle)
		{
			strFormat.SetLineAlignment(StringAlignmentCenter);	// 中间对齐
		}else
		if(m_uVAlignment == VAlign_Bottom)
		{
			strFormat.SetLineAlignment(StringAlignmentFar);	// 下对齐
		}
		strFormat.SetTrimming(StringTrimmingEllipsisWord);	// 以单词为单位去尾,略去部分使用省略号
		//strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);
		if(!m_bTextWrap)
		{
			strFormat.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);	// 不换行
		}

		// 时间字段采用右对齐
		StringFormat strFormatRight;
		strFormatRight.SetAlignment(StringAlignmentFar);	// 右对齐
		if(m_uVAlignment == VAlign_Top)
		{
			strFormatRight.SetLineAlignment(StringAlignmentNear);	// 上对其
		}else
		if(m_uVAlignment == VAlign_Middle)
		{
			strFormatRight.SetLineAlignment(StringAlignmentCenter);	// 中间对齐
		}else
		if(m_uVAlignment == VAlign_Bottom)
		{
			strFormatRight.SetLineAlignment(StringAlignmentFar);	// 下对齐
		}
		//strFormatRight.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);
		if(!m_bTextWrap)
		{
			strFormatRight.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);	// 不换行
		}
		
		if(m_vecRowInfo.size() > 0)
		{
			for(int i = m_nFirstViewRow; i <= m_nLastViewRow && i < (int)m_vecRowInfo.size(); i++)
			{
				ListRowInfo &rowInfo = m_vecRowInfo.at(i);
				SolidBrush solidBrushRow(rowInfo.clrText);	// 行定义的颜色

				int nXPos = 0;
				int nVI = i - m_nFirstViewRow;

				// 鼠标移动到行时候显示的背景颜色
				if(m_nHoverRow == i)
				{
					SolidBrush brush(m_clrRowHover);
					graphics.FillRectangle(&brush, 0, nVI*m_nRowHeight, nWidth, m_nRowHeight);
				}

				// 画检查框
				int nCheckImgY = 3;
				if((m_sizeCheckBox.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
				{
					nCheckImgY = (m_nRowHeight - m_sizeCheckBox.cy) / 2 + 1;
				}
				if((rowInfo.nCheck != -1) && (m_pImageCheckBox != NULL))
				{
					int nCheckImageIndex = ((m_nHoverRow == i) ? ((rowInfo.nCheck==1) ? 4 : 1) : ((rowInfo.nCheck==1) ? 2 : 0));
					graphics.DrawImage(m_pImageCheckBox, Rect(nXPos, nVI*m_nRowHeight + nCheckImgY, m_sizeCheckBox.cx, m_sizeCheckBox.cy),
						nCheckImageIndex * m_sizeCheckBox.cx, 0, m_sizeCheckBox.cx, m_sizeCheckBox.cy, UnitPixel);
					rowInfo.rcCheck.SetRect(nXPos, i*m_nRowHeight + nCheckImgY, nXPos + m_sizeCheckBox.cx, i*m_nRowHeight + nCheckImgY + m_sizeCheckBox.cy);
					nXPos += (m_sizeCheckBox.cx + 3);
				}

				// 画行左边图片
				int nImgY = 3;
				if(rowInfo.pImage != NULL)
				{
					if((rowInfo.sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - rowInfo.sizeImage.cy) / 2 + 1;
					}
					// 使用行数据指定的图片
					graphics.DrawImage(rowInfo.pImage, Rect(nXPos, nVI*m_nRowHeight + nImgY, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy),
						0, 0, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy, UnitPixel);
					nXPos += (rowInfo.sizeImage.cx + 3);
				}else
				if((rowInfo.nImageIndex != -1) && (m_pImage != NULL))
				{
					if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1;
					}
					// 使用索引图片
					graphics.DrawImage(m_pImage, Rect(nXPos, nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy),
						rowInfo.nImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
					nXPos += (m_sizeImage.cx + 3);
				}

				// 画行右边图片
				int nRightImageWidth = 0;
				nImgY = 3;
				if(rowInfo.pRightImage != NULL)
				{
					if((rowInfo.sizeRightImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - rowInfo.sizeRightImage.cy) / 2 + 1;
					}
					// 使用行数据指定的图片
					graphics.DrawImage(rowInfo.pRightImage, Rect(nWidth-rowInfo.sizeRightImage.cx-1, nVI*m_nRowHeight + nImgY, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy),
						0, 0, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy, UnitPixel);
					nRightImageWidth = rowInfo.sizeRightImage.cx + 1;
				}else
				if((rowInfo.nRightImageIndex != -1) && (m_pImage != NULL))
				{
					if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle))
					{
						nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1;
					}
					// 使用索引图片
					graphics.DrawImage(m_pImage, Rect(nWidth-m_sizeImage.cx-1, nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy),
						rowInfo.nRightImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
					nRightImageWidth = m_sizeImage.cx + 1;
				}

				// 画内容
				RectF rect((Gdiplus::REAL)nXPos, (Gdiplus::REAL)(nVI*m_nRowHeight + 1), (Gdiplus::REAL)(nWidth-20), (Gdiplus::REAL)(m_bSingleLine ? (m_nRowHeight - 2) : (m_nRowHeight / 2 - 2)) );
				if(!rowInfo.strTime.IsEmpty())
				{
					Size size = GetTextBounds(font, rowInfo.strTime);
					rect.Width -= (size.Width + 5);
				}

				// 链接文字
				int nLinkWidth = 0;
				if(!rowInfo.strLink2.IsEmpty())
				{
					Size sizeLink = GetTextBounds(font, strFormatRight, rowInfo.strLink2);
					nLinkWidth += (sizeLink.Width + 10);
					RectF rectLink((Gdiplus::REAL)(nWidth-nLinkWidth-nRightImageWidth), (Gdiplus::REAL)(nVI*m_nRowHeight + (m_nRowHeight - sizeLink.Height)/2), (Gdiplus::REAL)(sizeLink.Width+8), (Gdiplus::REAL)sizeLink.Height);
					rowInfo.rcLink2.SetRect((int)rectLink.X,(int)rectLink.Y,(int)(rectLink.X+sizeLink.Width),(int)(rectLink.Y+rectLink.Height));
					rowInfo.rcLink2.OffsetRect(0, m_nFirstViewRow*m_nRowHeight);
					if(((m_nHoverRow == i) || (m_nDownRow == i)) && (rowInfo.nHoverLink == 1))
					{
						BSTR bsLink2 = rowInfo.strLink2.AllocSysString();
						graphics.DrawString(bsLink2, (INT)wcslen(bsLink2), &font, rectLink, &strFormatRight, &solidBrushH);
						::SysFreeString(bsLink2);
					}else
					{
						BSTR bsLink2 = rowInfo.strLink2.AllocSysString();
						graphics.DrawString(bsLink2, (INT)wcslen(bsLink2), &font, rectLink, &strFormatRight, &solidBrush);
						::SysFreeString(bsLink2);
					}
				}
				if(!rowInfo.strLink1.IsEmpty())
				{
					Size sizeLink = GetTextBounds(font, strFormatRight, rowInfo.strLink1);
					nLinkWidth += (sizeLink.Width + 10);
					RectF rectLink((Gdiplus::REAL)(nWidth-nLinkWidth-nRightImageWidth), (Gdiplus::REAL)(nVI*m_nRowHeight + (m_nRowHeight - sizeLink.Height)/2), (Gdiplus::REAL)(sizeLink.Width+8), (Gdiplus::REAL)sizeLink.Height);
					rowInfo.rcLink1.SetRect((int)rectLink.X,(int)rectLink.Y,(int)(rectLink.X+sizeLink.Width),(int)(rectLink.Y+rectLink.Height));
					rowInfo.rcLink1.OffsetRect(0, m_nFirstViewRow*m_nRowHeight);
					if(((m_nHoverRow == i) || (m_nDownRow == i)) && (rowInfo.nHoverLink == 0))
					{
						BSTR bsLink1 = rowInfo.strLink1.AllocSysString();
						graphics.DrawString(bsLink1, (INT)wcslen(bsLink1), &font, rectLink, &strFormatRight, &solidBrushH);
						::SysFreeString(bsLink1);
					}else
					{
						BSTR bsLink1 = rowInfo.strLink1.AllocSysString();
						graphics.DrawString(bsLink1, (INT)wcslen(bsLink1), &font, rectLink, &strFormatRight, &solidBrush);
						::SysFreeString(bsLink1);
					}
				}
				
				rect.Width -= nLinkWidth;
				// 计算是否需要显示tip
				rowInfo.bNeedTitleTip = rect.Width < GetTextBounds(font, rowInfo.strTitle).Width;
				rowInfo.bNeedContentTip = rect.Width < GetTextBounds(font, rowInfo.strContent).Width;
				Size sizeTime = GetTextBounds(font, strFormatRight, rowInfo.strTime);
				int nTimeWidth = sizeTime.Width + 10;
				RectF rectTime((Gdiplus::REAL)(nWidth-nRightImageWidth-2-nTimeWidth-nLinkWidth), (Gdiplus::REAL)(nVI*m_nRowHeight + 1), (Gdiplus::REAL)nTimeWidth, (Gdiplus::REAL)(m_bSingleLine ? m_nRowHeight : (m_nRowHeight / 2)) );
				if(m_nHoverRow == i)
				{
					// 画标题行
					BSTR bsTitle = rowInfo.strTitle.AllocSysString();
					graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &fontTitle, rect, &strFormat, &solidBrushH);
					::SysFreeString(bsTitle);
					// 画时间
					if(!rowInfo.strTime.IsEmpty())
					{
						BSTR bsTime = rowInfo.strTime.AllocSysString();
						graphics.DrawString(bsTime, (INT)wcslen(bsTime), &font, rectTime, &strFormatRight, &solidBrushH);
						::SysFreeString(bsTime);
					}
					// 画内容行
					if(!m_bSingleLine)
					{
						rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2);
						rect.Width = (Gdiplus::REAL)nWidth-20;
						rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4;
						BSTR bsContent = rowInfo.strContent.AllocSysString();
						graphics.DrawString(bsContent, (INT)wcslen(bsContent), &font, rect, &strFormat, &solidBrushH);
						::SysFreeString(bsContent);
					}
				}else
				if(m_nDownRow == i)
				{
					// 画标题行
					BSTR bsTitle = rowInfo.strTitle.AllocSysString();
					graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &fontTitle, rect, &strFormat, &solidBrushD);
					::SysFreeString(bsTitle);
					// 画时间
					if(!rowInfo.strTime.IsEmpty())
					{
						BSTR bsTime = rowInfo.strTime.AllocSysString();
						graphics.DrawString(bsTime, (INT)wcslen(bsTime), &font, rectTime, &strFormatRight, &solidBrushD);
						::SysFreeString(bsTime);
					}
					// 画内容行
					if(!m_bSingleLine)
					{
						rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2);
						rect.Width = (Gdiplus::REAL)nWidth-20;
						rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4;
						BSTR bsContent = rowInfo.strContent.AllocSysString();
						graphics.DrawString(bsContent, (INT)wcslen(bsContent), &font, rect, &strFormat, &solidBrushD);
						::SysFreeString(bsContent);
					}
				}else
				{
					// 画标题行
					BSTR bsTitle = rowInfo.strTitle.AllocSysString();
					graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &fontTitle, 
						rect, &strFormat, rowInfo.bRowColor ? &solidBrushRow : &solidBrushT);
					::SysFreeString(bsTitle);
					// 画时间
					if(!rowInfo.strTime.IsEmpty())
					{
						BSTR bsTime = rowInfo.strTime.AllocSysString();
						graphics.DrawString(bsTime, (INT)wcslen(bsTime), &font, 
						rectTime, &strFormatRight, rowInfo.bRowColor ? &solidBrushRow : &solidBrush);
						::SysFreeString(bsTime);
					}
					// 画内容行
					if(!m_bSingleLine)
					{
						rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2);
						rect.Width = (Gdiplus::REAL)nWidth-20;
						rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4;
						BSTR bsContent = rowInfo.strContent.AllocSysString();
						graphics.DrawString(bsContent, (INT)wcslen(bsContent), &font, 
								rect, &strFormat, rowInfo.bRowColor ? &solidBrushRow : &solidBrush);
						::SysFreeString(bsContent);
					}
				}

				// 画分隔线(采用拉伸模式)
				if(m_pImageSeperator != NULL)
				{
					// 使用拉伸模式属性画图
					graphics.DrawImage(m_pImageSeperator, RectF(0, (Gdiplus::REAL)((nVI+1)*m_nRowHeight), (Gdiplus::REAL)(nWidth-2), (Gdiplus::REAL)m_sizeSeperator.cy),
							0, 0, (Gdiplus::REAL)m_sizeSeperator.cx, (Gdiplus::REAL)m_sizeSeperator.cy, UnitPixel);

					// 使用平铺方式填充矩形(暂不使用这种方式)
					//TextureBrush tileBrush(m_pImageSeperator, WrapModeTile);
					//graphics.FillRectangle(&tileBrush, RectF(0, (nVI+1)*m_nRowHeight, nWidth-2, m_sizeSeperator.cy));
				}else
				{
					// 未指定图片,则画矩形
					graphics.FillRectangle(&solidBrushS, 0, (nVI+1)*m_nRowHeight, nWidth-2, 1);
				}
			}
		}
	}

	// 输出到界面DC,使用与的方式合并背景
	dc.BitBlt(m_rc.left,m_rc.top, nWidth, m_rc.Height(), &m_memDC, 0, nYViewPos, SRCCOPY);//SRCAND);
}
Exemple #17
0
void CDrawWarn::Draw(CDC* pDC)
{
	ASSERT_VALID(this);
	CRect rect = m_position;
	rect.NormalizeRect();

	if(rect.Width() < 10 || rect.Height()<10)
		return;

	Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); 

	Color crBackColor,crTitleColor,crLineColor,crTextColor ;
	crBackColor.SetFromCOLORREF(m_ctlBackColor);
	crTitleColor.SetFromCOLORREF(m_ctlTitleColor );
	crLineColor.SetFromCOLORREF(m_ctlLineColor);
	crTextColor.SetFromCOLORREF(m_ctlTextColor);

	Graphics graphics (pDC->m_hDC);
	graphics.SetSmoothingMode (SmoothingModeHighSpeed);
	Graphics Textgraphics (pDC->m_hDC);
	SolidBrush  solidBrush(crBackColor);
	SolidBrush  TitleBrush(crTitleColor);
	SolidBrush  TextBrush(crTextColor);
	Pen pen(crLineColor,1);
	
	graphics.FillRectangle(&solidBrush,GdiRect);

        		BSTR bstr = m_fontName.AllocSysString();
///	BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName);
	FontFamily  fontFamily(bstr);
   	SysFreeString(bstr);
	Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint);

	for(int j =1; j<= m_nColCount; j++)
	{
		m_nCellWidth = 0;
		for(int i=1; i<= m_nRowCount; i++)
		{
			CRect rc = rect;
			if(m_bIsAutoSize)
			{
				m_nCellWidth = rect.Width()/m_nRowCount;
				m_nCellHeight = rect.Height()/m_nColCount;
				rc.TopLeft().x += (i-1)*m_nCellWidth;
				rc.TopLeft().y += (j-1)*m_nCellHeight;
				m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight));
				m_CellRect.NormalizeRect();
			}
			else
			{
				rc.TopLeft().x += m_nCellWidth;
				m_nCellWidth += rect.Width()*m_nPercent[i-1]/100;
				m_nCellHeight = rect.Height()/m_nColCount;
				rc.TopLeft().y += (j-1)*m_nCellHeight;	
				m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight));
				m_CellRect.NormalizeRect();
			}

			Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);

			graphics.DrawRectangle(&pen,CellRect);
			
			if(j == m_nColCount)	//画标题
			{
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft);
				stringFormat.SetTrimming(m_trimmingSyle);

				CString m_strButton;
				if(i == 1)
					m_strButton = "点号";
				if(i == 2)
					m_strButton = "数据";
				if(i == 3)
					m_strButton = "说明";
				if(i == 4)
					m_strButton = "报警原因";
				if(i == 5)
					m_strButton = "时间";

				m_strButton.TrimRight();
        		bstr = m_strButton.AllocSysString();
///				bstr = _com_util::ConvertStringToBSTR(m_strButton);
				RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);
				Matrix matrix(1,0,0,-1,0,0);
				Textgraphics.SetTransform(&matrix);
				
				theRect.Y *=-1;
				theRect.Height*=-1;
				Normallize (theRect);	
				Textgraphics.FillRectangle(&TitleBrush,theRect);
				Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush);
            	SysFreeString(bstr);
			}
			else 
			{					//画文字  m_CStrWarn      pStrWarn
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentNear);
				stringFormat.SetLineAlignment(StringAlignmentNear);

            	CString  strWarn;
/*				if(i == 1)
					strWarn = m_CStrWarn[j].strPoint;
				if(i == 2)
					strWarn = m_CStrWarn[j].strDate;
				if(i == 3)
					strWarn = m_CStrWarn[j].strTime;
				if(i == 4)
					strWarn = m_CStrWarn[j].strText;
				if(i == 5)
					strWarn = m_CStrWarn[j].strWarn;
*/
				strWarn.TrimRight();
        		bstr = strWarn.AllocSysString();
///				bstr = _com_util::ConvertStringToBSTR(strWarn);

				RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);
				Matrix matrix(1,0,0,-1,0,0);
				Textgraphics.SetTransform(&matrix);
				
				theRect.Y *=-1;
				theRect.Height*=-1;
				Normallize (theRect);	
				Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush);
             	SysFreeString(bstr);
			}			
		}
	}
	graphics.ReleaseHDC(pDC->m_hDC);
}
Exemple #18
0
void ASSISTANT::Text::Draw(CDC *pDC, float _zoomFactor, double dOffX, double dOffY)
{
   if (!visible) return;
   
   if (text.IsEmpty())
      return;

   Gdiplus::Graphics graphics(pDC->m_hDC);
   graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAliasGridFit);

   // Move and Scale
   graphics.TranslateTransform((Gdiplus::REAL)dOffX, (Gdiplus::REAL)dOffY);
   
   Gdiplus::Font gdipFont(pDC->m_hDC, &m_logFont);
   Gdiplus::FontFamily fontFamily;
   gdipFont.GetFamily(&fontFamily);

   int fontStyle = GetValidFontStyle(fontFamily);
   Gdiplus::REAL ascent = fontFamily.GetCellAscent(fontStyle) * 
                          (gdipFont.GetSize() / fontFamily.GetEmHeight(fontStyle));

   Gdiplus::PointF drawPoint;
   drawPoint.X = (Gdiplus::REAL)m_dX;
   drawPoint.Y = (Gdiplus::REAL)(m_dY - ascent);

   // convert text string to WCHAR format
   int iStringLength = text.GetLength();
   WCHAR *wcString = (WCHAR *)malloc((iStringLength+1)*sizeof(WCHAR)); // +1 for null termination
#ifdef _UNICODE
   wcscpy(wcString, text);
#else
   MultiByteToWideChar(CP_ACP, 0, text, iStringLength+1, 
                       wcString, iStringLength+1);
#endif

   // compute real text width
   Gdiplus::StringFormat measureStringFormat(Gdiplus::StringFormatFlagsMeasureTrailingSpaces);
   Gdiplus::RectF bbox;
   
   graphics.MeasureString(wcString, iStringLength, &gdipFont, Gdiplus::PointF(0.0, 0.0), &measureStringFormat, &bbox);

   Gdiplus::CharacterRange charRange(0, iStringLength);
   measureStringFormat.SetMeasurableCharacterRanges(1, &charRange);
   Gdiplus::Region pRangeRegion[1];
   graphics.MeasureCharacterRanges(wcString, iStringLength,
                                   &gdipFont, bbox, &measureStringFormat, 1, pRangeRegion);
   // get bounding rectangle
   Gdiplus::RectF rect;
   pRangeRegion[0].GetBounds(&rect, &graphics);

   Gdiplus::REAL realTextWidth = rect.Width;
   if (iStringLength > 1 && m_dWidth != 0 && realTextWidth != m_dWidth)
   {
      Gdiplus::REAL scaleX = (Gdiplus::REAL)(m_dWidth / realTextWidth);
      graphics.ScaleTransform(scaleX, 1.0);
      drawPoint.X = (Gdiplus::REAL)(m_dX / scaleX); //(x_*scaleX - x_);
   }
   // the text should begin at x, y
   drawPoint.X -= rect.X;

   graphics.ScaleTransform(_zoomFactor, _zoomFactor);

   Gdiplus::Color clrText(m_argbLineColor);
   Gdiplus::SolidBrush solidBrush(clrText);
   graphics.DrawString(wcString, iStringLength, &gdipFont, drawPoint, &measureStringFormat, &solidBrush);
   
   if (wcString)
      delete wcString;
}
void CDuiSlider::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{
		UpdateMemDC(dc, nWidth, nHeight * 4);

		Graphics graphics(m_memDC);

		// 画4个状态的内存图片
		for(int i = 0; i < 4; i++)
		{
			// 复制背景
			m_memDC.BitBlt(0, i * nHeight, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);

			int nPosY = i * nHeight;

			if(m_pImageForeGround != NULL)	// 使用背景和前景图片画进度条
			{
				if(m_pImageBackGround != NULL)	// 画背景
				{
					DrawImageFrameMID(graphics, m_pImageBackGround, CRect(0, nPosY + m_nThumbTop, nWidth, nPosY + m_nThumbTop + m_nSliderHeight),
						0, 0, m_sizeBackGround.cx, m_sizeBackGround.cy,
						m_nHeadLength, 0, m_nHeadLength, 0);
				}

				if(m_nProgress != 0)	// 画前景
				{
					DrawImageFrameMID(graphics, m_pImageForeGround, CRect(0, nPosY + m_nThumbTop, nWidth * m_nProgress / m_nMaxProgress, nPosY + m_nThumbTop + m_nSliderHeight),
						0, 0, m_sizeForeGround.cx, m_sizeForeGround.cy,
						m_nHeadLength, 0, m_nHeadLength, 0);
				}
			}else
			if(m_pImage != NULL)	// 使用单张图片画进度条
			{
				DrawImageFrame(graphics, m_pImage, CRect(0, nPosY + m_nThumbTop, nWidth, nPosY + m_nThumbTop + m_nSliderHeight), 
					0, 0, m_sizeImage.cx, m_sizeImage.cy, 2);

				if(m_nProgress != 0)
				{
					DrawImageFrame(graphics, m_pImage, CRect(0, nPosY + m_nThumbTop, nWidth * m_nProgress / m_nMaxProgress, nPosY + m_nThumbTop + m_nSliderHeight), 
						m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, 2);
				}
			}

			// 画滑块
			if(m_pImageThumb != NULL)
			{
				// 计算滑块的位置
				int nPos = (int)__max(m_rc.Width() * m_nProgress / m_nMaxProgress - m_nThumbWidth / 2, 0);
				nPos = (int)__min(nPos, m_rc.Width() - m_nThumbWidth);
				Rect rect(nPos, nPosY, m_nThumbWidth, m_nThumbHeight);
				graphics.DrawImage(m_pImageThumb, rect, i * m_sizeThumb.cx, 0, m_sizeThumb.cx, m_sizeThumb.cy, UnitPixel);
			}

			// 画进度文字
			if(m_bShowText)
			{
				BSTR bsFont = m_strFont.AllocSysString();
				FontFamily fontFamily(bsFont);
				Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
				::SysFreeString(bsFont);

				SolidBrush solidBrush(m_clrText);
				graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
				// 设置水平和垂直对齐方式
				DUI_STRING_ALIGN_DEFINE();
				strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);

				CString strText;
				// 只有最大值设置为100情况下才会显示百分号
				strText.Format(_T("%s%d%s"), m_strTitle, m_nProgress, (m_nMaxProgress == 100) ? _T("%") : _T(""));
				BSTR bsTitle = strText.AllocSysString();
				RectF rect((Gdiplus::REAL)(0), (Gdiplus::REAL)nPosY, (Gdiplus::REAL)nWidth, (Gdiplus::REAL)nHeight);
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
				::SysFreeString(bsTitle);
			}
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, 0, m_enButtonState * nHeight, SRCCOPY);
}
Exemple #20
0
// 曲线绘制.
void DataGrids::DrawCurve(void)
{

#define SHOW_LOWLEVEL 0

#define X(_x) UserX((_x)+xMarginLeft)
#define Y(_y) UserY((_y)+yMarginDown)

	WideString strList[] =
	{
		L"Vl(低电平电压)",
		L"Vh(高电平电压)",
		L"Tr(上升沿)",
		L"Th(高电平)",
		L"Tf(下降沿)",
		L"Tl(低电平)",
	};

	Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 0, 0, 255));
	Gdiplus::Pen pX(Gdiplus::Color(255, 0, 0, 0),1);
	Gdiplus::AdjustableArrowCap cap(8,6,true);
	Gdiplus::Font font(L"Times New Roman",8);
	Gdiplus::SolidBrush s( Gdiplus::Color(255, 0, 0, 0));
	Gdiplus::PointF *pComm = new Gdiplus::PointF[4];

	// 有上升.下降沿的斜坡.
	Gdiplus::Pen p(Gdiplus::Color(255, 0, 0, 255),2);
	//先将点计算好.
	Gdiplus::PointF *points = new Gdiplus::PointF[10];

	// 低电平位置为可用高度的 %20.
	// 高电平位置位可用高度的 %80.
	// 占空比位%50.
	// 上升沿/下降沿使用的%5的位置.
	// 低电平先开始.
	// 开始区域.(xMarkHeight + 20 , yMarksHeigh + 20).
	// 结束区域.(width - 20, heigh - 20).

	double fLvPos = 0.1 + 0.1 * m_fLRatio / 100, fHvPos = 0.4 + 0.4 * m_fHRatio/100, fHvLen = (m_fDuty*0.8/100.0), fLvLen = ((100-m_fDuty)*0.8/100), fRiseLen = 0.05,fFallLen= 0.05;
	double xMarginLeft = xMarkHeight + 30;
	double yMarginDown = yMarkHeight + 20;
	double xMarginRight  = 20;
	double yMarginTop  = 20;
	double RealWidth = m_iWidth - xMarginLeft - xMarginRight;
	double RealHeight = m_iHeight - yMarginDown - yMarginTop;
	int idx = 0;
	points[idx++] = Gdiplus::PointF((int)X(0),(int)Y(fLvPos * RealHeight));
	points[idx++] = Gdiplus::PointF((int)X(fHvLen * RealWidth),(int)Y(fLvPos * RealHeight));
	points[idx++] = Gdiplus::PointF((int)X((fHvLen + fRiseLen)* RealWidth),(int)Y(fHvPos * RealHeight));
	points[idx++] = Gdiplus::PointF((int)X((fHvLen + fRiseLen + fLvLen)* RealWidth),(int)Y(fHvPos * RealHeight));
	points[idx++] = Gdiplus::PointF((int)X((fHvLen + fRiseLen + fLvLen + fFallLen)* RealWidth),(int)Y(fLvPos * RealHeight));
	points[idx++] = Gdiplus::PointF((int)X(RealWidth),(int)Y(fLvPos * RealHeight));

	m_stGrp->DrawLines(&p,points,idx);

	//设置位虚线.
	pX.SetDashStyle(Gdiplus::DashStyleDash);
	pX.SetAlignment(Gdiplus::PenAlignmentCenter);
	pX.SetDashOffset(20.0);

	// P0 起点. P1 上升沿的起点. P2上升沿结束点. P3 下降沿起点. P4 下降沿的结束点. P5 结束点.
#if SHOW_LOWLEVEL
	pComm[0].X = (int)points[0].X;
	pComm[0].Y = (int)points[0].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(m_iHeight - yMarginTop);
	m_stGrp->DrawLines(&pX,pComm,2);
#endif

	pComm[0].X = (int)points[1].X;
	pComm[0].Y = (int)points[1].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(m_iHeight - yMarginTop);
	m_stGrp->DrawLines(&pX,pComm,2);

	pComm[0].X = (int)points[2].X;
	pComm[0].Y = (int)points[2].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(m_iHeight - yMarginTop - 35);
	m_stGrp->DrawLines(&pX,pComm,2);

	pComm[0].X = (int)points[3].X;
	pComm[0].Y = (int)points[3].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(m_iHeight - yMarginTop - 35);
	m_stGrp->DrawLines(&pX,pComm,2);

	pComm[0].X = (int)points[4].X;
	pComm[0].Y = (int)points[4].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(m_iHeight - yMarginTop);
	m_stGrp->DrawLines(&pX,pComm,2);

	// 准备画笔的箭头.
	cap.SetFillState(false);
	pX.SetCustomEndCap(&cap);
	pX.SetCustomStartCap(&cap);


	// Vl -- .P0~P1中点位置开始.到轴线上--双箭头.
	pComm[0].X = (int)(points[0].X + points[1].X) / 2;
	pComm[0].Y = (int)points[0].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(xAxisOffset);

	m_stGrp->DrawLines(&pX,pComm,2);
	m_stGrp->DrawString(strList[0].c_bstr(),strList[0].Length(),&font,Gdiplus::PointF(pComm[0].X + 10 ,(pComm[0].Y + pComm[1].Y)/2),&s);

	// Vh -- .P2~P3中点位置开始.到轴线上--双箭头.
	// 高电平线.
	pComm[0].X = (int)(points[2].X + points[3].X) / 2;
	pComm[0].Y = (int)points[2].Y;
	pComm[1].X = pComm[0].X;
	pComm[1].Y = UserY(xAxisOffset);
	m_stGrp->DrawLines(&pX,pComm,2);
	m_stGrp->DrawString(strList[1].c_bstr(),strList[1].Length(),&font,Gdiplus::PointF(pComm[0].X + 10 ,(pComm[0].Y + pComm[1].Y)/2),&s);

	//
#if SHOW_LOWLEVEL
	pComm[0].X =  points[0].X;
	pComm[0].Y =  UserY(m_iHeight - yMarginTop - 30);
	pComm[1].X =  points[1].X;
	pComm[1].Y =  UserY(m_iHeight - yMarginTop - 30);
	m_stGrp->DrawLines(&pX,pComm,2);
	m_stGrp->DrawString(strList[5].c_bstr(),strList[5].Length(),&font,Gdiplus::PointF((pComm[0].X + pComm[1].X)/2 -30 , pComm[0].Y + 10 ),&s);
#endif

	pComm[0].X =  points[1].X;
	pComm[0].Y =  UserY(m_iHeight - yMarginTop - 40);
	pComm[1].X =  points[2].X;
	pComm[1].Y =  UserY(m_iHeight - yMarginTop - 40);
	m_stGrp->DrawLines(&pX,pComm,2);
	m_stGrp->DrawString(strList[2].c_bstr(),strList[2].Length(),&font,Gdiplus::PointF(pComm[0].X + 5 , pComm[0].Y - 30 ),&s);

	pComm[2].X =  points[3].X;
	pComm[2].Y =  UserY(m_iHeight - yMarginTop - 40);
	pComm[3].X =  points[4].X;
	pComm[3].Y =  UserY(m_iHeight - yMarginTop - 40);
	m_stGrp->DrawLines(&pX,pComm+2,2);
	m_stGrp->DrawString(strList[4].c_bstr(),strList[4].Length(),&font,Gdiplus::PointF(pComm[2].X - 30 , pComm[2].Y - 20 ),&s);

	pComm[1].Y =  pComm[1].Y + 10;
	pComm[2].Y =  pComm[1].Y;
	m_stGrp->DrawLines(&pX,pComm+1,2);
	m_stGrp->DrawString(strList[3].c_bstr(),strList[3].Length(),&font,Gdiplus::PointF((pComm[1].X + pComm[2].X)/2 - 30, pComm[2].Y + 15 ),&s);

	delete points;
	delete pComm;
#undef X(_x)
#undef Y(_y)
}
Exemple #21
0
void CSkinDialog::DrawTitleBar(void){
	//获取窗体大小
	CRect rtWindow;
	GetWindowRect(&rtWindow);
	
	UINT btnHeight = m_bpBtnExt->GetHeight();
	UINT btnWidth = m_bpBtnExt->GetWidth();
	UINT border = GetSystemMetrics(SM_CXSIZEFRAME);

	//确定按钮位置
	m_rtBtnExt.right	= rtWindow.Width() - 5 - border;
	m_rtBtnExt.top		= (m_bpTitleBar->GetHeight() - btnHeight)/2 + border;
	m_rtBtnExt.left		= m_rtBtnExt.right - btnWidth;
	m_rtBtnExt.bottom	= m_rtBtnExt.top + btnHeight;

	m_rtBtnMax.right	= m_rtBtnExt.left - 2;
	m_rtBtnMax.top		= m_rtBtnExt.top;
	m_rtBtnMax.left		= m_rtBtnMax.right - btnWidth;
	m_rtBtnMax.bottom	= m_rtBtnExt.bottom;

	m_rtBtnMin.right	= m_rtBtnMax.left - 2;
	m_rtBtnMin.top		= m_rtBtnMax.top;
	m_rtBtnMin.left		= m_rtBtnMin.right - btnWidth;
	m_rtBtnMin.bottom	= m_rtBtnExt.bottom;

	//获取窗体DC
	CWindowDC WndDc(this);
	//创建Graphics对象
	Graphics graph(WndDc.m_hDC);

	//绘制边框
	TextureBrush Hbrush(m_bpHBorder); 
	Rect destTRect(0,0,rtWindow.Width(),border);
	graph.FillRectangle(&Hbrush,destTRect);
	Rect destBRect(0,rtWindow.Height()-border,rtWindow.Width(),border);
	graph.FillRectangle(&Hbrush,destBRect);

	TextureBrush Vbrush(m_bpVBorder);
	Rect destLRect(0,0,border,rtWindow.Height());
	graph.FillRectangle(&Vbrush,destLRect);
	Rect destRRect(rtWindow.Width()-border,0,border,rtWindow.Height());
	graph.FillRectangle(&Vbrush,destRRect);


	//绘制标题栏背景	
	graph.DrawImage(m_bpTitleBar,
					border,
					border,
					(int)(rtWindow.Width()-border),
					m_bpTitleBar->GetHeight());
	

	//!ToDo绘制程序图标
	WndDc.DrawIcon(2, 2, m_hIcon);

	//!ToDo绘制标题栏文字
	//设置字体
	FontFamily fontFamily(L"Arial");
	Font font(&fontFamily, 12, FontStyleBold, UnitPixel);
	//设置文字颜色
	SolidBrush solidBrush(Color(58, 58, 60));
	//位置
	PointF pointF(35.0f, 8.0f);
	//绘制文字
	graph.DrawString(m_strTitle,m_strTitle.GetLength(),&font,pointF,&solidBrush);

	//绘制退出按钮
	graph.DrawImage(m_bpBtnExt,m_rtBtnExt.left,m_rtBtnExt.top,m_bpBtnExt->GetWidth(),m_bpBtnExt->GetHeight());
	//绘制最大化/恢复按钮
	if(this->IsZoomed()){
		graph.DrawImage(m_bpBtnRes,m_rtBtnMax.left,m_rtBtnMax.top,m_bpBtnRes->GetWidth(),m_bpBtnRes->GetHeight());
	}else{
		graph.DrawImage(m_bpBtnMax,m_rtBtnMax.left,m_rtBtnMax.top,m_bpBtnMax->GetWidth(),m_bpBtnMax->GetHeight());
	}
	//绘制最小化按钮
	graph.DrawImage(m_bpBtnMin,m_rtBtnMin.left,m_rtBtnMin.top,m_bpBtnMin->GetWidth(),m_bpBtnMin->GetHeight());

}
Exemple #22
0
void CMenuItem::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

	if(!m_bUpdate)
	{
		int nImageCount = m_bSelect ? 6 : 4;
		if(m_nImagePicCount != 4)
		{
			// 如果修改过img-count属性,则用此属性设置的图片个数
			nImageCount = m_nImagePicCount;
		}
		if(m_bIsSeparator)
		{
			nImageCount = 1;
		}
		UpdateMemDC(dc, nWidth * nImageCount, nHeight);

		// 刷新图片的大小(因为m_bSelect选项有可能在SetBitmap之后有变化)
		if(m_pImage != NULL)
		{
			if(m_bIsPopup && (m_pImagePopupArrow == NULL))
			{
				m_sizeImage.SetSize(m_pImage->GetWidth() / 2, m_pImage->GetHeight());
			}else
			{
				m_sizeImage.SetSize(m_pImage->GetWidth() / nImageCount, m_pImage->GetHeight());
			}
		}

		Graphics graphics(m_memDC);
		CRect  rcTemp(0, 0, nWidth, nHeight);

		for(int i = 0; i < nImageCount; i++)
		{
			m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);

			if(enBSHover == i || (enBSDown == i && !m_bSelect) || enBSHoverDown == i)
			{
				// 画菜单项背景
				if(m_pImageHover != NULL)
				{
					// 使用拉伸模式属性画图
					graphics.DrawImage(m_pImageHover, RectF((Gdiplus::REAL)(i * nWidth+m_nFrameWidth), 0, (Gdiplus::REAL)(nWidth-m_nFrameWidth*2), (Gdiplus::REAL)nHeight),
							0, 0, (Gdiplus::REAL)m_sizeHover.cx, (Gdiplus::REAL)m_sizeHover.cy, UnitPixel);
				}else
				{
					// 使用颜色填充
					SolidBrush brush(m_clrHover);//Color(254, 71, 156, 235));
					graphics.FillRectangle(&brush, i * nWidth+m_nFrameWidth, 0, nWidth-m_nFrameWidth*2, nHeight);
				}
				
			}

			if(m_pImage != NULL)
			{
				if(m_bIsSeparator)
				{
					// 如果是分隔线,则采用平铺方式画图
					TextureBrush tileBrush(m_pImage, WrapModeTile);
					graphics.FillRectangle(&tileBrush, RectF((Gdiplus::REAL)rcTemp.left, (Gdiplus::REAL)(rcTemp.top + (nHeight - m_sizeImage.cy) / 2), (Gdiplus::REAL)(nWidth-m_nFrameWidth*2), (Gdiplus::REAL)m_sizeImage.cy));
				}else
				if(m_bIsPopup && (m_pImagePopupArrow == NULL))
				{
					// 如果是弹出菜单,并且没有设置菜单的箭头图片,则用菜单图片作为右侧的箭头图片
					graphics.DrawImage(m_pImage, Rect(rcTemp.right - m_sizeImage.cx - 6, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy),
						(i % 2) * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
				}else
				{
					// 普通菜单项的图片
					graphics.DrawImage(m_pImage, Rect(rcTemp.left + (m_nLeft - m_sizeImage.cx) / 2, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy),
						i * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel);
				}
			}

			// 如果是弹出菜单,并且设置了菜单的箭头图片,则画右侧的箭头图片
			if(m_bIsPopup && (m_pImagePopupArrow != NULL))
			{
				graphics.DrawImage(m_pImagePopupArrow, Rect(rcTemp.right - m_sizePopupArrow.cx - 6, rcTemp.top + (nHeight - m_sizePopupArrow.cy) / 2, m_sizePopupArrow.cx, m_sizePopupArrow.cy),
					(i % 2) * m_sizePopupArrow.cx, 0, m_sizePopupArrow.cx, m_sizePopupArrow.cy, UnitPixel);
			}

			rcTemp.OffsetRect(nWidth, 0);
		}
		
		if(!m_strTitle.IsEmpty())
		{
			m_memDC.SetBkMode(TRANSPARENT);

			rcTemp.SetRect(0, 0, nWidth, nHeight);

			BSTR bsFont = m_strFont.AllocSysString();
			FontFamily fontFamily(bsFont);
			Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
			graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
			::SysFreeString(bsFont);

			StringFormat strFormat;
			strFormat.SetAlignment(StringAlignmentNear);
			strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
			Size size = GetTextBounds(font, strFormat, m_strTitle);
			CPoint point = GetOriginPoint(nWidth - m_nLeft, nHeight, size.Width, size.Height, m_uAlignment, m_uVAlignment);

			for(int i = 0; i < nImageCount; i++)
			{
				SolidBrush solidBrush(enBSDisable == i ? Color(254, 128, 128, 128) : (enBSHover == i || (enBSDown == i && !m_bSelect) || enBSHoverDown == i ? Color(254, 255, 255, 255) : Color(254, 56, 56, 56)));

				RectF rect((Gdiplus::REAL)(m_nLeft + point.x + i * nWidth), (Gdiplus::REAL)point.y, (Gdiplus::REAL)(nWidth - (m_nLeft + point.x)), (Gdiplus::REAL)size.Height);
				BSTR bsTitle = m_strTitle.AllocSysString();
				graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
				::SysFreeString(bsTitle);
			}
		}
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY);
}
Exemple #23
0
void CDrawWarn::Draw(CDC* pDC)
{
	ASSERT_VALID(this);
	CRect rect = m_position;
	rect.NormalizeRect();

	if(rect.Width() < 10 || rect.Height()<10)
		return;

	pStrWarn = new STRWARN[m_nColCount];
	AddWarn("1","2004/12/12","12:00","高报警","电压过低");
	AddWarn("2","2004/12/12","12:00","高报警","电压过低");
	AddWarn("3","2004/12/12","12:00","高报警","电压过低");
	AddWarn("4","2004/12/12","12:00","高报警","电压过低");
	AddWarn("5","2004/12/12","12:00","高报警","电压过低");
	AddWarn("6","2004/12/12","12:00","高报警","电压过低");
	AddWarn("7","2004/12/12","12:00","高报警","电压过低");
	AddWarn("8","2004/12/12","12:00","高报警","电压过低");
	AddWarn("9","2004/12/12","12:00","高报警","电压过低");
	AddWarn("10","2004/12/12","12:00","高报警","电压过低");
	AddWarn("11","2004/12/12","12:00","高报警","电压过低");
	AddWarn("12","2004/12/12","12:00","高报警","电压过低");

	Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); 

	Color crBackColor,crTitleColor,crLineColor,crTextColor ;
	crBackColor.SetFromCOLORREF(m_ctlBackColor);
	crTitleColor.SetFromCOLORREF(m_ctlTitleColor );
	crLineColor.SetFromCOLORREF(m_ctlLineColor);
	crTextColor.SetFromCOLORREF(m_ctlTextColor);

	Graphics graphics (pDC->m_hDC);
	Graphics Textgraphics (pDC->m_hDC);
	SolidBrush  solidBrush(crBackColor);
	SolidBrush  TitleBrush(crTitleColor);
	SolidBrush  TextBrush(crTextColor);
	Pen pen(crLineColor,1);
	
	graphics.FillRectangle(&solidBrush,GdiRect);

	BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName);
///	WCHAR *fn = new unsigned short[m_fontName.GetLength()+1];;
///	wcscpy(fn,bstr);
				
	FontFamily  fontFamily(bstr);
	Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint);

	for(int j =1; j<= m_nColCount; j++)
	{
		m_nCellWidth = 0;
		for(int i=1; i<= m_nRowCount; i++)
		{
			CRect rc = rect;
			if(m_bIsAutoSize)
			{
				m_nCellWidth = rect.Width()/m_nRowCount;
				m_nCellHeight = rect.Height()/m_nColCount;
				rc.TopLeft().x += (i-1)*m_nCellWidth;
				rc.TopLeft().y += (j-1)*m_nCellHeight;
				m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight));
				m_CellRect.NormalizeRect();
			}
			else
			{
				rc.TopLeft().x += m_nCellWidth;
				m_nCellWidth += rect.Width()*m_nPercent[i-1]/100;
				m_nCellHeight = rect.Height()/m_nColCount;
				rc.TopLeft().y += (j-1)*m_nCellHeight;	
				m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight));
				m_CellRect.NormalizeRect();
				
			}

			Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);

			graphics.DrawRectangle(&pen,CellRect);
			
			if(j == m_nColCount)	//画标题
			{
				
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft);
				stringFormat.SetTrimming(m_trimmingSyle);

				CString m_strButton;
				if(i == 1)
					m_strButton = "点号";
				if(i == 2)
					m_strButton = "数据";
				if(i == 3)
					m_strButton = "说明";
				if(i == 4)
					m_strButton = "报警原因";
				if(i == 5)
					m_strButton = "时间";

				m_strButton.TrimRight();
///				int len = m_strButton.GetLength();
				bstr = _com_util::ConvertStringToBSTR(m_strButton);
///				WCHAR *strButton = new unsigned short[len];
///				wcscpy(strButton,bstr);
				RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);
				Matrix matrix(1,0,0,-1,0,0);
				Textgraphics.SetTransform(&matrix);
				
				theRect.Y *=-1;
				theRect.Height*=-1;
				Normallize (theRect);	
				Textgraphics.FillRectangle(&TitleBrush,theRect);
				Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush);
			}
			else					//画文字
			{
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentNear);
				stringFormat.SetLineAlignment(StringAlignmentNear);

				CString strWarn;
				if(i == 1)
					strWarn = pStrWarn[j].strPoint;
				if(i == 2)
					strWarn = pStrWarn[j].strDate;
				if(i == 3)
					strWarn = pStrWarn[j].strTime;
				if(i == 4)
					strWarn = pStrWarn[j].strText;
				if(i == 5)
					strWarn = pStrWarn[j].strWarn;

				strWarn.TrimRight();
///				int len = strWarn.GetLength();
				bstr = _com_util::ConvertStringToBSTR(strWarn);
///				WCHAR *strButton = new unsigned short[len];
///				wcscpy(strButton,bstr);
				RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy);
				Matrix matrix(1,0,0,-1,0,0);
				Textgraphics.SetTransform(&matrix);
				
				theRect.Y *=-1;
				theRect.Height*=-1;
				Normallize (theRect);	
				Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush);
			}
		}
	}
	graphics.ReleaseHDC(pDC->m_hDC);
}