Exemple #1
1
BOOL CToolTipWnd::PopupTipWnd(LPPOINT ptCur, LPCTSTR lpszText)
{
	if(!IsWindow(GetSafeHwnd()))
	{
		if(!Create(m_pParentWnd))
			return FALSE;
	}

	if(m_uTimerID	!= 0)
	{
		KillTimer(m_uTimerID);
		m_uTimerID = 0;
	}
	
	m_strCurTipText = lpszText;
	m_uTimerID = SetTimer(nTimerID,1000,NULL);
	if(m_uTimerID != 0)
	{
		ASSERT_VALID(m_pParentWnd);
		CPoint ptPos = *ptCur;
		m_pParentWnd->ClientToScreen(&ptPos);

		CDC *pDC = GetDC();
		ASSERT(pDC != NULL);
		CFont *pOldFont = (CFont *)pDC->SelectStockObject(DEFAULT_GUI_FONT);
		CRect rcTemp(0,0,0,0);
		int nHeight = pDC->DrawText(m_strCurTipText,&rcTemp,DT_LEFT|DT_SINGLELINE|DT_CALCRECT);
		pDC->SelectObject(pOldFont);
		ReleaseDC(pDC);

		int nWidth = rcTemp.Width() + 8;
		nHeight += 8;

		SetWindowPos(&wndTop,ptPos.x,ptPos.y,nWidth,nHeight,SWP_SHOWWINDOW|SWP_NOCOPYBITS|SWP_NOACTIVATE|SWP_NOZORDER);

		return TRUE;
	}
	else
	{
		ShowWindow(SW_HIDE);
		return FALSE;
	}
}
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 PngButton::ShowBtnTask(CRect& rc)
{
    CRect rcTemp(&m_rcWnd);
    //GetWindowRect(&rcTemp);
    MoveWindow(rc.left, rc.top, rcTemp.Width(), rcTemp.Height());
    DrawBtn();
    ShowWindow(SW_SHOWNOACTIVATE);
}
Exemple #4
0
bool wxToolBoxItem::HitTest(wxPoint pt)
{
	bool bHit(false);
	wxRect rcTemp(0,0,0,0);	
	if(m_ParentTab)
	{
		rcTemp = m_Rectangle;
		rcTemp.y += m_ParentTab->GetItemArea().y;				
		bHit = rcTemp.Contains(pt);
	}
	else
	{
		bHit = m_Rectangle.Contains(pt);
	}
	return bHit;
}
Exemple #5
0
void wxToolBoxItem::Invalidate()
{	
	if(m_Parent)
	{
		if(m_ParentTab)
		{
			wxRect rcTemp(m_Rectangle);			
			rcTemp.y += m_ParentTab->GetItemArea().y;
			rcTemp.Inflate(1,1);
			m_Parent->RefreshRect(rcTemp);
		}
		else
		{
			m_Parent->RefreshRect(m_Rectangle);
		}
	}
}
// 画Area控件的半透明层
void CDuiVisionDesignerView::DrawAreaControl(CDC &dc, CRect rcArea, COLORREF clr, int nBeginTransparent, int nEndTransparent)
{
	CRect  rcTemp(0, 0, rcArea.Width(), rcArea.Height());

	CDC TempDC;
	TempDC.CreateCompatibleDC(&dc);

	CBitmap memBmpTemp;
	memBmpTemp.CreateCompatibleBitmap(&dc, rcArea.Width(), rcArea.Height());
	CBitmap *pOldmap =  TempDC.SelectObject(&memBmpTemp);

	TempDC.FillSolidRect(&rcTemp, clr);		

	DrawVerticalTransition(dc, TempDC, rcArea, rcArea, nBeginTransparent, nEndTransparent);
	
	TempDC.SelectObject(pOldmap);
	memBmpTemp.DeleteObject();
	TempDC.DeleteDC();
}
Exemple #7
0
void CArea::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	int nHeight = m_rc.Height();

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

		CRect  rcTemp(0, 0, nWidth, nHeight);

		CDC TempDC;
		TempDC.CreateCompatibleDC(&dc);

		CBitmap memBmpTemp;
		memBmpTemp.CreateCompatibleBitmap(&dc, nWidth, nHeight);
		CBitmap *pOldmap =  TempDC.SelectObject(&memBmpTemp);

		m_memDC.BitBlt(0, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY);
		TempDC.FillSolidRect(&rcTemp, m_clr);		

		if(m_nTransparentType == TRANSPARENT_VERTICAL)
		{
			DrawVerticalTransition(m_memDC, TempDC, rcTemp, rcTemp, m_nBeginTransparent, m_nEndTransparent);
		}else
		if(m_nTransparentType == TRANSPARENT_HORIZONTAL)
		{
			DrawHorizontalTransition(m_memDC, TempDC, rcTemp, rcTemp, m_nBeginTransparent, m_nEndTransparent);
		}
		
		TempDC.SelectObject(pOldmap);
		memBmpTemp.DeleteObject();
		TempDC.DeleteDC();
	}

	dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, 0, 0, SRCCOPY);
}
Exemple #8
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 #9
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);
}
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(&ps);
		std::wstring wstrDraw = L"To Be No.One!哈哈,加油!";
		HFONT hfont = ::CreateFont(
			30,               // height of font
			0,                // average character width
			0,           // angle of escapement
			0,          // base-line orientation angle
			FW_BOLD,              // font weight
			0,           // italic attribute option
			0,        // underline attribute option
			0,        // strikeout attribute option
			OEM_CHARSET,          // character set identifier
			OUT_DEFAULT_PRECIS,  // output precision
			CLIP_DEFAULT_PRECIS,    // clipping precision
			ANTIALIASED_QUALITY,          // output quality
			DEFAULT_PITCH,   // pitch and family
			_T("Arial")           // typeface name
			);
		::SelectObject(hdc, hfont);

		//文字透明输出,不修改背景
		::SetBkMode(hdc, TRANSPARENT);

//方式1
		//绘制背景,也就是包边的颜色
		::SetTextColor(hdc, RGB(2,2,2));
		for(int i = -1; i < 2; ++i)
		{
			for (int j = -1; j < 2; ++j)
			{
				CRect rc;
				GetClientRect(&rc);
				rc.OffsetRect(i, j);
				::DrawText(hdc, wstrDraw.c_str(), wstrDraw.length(), rc, DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
			}
		}

		//绘制前景
		::SetTextColor(hdc, RGB(255, 255, 49));
		CRect rc;
		GetClientRect(&rc);
		::DrawText(hdc, wstrDraw.c_str(), wstrDraw.length(), rc, DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);

//方式2
		LOGFONT lf = {0};
		HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
		::GetObject((HANDLE)hFont ,sizeof(LOGFONT) ,&lf);
		lf.lfHeight = 16;
		HFONT hhfont = ::CreateFontIndirect(&lf);
		::SelectObject(hdc, hhfont);

		//测试截断文字,必须不能有DT_NOCLIP,该参数会导致绘制文本超出设定区域
		CRect rcOrigin = CRect(100, 30, 175, 50);
		//背景色
		::SetTextColor(hdc, RGB(255, 2, 2));
		int nXExcursion[8]={1, 1, 1, 0, -1, -1, -1, 0};
		int nYExcursion[8]={-1, 0, 1, 1, 1, 0, -1, -1};
		for (int i = 0; i < 8; i++)
		{
			CRect rcTemp(rcOrigin.left, rcOrigin.top, rcOrigin.right, rcOrigin.bottom);
			rcTemp.OffsetRect(nXExcursion[i], nYExcursion[i]);
			DrawText(hdc, wstrDraw.c_str(), wstrDraw.length(), rcTemp, DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
		}
		::SetTextColor(hdc, RGB(0, 255, 0));
		//DT_NOCLIP 前景色
		::DrawText(hdc, wstrDraw.c_str(), wstrDraw.length(), rcOrigin, DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
		EndPaint(&ps);
		return TRUE;
	}
Exemple #11
0
// 画控件
void CDuiTabCtrl::DrawControl(CDC &dc, CRect rcUpdate)
{
	int nWidth = m_rc.Width();
	//int nHeight = m_rc.Height();	// 纵向内存DC的高度是整个tabctrl的高度,不只是页签部分高度
	int nTabHeight = m_nTabCtrlHeight;	// 纵向内存DC高度改为tabctrl部分高度

	if(!m_bUpdate)
	{
		// 创建内存DC,纵向分为6层:
		// 1.tab页签图片-原图
		// 2.tab页签图片-鼠标热点
		// 3.tab页签图片-鼠标按下
		// 4,5,6层是上面3层的备份
		UpdateMemDC(dc, nWidth, nTabHeight * 3 * 2);

		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 );

		// 设置tab页签文字的水平和垂直对齐方式
		DUI_STRING_ALIGN_DEFINE();
		strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
		
		// 画内存DC的3个层的内容
		for(int i = 0; i < 3; i++)
		{
			// 将背景内容拷贝到内存DC
			m_memDC.BitBlt(0, i * nTabHeight, nWidth, nTabHeight, &dc, m_rc.left, m_rc.top, SRCCOPY);

			// 画tab页签
			int nXPos = m_nTabLeftPading;
			int nYPos = i * nTabHeight;
			for(size_t j = 0; j < m_vecItemInfo.size(); j++)
			{
				TabItemInfo &itemInfo = m_vecItemInfo.at(j);
				
				if(!itemInfo.bVisible)
				{
					continue;
				}

				// 图片位置(根据对齐方式进行计算)
				CPoint point = GetOriginPoint(m_nTabItemWidth, m_nTabCtrlHeight, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy,
						GetGDIAlignment(m_uAlignment), GetGDIVAlignment(m_uVAlignment));
				// 如果有图片和文字,则图片的垂直对齐按照上对齐方式
				if(!itemInfo.strText.IsEmpty())
				{
					point.y = 0;
				}

				// 画tab页签底图
				if(itemInfo.pImage != NULL)	// 如果页签设置了图片,则使用tab页签指定的图片
				{
					int nImageIndex = i;
					if(itemInfo.nImageCount == 1)
					{
						nImageIndex = 0;
					}
					graphics.DrawImage(itemInfo.pImage, Rect(nXPos + point.x, nYPos + point.y,  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图片的索引图片
				{
					if(m_enTabImageMode == enTIMNormal)	// 普通模式
					{
						graphics.DrawImage(m_pImage, Rect(nXPos + point.x, nYPos + point.y,  itemInfo.sizeImage.cx, itemInfo.sizeImage.cy),
							itemInfo.sizeImage.cx * itemInfo.nImageIndex, 0, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy, UnitPixel);
					}else
					if(m_enTabImageMode == enTIMMID)	// 九宫格模式
					{
						CRect rcTemp(nXPos, nYPos, nXPos+m_nTabItemWidth, nYPos+m_nTabCtrlHeight);
						DrawImageFrameMID(graphics, m_pImage, rcTemp, m_sizeImage.cx * i, 0, m_sizeImage.cx, m_sizeImage.cy,
							m_nWLT, m_nHLT, m_nWRB, m_nHRB);
					}
				}

				// 画tab页签热点图(如果存在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);
				}

				// 画tab页签文字
				if(!itemInfo.strText.IsEmpty())
				{
					// 设置页签文字颜色
					SolidBrush solidBrushItem(m_clrText);
					if((m_nHoverItem == j) && (m_clrTextHover.GetValue() != Color(0, 0, 0, 0).GetValue()))	// 设置了鼠标移动颜色,则使用
					{
						solidBrushItem.SetColor(m_clrTextHover);
					}else
					if((m_nDownItem == j) && (m_clrTextDown.GetValue() != Color(0, 0, 0, 0).GetValue()))	// 设置了鼠标按下颜色,则使用
					{
						solidBrushItem.SetColor(m_clrTextDown);
					}

					RectF rectText((Gdiplus::REAL)nXPos,
							(Gdiplus::REAL)(nYPos + itemInfo.sizeImage.cy + 1),
							(Gdiplus::REAL)((m_pImageTabBtn != NULL) ? (itemInfo.rc.Width()-m_sizeTabBtn.cx) : 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;
					}

					// 计算是否需要显示tip
					itemInfo.bNeedTextTip = rectText.Width < GetTextBounds(font, itemInfo.strText).Width;

					BSTR bsText = itemInfo.strText.AllocSysString();
					graphics.DrawString(bsText, (INT)wcslen(bsText), &font, rectText, &strFormat, &solidBrushItem);
					::SysFreeString(bsText);
				}

				nXPos += itemInfo.rc.Width();

				// 画tab页签之间的分隔图片(采用拉伸方式)
				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复制一份进行备份
		m_memDC.BitBlt(0, nTabHeight * 3, nWidth, nTabHeight * 3, &m_memDC, 0, 0, SRCCOPY);
	}

	// 画Tab页签按钮到内存dc
	if(m_pImageTabBtn != NULL)
	{
		// 现将备份的内存dc整体进行恢复,避免页签按钮叠加之后的影响
		m_memDC.BitBlt(0, 0, nWidth, nTabHeight * 3, &m_memDC, 0, nTabHeight * 3, SRCCOPY);

		Graphics graphics(m_memDC);
		for(int i = 0; i < 3; i++)
		{
			for(size_t j = 0; j < m_vecItemInfo.size(); j++)
			{
				TabItemInfo &itemInfo = m_vecItemInfo.at(j);
				graphics.DrawImage(m_pImageTabBtn,
					RectF((Gdiplus::REAL)itemInfo.rcButton.left, (Gdiplus::REAL)(nTabHeight * i + itemInfo.rcButton.top),
					(Gdiplus::REAL)itemInfo.rcButton.Width(), (Gdiplus::REAL)itemInfo.rcButton.Height()),
					(Gdiplus::REAL)(itemInfo.buttonState * m_sizeTabBtn.cx), 0,
					(Gdiplus::REAL)m_sizeTabBtn.cx, (Gdiplus::REAL)m_sizeTabBtn.cy,
					UnitPixel); 
			}
		}
	}

	// 内存dc输出到dc
	// 1.画原图
	dc.BitBlt(m_rc.left,m_rc.top, nWidth, nTabHeight, &m_memDC, 0, 0, SRCCOPY);

	// 2.画鼠标热点的Tab页签
	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 + nTabHeight, SRCCOPY);
	}

	// 3.画鼠标按下的Tab页签
	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 + nTabHeight * 2, SRCCOPY);
	}
}
void CWndShadow::Update(HWND hParent)
{
	//int ShadSize = 5;
	//int Multi = 100 / ShadSize;

	RECT WndRect;
	GetWindowRect(hParent, &WndRect);
	int nShadWndWid = 0;
	int nShadWndHei = 0;
	if(m_pShadowImage != NULL)
	{
		// 九宫格方式,计算阴影窗口总的宽度和高度
		nShadWndWid = WndRect.right - WndRect.left + m_nShadowWLT + m_nShadowWRB;
		nShadWndHei = WndRect.bottom - WndRect.top + m_nShadowHLT + m_nShadowHRB;
	}else
	{
		// 算法阴影方式,计算阴影窗口总的宽度和高度
		nShadWndWid = WndRect.right - WndRect.left + m_nSize * 2;
		nShadWndHei = WndRect.bottom - WndRect.top + m_nSize * 2;
	}

	// Create the alpha blending bitmap
	BITMAPINFO bmi;        // bitmap header

	ZeroMemory(&bmi, sizeof(BITMAPINFO));
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth = nShadWndWid;
	bmi.bmiHeader.biHeight = nShadWndHei;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biBitCount = 32;         // four 8-bit components
	bmi.bmiHeader.biCompression = BI_RGB;
	bmi.bmiHeader.biSizeImage = nShadWndWid * nShadWndHei * 4;

	BYTE *pvBits;          // pointer to DIB section
	HBITMAP hbitmap = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void **)&pvBits, NULL, 0);
	HDC hMemDC = CreateCompatibleDC(NULL);
	HBITMAP hOriBmp = (HBITMAP)SelectObject(hMemDC, hbitmap);

	if(m_pShadowImage != NULL)
	{
		// 九宫格方式画阴影图片
		Graphics graphics(hMemDC);
		CRect rcTemp(0, 0, nShadWndWid, nShadWndHei);
		DrawImageFrameMID(graphics, m_pShadowImage, rcTemp,
			0, 0, m_pShadowImage->GetWidth(), m_pShadowImage->GetHeight(),
			m_nShadowWLT, m_nShadowHLT, m_nShadowWRB+1, m_nShadowHRB+1);
	}else
	{
		// 画算法阴影
		ZeroMemory(pvBits, bmi.bmiHeader.biSizeImage);
		MakeShadow((UINT32 *)pvBits, hParent, &WndRect);
	}

	// 计算阴影窗口偏移位置
	POINT ptDst;  
    if(m_pShadowImage != NULL)  
    {
        ptDst.x = WndRect.left - m_nShadowWLT;  
        ptDst.y = WndRect.top - m_nShadowHLT;  
    }  
    else  
    {  
        ptDst.x = WndRect.left + m_nxOffset - m_nSize;  
        ptDst.y = WndRect.top + m_nyOffset - m_nSize;  
    }

	POINT ptSrc = {0, 0};
	SIZE WndSize = {nShadWndWid, nShadWndHei};
	BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };

	MoveWindow(m_hWnd, ptDst.x, ptDst.y, nShadWndWid, nShadWndHei, FALSE);

	BOOL bRet= s_UpdateLayeredWindow(m_hWnd, NULL, &ptDst, &WndSize, hMemDC,
		&ptSrc, 0, &blendPixelFunction, ULW_ALPHA);

	_ASSERT(bRet); // something was wrong....

	// Delete used resources
	SelectObject(hMemDC, hOriBmp);
	DeleteObject(hbitmap);
	DeleteDC(hMemDC);

}
void CLibraryAlbumTrack::Paint(CLibraryAlbumView* pView, CDC* pDC, const CRect& rcTrack, int nCount)
{
	COLORREF crBack = m_bSelected ? Colors.m_crHighlight : CLibraryAlbumView::m_crRows[ nCount & 1 ];

	pDC->SetBkColor( crBack );
	pDC->SetTextColor( m_bSelected ? Colors.m_crHiText : Colors.m_crText );

	CRect rcLine( &rcTrack );
	rcLine.DeflateRect( 2, 1 );

	// Icon Box

	CRect rcTemp( rcLine.left, rcLine.top, rcLine.left + ICON_WIDTH, rcLine.bottom );
	rcLine.left += ICON_WIDTH;

	if ( nCount >= 0 )
		PaintText( pDC, rcTemp, 0, 100, NULL );

	ShellIcons.Draw( pDC, m_nShell, 16, rcTemp.left + 4,
		( rcTemp.top + rcTemp.bottom ) / 2 - 8, CLR_NONE, m_bSelected );

	// Rating Stars Box

	rcTemp.SetRect( rcLine.right - RATING_WIDTH, rcLine.top, rcLine.right, rcLine.bottom );
	rcLine.right -= RATING_WIDTH;

	CPoint ptStar( rcTemp.left + 4, ( rcTemp.top + rcTemp.bottom ) / 2 - 6 );
	PaintText( pDC, rcTemp, 0, 100, NULL, TRUE );

	if ( pView->m_pRating == this && m_nSetRating < 7 )
	{
		for ( int nRating = 2 ; nRating <= 6 ; nRating++ )
		{
			ImageList_DrawEx( pView->m_pStars, m_nSetRating >= nRating ? 2 : 1,
				*pDC, ptStar.x, ptStar.y, 12, 12,
				m_bSelected ? CLR_NONE : crBack, crBack,
				m_nSetRating >= nRating ? ILD_NORMAL : ILD_BLEND50 );
			ptStar.x += 12;
		}
	}
	else
	{
		for ( int nRating = 2 ; nRating <= 6 ; nRating++ )
		{
			ImageList_DrawEx( pView->m_pStars, m_nRating >= nRating ? 0 : 1,
				*pDC, ptStar.x, ptStar.y, 12, 12,
				m_bSelected ? CLR_NONE : crBack, crBack,
				m_nRating >= nRating ? ILD_NORMAL : ILD_BLEND50 );
			ptStar.x += 12;
		}
	}

	ptStar.x++;	// Comment icon gap

	if ( pView->m_pRating == this && m_nSetRating == 7 )
	{
		ImageList_DrawEx( pView->m_pStars, 5,
			*pDC, ptStar.x, ptStar.y, 12, 12, CLR_NONE, crBack, ILD_NORMAL );
	}
	else
	{
		ImageList_DrawEx( pView->m_pStars, m_bComments ? 3 : 4,
			*pDC, ptStar.x, ptStar.y, 12, 12,
			m_bSelected ? CLR_NONE : crBack, crBack,
			m_bComments ? ILD_NORMAL : ILD_BLEND50 );
	}

	// Metadata Boxes  (Available space %)

	if ( pView->m_pStyle == CSchema::uriMusicAlbum )
	{
		// Track, Title, Length, Bitrate
		PaintText( pDC, rcLine, 0, 5, &m_sTrack, TRUE );
		PaintText( pDC, rcLine, 5, 84, &m_sTitle );
		PaintText( pDC, rcLine, 84, 92, &m_sLength, TRUE );
		PaintText( pDC, rcLine, 92, 100, &m_sBitrate, TRUE );
	}
	else if ( pView->m_pStyle == CSchema::uriMusicArtist )
	{
		// Album, Title, Length, Bitrate
		PaintText( pDC, rcLine, 0, 30, &m_sAlbum );
		PaintText( pDC, rcLine, 30, 84, &m_sTitle );
		PaintText( pDC, rcLine, 84, 92, &m_sLength, TRUE );
		PaintText( pDC, rcLine, 92, 100, &m_sBitrate, TRUE );
	}
	else if ( pView->m_pStyle == CSchema::uriMusicAll ) // Genre
	{
		// Artist, Album, Title, Length, Bitrate
		PaintText( pDC, rcLine, 0, 25, &m_sArtist );
		PaintText( pDC, rcLine, 25, 50, &m_sAlbum );
		PaintText( pDC, rcLine, 50, 84, &m_sTitle );
		PaintText( pDC, rcLine, 84, 92, &m_sLength, TRUE );
		PaintText( pDC, rcLine, 92, 100, &m_sBitrate, TRUE );
	}
	else // Non-music
	{
		// Title, Artist, Length
		PaintText( pDC, rcLine,  0, 66, &m_sTitle );
		PaintText( pDC, rcLine, 66, 88, &m_sArtist );
		PaintText( pDC, rcLine, 88, 100, &m_sLength, TRUE );
	}
}
void CLibraryAlbumTrack::Paint(CLibraryAlbumView* pView, CDC* pDC, const CRect& rcTrack, int nCount)
{
	COLORREF crBack1 = CLibraryAlbumView::m_crRows[ nCount & 1 ];
	COLORREF crBack2 = m_bSelected ? CoolInterface.m_crHighlight : crBack1;
	
	CRect rcLine( &rcTrack );
	rcLine.DeflateRect( 1, 1 );
	rcLine.left ++; rcLine.right --;
	
	CRect rcTemp( rcLine.left, rcLine.top, rcLine.left + 22, rcLine.bottom );
	rcLine.left += 22;
	
	pDC->SetBkColor( m_bSelected ? crBack2 : crBack1 );
	
	ShellIcons.Draw( pDC, m_nShell, 16, rcTemp.left + 3,
		( rcTemp.top + rcTemp.bottom ) / 2 - 8, CLR_NONE, m_bSelected );
	
	pDC->SetTextColor( m_bSelected ? CoolInterface.m_crHiText : CoolInterface.m_crText );
	
	rcTemp.SetRect( rcLine.right - 78, rcLine.top, rcLine.right, rcLine.bottom );
	rcLine.right -= 78;
	
	CPoint ptStar( rcTemp.left + 3, ( rcTemp.top + rcTemp.bottom ) / 2 - 6 );
	PaintText( pDC, rcTemp, 0, 100, NULL );
	
	if ( pView->m_pRating == this && m_nSetRating < 7 )
	{
		for ( int nRating = 2 ; nRating <= 6 ; nRating++ )
		{
			ImageList_DrawEx( pView->m_pStars, m_nSetRating >= nRating ? 2 : 1,
				*pDC, ptStar.x, ptStar.y, 12, 12, crBack2, crBack2,
				m_nSetRating >= nRating ? ILD_NORMAL : ILD_BLEND50 );
			ptStar.x += 12;
		}
	}
	else
	{
		for ( int nRating = 2 ; nRating <= 6 ; nRating++ )
		{
			ImageList_DrawEx( pView->m_pStars, m_nRating >= nRating ? 0 : 1,
				*pDC, ptStar.x, ptStar.y, 12, 12, crBack2, crBack2,
				m_nRating >= nRating ? ILD_NORMAL : ILD_BLEND50 );
			ptStar.x += 12;
		}
	}
	
	if ( pView->m_pRating == this && m_nSetRating == 7 )
	{
		ImageList_DrawEx( pView->m_pStars, 5,
			*pDC, ptStar.x, ptStar.y, 12, 12, crBack2, crBack2, ILD_NORMAL );
	}
	else
	{
		ImageList_DrawEx( pView->m_pStars, m_bComments ? 3 : 4,
			*pDC, ptStar.x, ptStar.y, 12, 12, crBack2, crBack2,
			m_bComments ? ILD_NORMAL : ILD_BLEND50 );
	}
	
	if ( pView->m_pStyle == CSchema::uriMusicAlbum )
	{
		// Track, Title, Length, Bitrate
		PaintText( pDC, rcLine, 0, 5, &m_sTrack, TRUE );
		PaintText( pDC, rcLine, 5, 84, &m_sTitle );
		PaintText( pDC, rcLine, 84, 92, &m_sLength, TRUE );
		PaintText( pDC, rcLine, 92, 100, &m_sBitrate, TRUE );
	}
	else if ( pView->m_pStyle == CSchema::uriMusicArtist )
	{
		// Album, Title, Length, Bitrate
		PaintText( pDC, rcLine, 0, 30, &m_sAlbum );
		PaintText( pDC, rcLine, 30, 84, &m_sTitle );
		PaintText( pDC, rcLine, 84, 92, &m_sLength, TRUE );
		PaintText( pDC, rcLine, 92, 100, &m_sBitrate, TRUE );
	}
	else
	{
		// Artist, Album, Title, Length, Bitrate
		PaintText( pDC, rcLine, 0, 25, &m_sArtist );
		PaintText( pDC, rcLine, 25, 50, &m_sAlbum );
		PaintText( pDC, rcLine, 50, 84, &m_sTitle );
		PaintText( pDC, rcLine, 84, 92, &m_sLength, TRUE );
		PaintText( pDC, rcLine, 92, 100, &m_sBitrate, TRUE );
	}
}