コード例 #1
0
ファイル: SkinComboBox.cpp プロジェクト: HuugY/MFC_Project
void CSkinComboBox::OnPaint()
{
	CPaintDC dc(this);

	CRect rcClient;
	GetClientRect(&rcClient);

	CMemoryDC MemDC(&dc,rcClient);

	CRect rcArrow;
	HRGN hRgn2 = NULL;
	if (m_lpArrowImgN != NULL && !m_lpArrowImgN->IsNull())
	{
		int cxIcon = m_nArrowWidth;
		int cyIcon = m_lpArrowImgN->GetHeight();

		CalcCenterRect(rcClient, cxIcon, cyIcon, rcArrow);
		rcArrow.right = rcClient.right - 2;
		rcArrow.left = rcArrow.right - cxIcon;
	}

	DrawParentWndBg(GetSafeHwnd(),MemDC->GetSafeHdc());

	if (m_bHover)
	{
		if (m_lpBgImgH != NULL && !m_lpBgImgH->IsNull())
		{
			m_lpBgImgH->Draw(&MemDC, rcClient);
		}
		else
		{
			if (m_lpBgImgN != NULL && !m_lpBgImgN->IsNull())
				m_lpBgImgN->Draw(&MemDC, rcClient);
		}
	}
	else
	{
		if (m_lpBgImgN != NULL && !m_lpBgImgN->IsNull())
			m_lpBgImgN->Draw(&MemDC, rcClient);
	}

	if (m_bArrowPress)
	{
		if (m_lpArrowImgP != NULL && !m_lpArrowImgP->IsNull())
			m_lpArrowImgP->Draw(&MemDC, rcArrow);
	}
	else if (m_bArrowHover)
	{
		if (m_lpArrowImgH != NULL && !m_lpArrowImgH->IsNull())
			m_lpArrowImgH->Draw(&MemDC, rcArrow);
	}
	else
	{
		if (m_lpArrowImgN != NULL && !m_lpArrowImgN->IsNull())
			m_lpArrowImgN->Draw(&MemDC, rcArrow);
	}

	//绘制边框
	m_SkinComboBoxList.DrawListFrame();
}
コード例 #2
0
ファイル: FaceCtrl.cpp プロジェクト: hjhong/MyDuiLib
void CFaceCtrl::DrawZoomImage(HDC hDC)
{
	COLORREF clrBg = m_dwBackColor;
	if (clrBg > 0xFF000000)
		clrBg -= 0xFF000000;

	HPEN hPen = ::CreatePen(PS_SOLID, 1, m_clrZoomBorder);
	HBRUSH hBrush = ::CreateSolidBrush(clrBg);
	HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
	HBRUSH hOldBrush = (HBRUSH)::SelectObject(hDC, hBrush);
	::Rectangle(hDC, m_rcZoomImg.left, m_rcZoomImg.top, m_rcZoomImg.right, m_rcZoomImg.bottom);
	::SelectObject(hDC, hOldBrush);
	::SelectObject(hDC, hOldPen);
	::DeleteObject(hBrush);
	::DeleteObject(hPen);

	if (m_nHoverIndex >= 0 && m_nHoverIndex < (int)m_arrImage.size())
	{
		CGifImage * lpImage = m_arrImage[m_nHoverIndex];
		if (lpImage != NULL)
		{
			RECT rcZoomImg;
			CalcCenterRect(m_rcZoomImg, lpImage->GetWidth(),
				lpImage->GetHeight(), rcZoomImg);
			lpImage->Draw(hDC, rcZoomImg, m_nFramePos);
		}
	}
}
コード例 #3
0
ファイル: FaceCtrl.cpp プロジェクト: hjhong/MyDuiLib
void CFaceCtrl::PaintStatusImage(HDC hDC)
{
	RECT rcItem, rcImage;
	int nRow = 0, nCol = 0;
	int nLeft = m_rcItem.left, nTop = m_rcItem.top;
	for (int i = 0; i < (int)m_arrImage.size(); i++)
	{
		::SetRect(&rcItem, nLeft, nTop, nLeft + m_nItemWidth, nTop + m_nItemHeight);

		CGifImage * lpImage = m_arrImage[i];
		if (lpImage != NULL)
		{
			CalcCenterRect(rcItem, lpImage->GetWidth(), lpImage->GetHeight(), rcImage);
			lpImage->Draw(hDC, rcImage, 0);
		}

		if (m_nHoverIndex == i)
			DrawFocusBorder(hDC, rcItem);

		nLeft += m_nItemWidth;
		nCol++;
		if (nCol >= m_nCol)
		{
			nCol = 0;
			nRow++;
			if (nRow > m_nRow)
				break;
			nLeft = m_rcItem.left;
			nTop += m_nItemHeight;
		}
	}

	if (m_nHoverIndex != -1)
		DrawZoomImage(hDC);
}
コード例 #4
0
ファイル: MyEdit.cpp プロジェクト: xiaoyiqingz/newwindow
void CMyEdit::GetIconRect(RECT &rcIcon)
{
	CRect rcWindow;
	GetWindowRect(&rcWindow);

	CalcCenterRect(rcWindow, m_nIconWidth, rcWindow.Height(), rcIcon);
	rcIcon.right = rcWindow.right - 2;
	rcIcon.left = rcIcon.right - m_nIconWidth;
}
コード例 #5
0
ファイル: MyEdit.cpp プロジェクト: xiaoyiqingz/newwindow
void CMyEdit::OnNcPaint()
{
	CRect rcWindow;
	GetWindowRect(&rcWindow);

	CRect rcClient;
	GetClientRect(&rcClient);

	ClientToScreen(&rcClient);
	rcClient.OffsetRect(-rcWindow.left, -rcWindow.top);

	rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top);

	CDC *pWindowDC = GetWindowDC();
	CMemoryDC MemDC(pWindowDC,rcWindow);

	CRect rcIcon;
	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
	{
		int cxIcon = m_pIconImg->GetWidth();
		int cyIcon = m_pIconImg->GetHeight();

		CalcCenterRect(rcWindow, cxIcon, cyIcon, rcIcon);
		rcIcon.right = rcWindow.right - 2;
		rcIcon.left = rcIcon.right - cxIcon;
	}

	DrawParentWndBg(GetSafeHwnd(),MemDC.GetSafeHdc());

	if (m_bHover)
	{
		if (m_pBackImgH != NULL && !m_pBackImgH->IsNull())
		{
			m_pBackImgH->Draw(&MemDC, rcWindow);
		}
		else
		{
			if (m_pBackImgN != NULL && !m_pBackImgN->IsNull())
				m_pBackImgN->Draw(&MemDC, rcWindow);
		}
	}
	else
	{
		if (m_pBackImgN != NULL && !m_pBackImgN->IsNull())
			m_pBackImgN->Draw(&MemDC, rcWindow);
	}

	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
		m_pIconImg->Draw(&MemDC, rcIcon);

	pWindowDC->BitBlt(rcWindow.left,rcWindow.top,rcWindow.Width(),rcWindow.Height(),&MemDC,0,0,SRCCOPY);

	ReleaseDC(pWindowDC);
}
コード例 #6
0
ファイル: SkinEdit.cpp プロジェクト: HuugY/MFC_Project
void CSkinEdit::OnNcPaint()
{
	CRect rcWindow;
	GetWindowRect(&rcWindow);
	rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top);

	CDC *pWindowDC = GetWindowDC();

	CRect rcIcon;
	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
	{
		int cxIcon = m_pIconImg->GetWidth();
		int cyIcon = m_pIconImg->GetHeight();

		CalcCenterRect(rcWindow, cxIcon, cyIcon, rcIcon);
		rcIcon.right = rcWindow.right - 2;
		rcIcon.left = rcIcon.right - cxIcon;
	}

	//pWindowDC->FillSolidRect(&rcWindow,m_colBack);
	//DrawParentWndBg(GetSafeHwnd(),pWindowDC->GetSafeHdc());

	//不要刷新整个客户区,客户区因为有字符串的缘故,当拉伸窗口时,非客户区和客户区两者因为刷新不同步,会造成客户区文字闪烁
	RenderEngine->DrawRect(pWindowDC->GetSafeHdc(),rcWindow,3,m_colBack);

	if (m_bHover)
	{
		if (m_pBackImgH != NULL && !m_pBackImgH->IsNull())
		{
			m_pBackImgH->DrawFrame(pWindowDC, rcWindow);
		}
		else
		{
			if (m_pBackImgN != NULL && !m_pBackImgN->IsNull())
				m_pBackImgN->DrawFrame(pWindowDC, rcWindow);
		}
	}
	else
	{
 		if (m_pBackImgN != NULL && !m_pBackImgN->IsNull())
		{
			m_pBackImgN->DrawFrame(pWindowDC, rcWindow);
		}
	}

	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
	{
		//图标填充一下背景,防止未能刷新留下尾巴
		pWindowDC->FillSolidRect(&rcIcon,m_colBack);
		m_pIconImg->Draw(pWindowDC, rcIcon);
	}

	ReleaseDC(pWindowDC);
}
コード例 #7
0
ファイル: FaceCtrl.cpp プロジェクト: 03050903/MingQQ
void CFaceCtrl::OnPaint(CDCHandle dc)
{
	CPaintDC PaintDC(m_hWnd);
	
	CRect rcClient;
	GetClientRect(&rcClient);

	CMemoryDC MemDC(PaintDC.m_hDC, rcClient);

	MemDC.FillSolidRect(&rcClient, m_clrBg);

	DrawLine(MemDC.m_hDC);

	CRect rcItem, rcImage;
	int nRow = 0, nCol = 0;
	int nLeft = 0, nTop = 0;
	for (int i = 0; i < (int)m_arrImage.size(); i++)
	{
		rcItem = CRect(nLeft, nTop, nLeft+m_nItemWidth, nTop+m_nItemHeight);
		
		CGifImage * lpImage = m_arrImage[i];
		if (lpImage != NULL)
		{
			CalcCenterRect(rcItem, lpImage->GetWidth(), lpImage->GetHeight(), rcImage);
			lpImage->Draw(MemDC.m_hDC, rcImage, 0);
		}

		if (m_nHoverIndex == i)
			DrawFocusBorder(MemDC.m_hDC, rcItem);

		nLeft += m_nItemWidth;
		nCol++;
		if (nCol >= m_nCol)
		{
			nCol = 0;
			nRow++;
			if (nRow > m_nRow)
				break;
			nLeft = 0;
			nTop += m_nItemHeight;
		}
	}

	if (m_nHoverIndex != -1)
		DrawZoomImage(MemDC.m_hDC);
}
コード例 #8
0
void CCreateSyncDIr::OnInitButton()
{
	CRect rcClient, rcCenter;
	GetClientRect(&rcClient);

	CalcCenterRect(rcClient, 360, 244, rcCenter);

	m_btCreate.SetBackImage(_T("res\\bt_create.png"),_T("res\\bt_create.png"),
		_T("res\\bt_create.png"),_T("res\\bt_create.png"), CRect(3,3,3,3));
	m_btCreate.SetButtonType(BT_PUSHBUTTON);
	m_btCreate.SetParentBack(GetBackDC());

	m_gbArea.SetItemSize(360, 244);
	m_gbArea.SetBackImage(_T("res\\bt_createdir.png"));
	m_gbArea.SetParentBack(GetBackDC());
	m_gbArea.MoveWindow(&rcCenter);
}
コード例 #9
0
ファイル: MyButtonEx.cpp プロジェクト: xiaoyiqingz/newwindow
void CMyButtonEx::DrawMenuButton(CDC* pDC,RECT &rcClient)
{
	if (m_bPress)
	{
		if (m_pBackImgD != NULL && !m_pBackImgD->IsNull())
			m_pBackImgD->DrawImage(pDC, rcClient);
	}
	else if (m_bHover)
	{
		if (m_pBackImgH != NULL && !m_pBackImgH->IsNull())
			m_pBackImgH->DrawImage(pDC, rcClient);
	}

	CRect rcMenu(0, 0, 0, 0);

	if (m_pMenuImg != NULL && !m_pMenuImg->IsNull())
	{
		int cx = m_pMenuImg->GetWidth();
		int cy = m_pMenuImg->GetHeight();
		int x = rcClient.right - 3 - cx;
		int y = (rcClient.bottom-rcClient.top - cy + 1) / 2;
		rcMenu = CRect(x, y, x+cx, y+cy);
		m_pMenuImg->DrawImage(pDC, rcMenu);
	}

	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
	{
		int cx = m_pIconImg->GetWidth();
		int cy = m_pIconImg->GetHeight();

		int nRight;
		if (rcMenu.left > 0)
			nRight = rcMenu.left;
		else
			nRight = rcClient.right;

		CRect rcIcon(rcClient.left, rcClient.top, nRight, rcClient.bottom);
		CalcCenterRect(rcIcon, cx, cy, rcIcon);

		if (m_bPress)
			rcIcon.OffsetRect(1, 1);
		m_pIconImg->DrawImage(pDC, rcIcon);
	}
}
コード例 #10
0
ファイル: SkinTabCtrl.cpp プロジェクト: HuugY/MFC_Project
void CSkinTabCtrl::DrawItem(CDC*pDC, int nIndex)
{
	CSkinTabCtrlItem * lpItem = GetItemByIndex(nIndex);
	if (NULL == lpItem) return;

	CRect rcItem;
	GetItemRectByIndex(nIndex, rcItem);

	if (m_nSelIndex == nIndex)
	{
		if (lpItem->m_lpBgImgD != NULL && !lpItem->m_lpBgImgD->IsNull())
			lpItem->m_lpBgImgD->Draw(pDC, rcItem);
		else if (m_lpItemBgImgD != NULL && !m_lpItemBgImgD->IsNull())
			m_lpItemBgImgD->Draw(pDC, rcItem);
	}
	else if (m_nHoverIndex == nIndex)
	{
		if (lpItem->m_lpBgImgH != NULL && !lpItem->m_lpBgImgH->IsNull())
			lpItem->m_lpBgImgH->Draw(pDC, rcItem);
		else if (m_lpItemBgImgH != NULL && !m_lpItemBgImgH->IsNull())
			m_lpItemBgImgH->Draw(pDC, rcItem);
	}
	else
	{
		if (lpItem->m_lpBgImgN != NULL && !lpItem->m_lpBgImgN->IsNull())
			lpItem->m_lpBgImgN->Draw(pDC, rcItem);
		else if (m_lpItemBgImgN != NULL && !m_lpItemBgImgN->IsNull())
			m_lpItemBgImgN->Draw(pDC, rcItem);
	}

	CImageEx * lpIconImg = NULL;

	if (m_nSelIndex == nIndex)
		lpIconImg = lpItem->m_lpSelIconImg;
	else
		lpIconImg = lpItem->m_lpIconImg;

	BOOL bHasText = FALSE;
	if (lpItem->m_strText.GetLength() > 0)
		bHasText = TRUE;

	BOOL bHasIcon = FALSE;
	if (lpIconImg != NULL && !lpIconImg->IsNull())
		bHasIcon = TRUE;

	if (bHasIcon && bHasText)	// 带图标和文字
	{
		int cxIcon = lpIconImg->GetWidth();
		int cyIcon = lpIconImg->GetHeight();

		int nMode = pDC->SetBkMode(TRANSPARENT);
		pDC->SelectObject(GetCtrlFont());
		pDC->SetTextColor(m_colNormalText);

		CRect rcText(0,0,0,0);	// 计算文字宽高
		pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, DT_SINGLELINE | DT_CALCRECT);

		int cx = cxIcon+1+rcText.Width();
		int cy = cyIcon;

		CRect rcCenter;
		CalcCenterRect(rcItem, cx, cy, rcCenter);

		CRect rcIcon(rcCenter.left, rcCenter.top, rcCenter.left+cxIcon, rcCenter.bottom);
		lpIconImg->Draw(pDC, rcIcon);

		UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;
		rcText = CRect(rcIcon.right+1, rcItem.top, rcIcon.right+1+rcText.Width(), rcItem.bottom);
		pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, nFormat);

		pDC->SetBkMode(nMode);
	}
	else if (bHasIcon)	// 仅图标
	{
		int cxIcon = lpIconImg->GetWidth();
		int cyIcon = lpIconImg->GetHeight();

		CRect rcIcon;
		CalcCenterRect(rcItem, cxIcon, cyIcon, rcIcon);

		lpIconImg->Draw(pDC, rcIcon);
	}
	else if (bHasText)	// 仅文字
	{
		UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;

		int nMode = pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(m_colNormalText);
		pDC->SelectObject(GetCtrlFont());

		pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcItem, nFormat);
		pDC->SetBkMode(nMode);
	}

	if (m_nSelIndex == nIndex)
	{
		if (lpItem->m_dwStyle & STCI_STYLE_DROPDOWN)
		{
			CRect rcArrow;
			rcArrow.left = rcItem.left+lpItem->m_nLeftWidth;
			rcArrow.top = rcItem.top;
			rcArrow.bottom = rcItem.bottom;
			rcArrow.right = rcArrow.left + lpItem->m_nRightWidth;

			if (m_bPressArrow)
			{
				if (lpItem->m_lpArrowImgD != NULL && !lpItem->m_lpArrowImgD->IsNull())
					lpItem->m_lpArrowImgD->Draw(pDC, rcArrow);
				else if (m_lpArrowImgD != NULL && !m_lpArrowImgD->IsNull())
					m_lpArrowImgD->Draw(pDC, rcArrow);
			}
			else if (m_nHoverIndex == nIndex)
			{
				if (lpItem->m_lpArrowImgH != NULL && !lpItem->m_lpArrowImgH->IsNull())
					lpItem->m_lpArrowImgH->Draw(pDC, rcArrow);
				else if (m_lpArrowImgH != NULL && !m_lpArrowImgH->IsNull())
					m_lpArrowImgH->Draw(pDC, rcArrow);
			}
		}
	}
}
コード例 #11
0
ファイル: MyButtonEx.cpp プロジェクト: xiaoyiqingz/newwindow
void CMyButtonEx::DrawIconButton(CDC* pDC,RECT &rcClient)
{
	if (m_bPress)
	{
		if (m_pBackImgD != NULL && !m_pBackImgD->IsNull())
			m_pBackImgD->Draw(pDC, rcClient);
	} else if (m_bHover) {
		if (m_pBackImgH != NULL && !m_pBackImgH->IsNull())
			m_pBackImgH->Draw(pDC, rcClient);
	}

	if (m_bPress)
		::OffsetRect(&rcClient,1, 1);

	CString strText;
	GetWindowText(strText);

	BOOL bHasText = FALSE;
	if (strText.GetLength() > 0)
		bHasText = TRUE;

	BOOL bHasIcon = FALSE;
	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
		bHasIcon = TRUE;

	if (bHasIcon && bHasText)	// ´øͼ±êºÍÎÄ×Ö
	{
		int cxIcon = m_pIconImg->GetWidth();
		int cyIcon = m_pIconImg->GetHeight();

		int nMode = pDC->SetBkMode(TRANSPARENT);
		CFont *pFont = GetFont();
		CFont *pOldFont = pDC->SelectObject(pFont);

		CRect rcText(0,0,0,0);	// ¼ÆËãÎÄ×Ö¿í¸ß
		pDC->DrawText(strText, &rcText, DT_SINGLELINE | DT_CALCRECT);

		int cx = cxIcon+3+rcText.Width();
		int cy = cyIcon;

		CRect rcCenter;
		CalcCenterRect(rcClient, cx, cy, rcCenter);

		CRect rcIcon(rcCenter.left, rcCenter.top, rcCenter.left+cxIcon, rcCenter.bottom);
		m_pIconImg->DrawImage(pDC, rcIcon);

		UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;
		rcText = CRect(rcIcon.right+3, rcClient.top, rcIcon.right+3+rcText.Width(), rcClient.bottom);
		pDC->DrawText(strText, &rcText, nFormat);

		pDC->SelectObject(pOldFont);
		pDC->SetBkMode(nMode);	
	}
	else if (bHasIcon)
	{
		int cxIcon = m_pIconImg->GetWidth();
		int cyIcon = m_pIconImg->GetHeight();

		CRect rcIcon;
		CalcCenterRect(rcClient, cxIcon, cyIcon, rcIcon);

		m_pIconImg->DrawImage(pDC, rcIcon);
	}
	else if (bHasText)
	{
		CRect rcText(rcClient);
		rcText.left += 2;
		rcText.right -= 2;

		UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;

		int nMode = pDC->SetBkMode(TRANSPARENT);
		CFont *pFont = GetFont();
		CFont *pOldFont = pDC->SelectObject(pFont);
		pDC->DrawText(strText, &rcText, nFormat);
		pDC->SelectObject(pOldFont);
		pDC->SetBkMode(nMode);	
	}
}
コード例 #12
0
ファイル: MyButtonEx.cpp プロジェクト: xiaoyiqingz/newwindow
void CMyButtonEx::DrawPushButton(CDC* pDC,RECT &rcClient)
{
	if (m_bPress)		// Êó±ê×ó¼ü°´ÏÂ״̬
	{
		if (m_pBackImgD != NULL && !m_pBackImgD->IsNull())
			m_pBackImgD->DrawImage(pDC, rcClient);
	}
	else if (m_bHover)	// Êó±êÐüͣ״̬
	{
		if (m_pBackImgH != NULL && !m_pBackImgH->IsNull())
			m_pBackImgH->DrawImage(pDC, rcClient);
	}
	else if (m_bFocus)	// ½¹µã״̬
	{
		if (m_pBackImgF != NULL && !m_pBackImgF->IsNull())
			m_pBackImgF->DrawImage(pDC, rcClient);
	}
	else				// ÆÕͨ״̬
	{
		if (m_pBackImgN != NULL && !m_pBackImgN->IsNull())
			m_pBackImgN->DrawImage(pDC, rcClient);
	}

	if (m_bPress)
		::OffsetRect(&rcClient,1, 1);

	CString strText;
	GetWindowText(strText);

	BOOL bHasText = FALSE;
	if (strText.GetLength() > 0)
		bHasText = TRUE;

	BOOL bHasIcon = FALSE;
	if (m_pIconImg != NULL && !m_pIconImg->IsNull())
		bHasIcon = TRUE;

	if (bHasIcon && bHasText)	// ´øͼ±êºÍÎÄ×Ö
	{
		int cxIcon = m_pIconImg->GetWidth();
		int cyIcon = m_pIconImg->GetHeight();

		int nMode = pDC->SetBkMode(TRANSPARENT);

		CFont *pFont = GetFont();
		CFont *pOldFont = pDC->SelectObject(pFont);

		CRect rcText(0,0,0,0);	// ¼ÆËãÎÄ×Ö¿í¸ß
		pDC->DrawText(strText, &rcText, DT_SINGLELINE | DT_CALCRECT);

		int cx = cxIcon+3+rcText.Width();
		int cy = cyIcon;

		CRect rcCenter;
		CalcCenterRect(rcClient, cx, cy, rcCenter);

		CRect rcIcon(rcCenter.left, rcCenter.top, rcCenter.left+cxIcon, rcCenter.bottom);
		m_pIconImg->DrawImage(pDC, rcIcon);

		UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;
		rcText = CRect(rcIcon.right+3, rcClient.top, rcIcon.right+3+rcText.Width(), rcClient.bottom);
		pDC->DrawText(strText, &rcText, nFormat);

		pDC->SelectObject(pOldFont);
		pDC->SetBkMode(nMode);
	}
	else if (bHasIcon)	// ½öͼ±ê
	{
		int cxIcon = m_pIconImg->GetWidth();
		int cyIcon = m_pIconImg->GetHeight();

		CRect rcIcon;
		CalcCenterRect(rcClient, cxIcon, cyIcon, rcIcon);

		m_pIconImg->DrawImage(pDC, rcIcon);
	}
	else if (bHasText)	// ½öÎÄ×Ö
	{
		UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;

		int nMode = pDC->SetBkMode(TRANSPARENT);
		CFont *pFont = GetFont();
		CFont *pOldFont = pDC->SelectObject(pFont);
		pDC->DrawText(strText, &rcClient, nFormat);
		pDC->SelectObject(pOldFont);
		pDC->SetBkMode(nMode);
	}
	/*if (m_bPress) {
		m_pBackImg.Draw(pDC->GetSafeHdc(), rcClient, CRect(108, 0, 144, 31));  //3
	} else if (m_bFocus) {
		m_pBackImg.Draw(pDC->GetSafeHdc(), rcClient, CRect(36, 0, 72, 31));   //2
	} else if (m_bHover) {
		m_pBackImg.Draw(pDC->GetSafeHdc(), rcClient, CRect(72, 0, 108, 31));  //4
	} else {
		m_pBackImg.Draw(pDC->GetSafeHdc(), rcClient, CRect(36, 0, 72, 31));	  //2
	}*/
}
コード例 #13
0
ファイル: SkinPictureBox.cpp プロジェクト: janseM3319/mingqq
void CSkinPictureBox::OnPaint(CDCHandle dc)
{
	CPaintDC PaintDC(m_hWnd);

	CRect rcClient;
	GetClientRect(&rcClient);

	CMemoryDC MemDC(PaintDC.m_hDC, rcClient);

	if (m_bTransparent)
		DrawParentWndBg(MemDC.m_hDC);

	int nMode = ::SetStretchBltMode(MemDC.m_hDC, HALFTONE);
	if (m_lpImage != NULL && !m_lpImage->IsNull())
	{
		if (DRAW_MODE_CENTER == m_nDrawMode)
		{
			int cx = m_lpImage->GetWidth();
			int cy = m_lpImage->GetHeight();

			CRect rcCenter;
			CalcCenterRect(rcClient, cx, cy, rcCenter);

			m_lpImage->Draw(MemDC.m_hDC, rcCenter);
		}
		else if (DRAW_MODE_STRETCH == m_nDrawMode)
		{
			m_lpImage->Draw(MemDC.m_hDC, rcClient);
		}
	}
	else if (m_lpGifImage != NULL)
	{
		if (DRAW_MODE_CENTER == m_nDrawMode)
		{
			int cx = m_lpGifImage->GetWidth();
			int cy = m_lpGifImage->GetHeight();

			CRect rcCenter;
			CalcCenterRect(rcClient, cx, cy, rcCenter);

			m_lpGifImage->Draw(MemDC.m_hDC, rcCenter);
		}
		else if (DRAW_MODE_STRETCH == m_nDrawMode)
		{
			m_lpGifImage->Draw(MemDC.m_hDC, rcClient);
		}
	}
	::SetStretchBltMode(MemDC.m_hDC, nMode);

	if (m_bPress)	// 鼠标左键按下状态
	{
		if (m_lpBgImgD != NULL && !m_lpBgImgD->IsNull())
			m_lpBgImgD->Draw(MemDC.m_hDC, rcClient);
	}
	else if (m_bHover)	// 鼠标悬停状态
	{
		if (m_lpBgImgH != NULL && !m_lpBgImgH->IsNull())
			m_lpBgImgH->Draw(MemDC.m_hDC, rcClient);
	}
	else	// 普通状态
	{
		if (m_lpBgImgN != NULL && !m_lpBgImgN->IsNull())
			m_lpBgImgN->Draw(MemDC.m_hDC, rcClient);
	}
}
コード例 #14
0
ファイル: SkinToolBar.cpp プロジェクト: HuugY/MFC_Project
void CSkinToolBar::DrawItem(CDC*pDC, int nIndex)
{
    CSkinToolBarItem * lpItem = GetItemByIndex(nIndex);
    if (NULL == lpItem)
        return;

    CRect rcItem;
    GetItemRectByIndex(nIndex, rcItem);

    CRect rcLeft, rcRight;
    if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN
            || lpItem->m_dwStyle & STBI_STYLE_WHOLEDROPDOWN)
    {
        rcLeft = rcItem;
        rcLeft.right = rcLeft.left + lpItem->m_nLeftWidth;

        rcRight = rcItem;
        rcRight.left += lpItem->m_nLeftWidth;
        rcRight.right = rcRight.left + lpItem->m_nRightWidth;
    }

    if (lpItem->m_dwStyle & STBI_STYLE_SEPARTOR)
    {
        if (lpItem->m_lpSepartorImg != NULL && !lpItem->m_lpSepartorImg->IsNull())
            lpItem->m_lpSepartorImg->Draw(pDC, rcItem);
        return;
    }

    if ((lpItem->m_dwStyle & STBI_STYLE_CHECK) && lpItem->m_bChecked)
    {
        if (lpItem->m_lpBgImgD != NULL && !lpItem->m_lpBgImgD->IsNull())
            lpItem->m_lpBgImgD->Draw(pDC, rcItem);

        rcItem.OffsetRect(1, 1);

        if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN)
        {
            if (lpItem->m_lpLeftD != NULL && !lpItem->m_lpLeftD->IsNull())
                lpItem->m_lpLeftD->Draw(pDC, rcLeft);
            rcLeft.OffsetRect(1, 1);
        }

        if (m_nPressIndex == nIndex)
        {
            if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN)
            {
                if (!m_bPressLorR)
                {
                    if (lpItem->m_lpRightD != NULL && !lpItem->m_lpRightD->IsNull())
                        lpItem->m_lpRightD->Draw(pDC, rcRight);

                    rcRight.OffsetRect(1, 1);
                }
            }
        }
        else if (m_nHoverIndex == nIndex)
        {
            if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN)
            {
                if (!m_bHoverLorR)
                {
                    if (lpItem->m_lpRightH != NULL && !lpItem->m_lpRightH->IsNull())
                        lpItem->m_lpRightH->Draw(pDC, rcRight);
                }
            }
        }
    }
    else
    {
        if (m_nPressIndex == nIndex)
        {
            if (lpItem->m_lpBgImgD != NULL && !lpItem->m_lpBgImgD->IsNull())
                lpItem->m_lpBgImgD->Draw(pDC, rcItem);

            if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN)
            {
                if (m_bPressLorR)
                {
                    if (lpItem->m_lpLeftD != NULL && !lpItem->m_lpLeftD->IsNull())
                        lpItem->m_lpLeftD->Draw(pDC, rcLeft);
                }
                else
                {
                    if (lpItem->m_lpRightD != NULL && !lpItem->m_lpRightD->IsNull())
                        lpItem->m_lpRightD->Draw(pDC, rcRight);
                }
            }

            rcItem.OffsetRect(1, 1);

            if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN
                    || lpItem->m_dwStyle & STBI_STYLE_WHOLEDROPDOWN)
            {
                if (m_bPressLorR)
                    rcLeft.OffsetRect(1, 1);
                else
                    rcRight.OffsetRect(1, 1);
            }
        }
        else if (m_nHoverIndex == nIndex)
        {
            if (lpItem->m_lpBgImgH != NULL && !lpItem->m_lpBgImgH->IsNull())
                lpItem->m_lpBgImgH->Draw(pDC, rcItem);

            if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN)
            {
                if (m_bHoverLorR)
                {
                    if (lpItem->m_lpLeftH != NULL && !lpItem->m_lpLeftH->IsNull())
                        lpItem->m_lpLeftH->Draw(pDC, rcLeft);
                }
                else
                {
                    if (lpItem->m_lpRightH != NULL && !lpItem->m_lpRightH->IsNull())
                        lpItem->m_lpRightH->Draw(pDC, rcRight);
                }
            }
        }
    }

    BOOL bHasText = FALSE;
    if (lpItem->m_strText.GetLength() > 0)
        bHasText = TRUE;

    BOOL bHasIcon = FALSE;
    if (lpItem->m_lpIconImg != NULL && !lpItem->m_lpIconImg->IsNull())
        bHasIcon = TRUE;

    if (!(lpItem->m_dwStyle & STBI_STYLE_DROPDOWN
            || lpItem->m_dwStyle & STBI_STYLE_WHOLEDROPDOWN))
        rcLeft = rcItem;

    if (bHasIcon && bHasText)	// 带图标和文字
    {
        int cxIcon = lpItem->m_lpIconImg->GetWidth();
        int cyIcon = lpItem->m_lpIconImg->GetHeight();

        int nMode = pDC->SetBkMode(TRANSPARENT);
        HFONT hFont = (HFONT)SendMessage(WM_GETFONT, 0, 0);
        if (NULL == hFont)
            hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
        HFONT hOldFont = (HFONT)pDC->SelectObject(hFont);

        CRect rcText(0,0,0,0);	// 计算文字宽高
        pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, DT_SINGLELINE | DT_CALCRECT);

        int cx = cxIcon+1+rcText.Width();
        int cy = cyIcon;

        CRect rcCenter;
        CalcCenterRect(rcLeft, cx, cy, rcCenter);

        CRect rcIcon(rcCenter.left, rcCenter.top, rcCenter.left+cxIcon, rcCenter.bottom);
        lpItem->m_lpIconImg->Draw(pDC, rcIcon);

        UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;
        rcText = CRect(rcIcon.right+1, rcLeft.top, rcIcon.right+1+rcText.Width(), rcLeft.bottom);
        pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, nFormat);

        pDC->SelectObject(hOldFont);
        pDC->SetBkMode(nMode);
    }
    else if (bHasIcon)	// 仅图标
    {
        int cxIcon = lpItem->m_lpIconImg->GetWidth();
        int cyIcon = lpItem->m_lpIconImg->GetHeight();

        CRect rcIcon;
        CalcCenterRect(rcLeft, cxIcon, cyIcon, rcIcon);

        lpItem->m_lpIconImg->Draw(pDC, rcIcon);
    }
    else if (bHasText)	// 仅文字
    {
        UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;

        int nMode = pDC->SetBkMode( TRANSPARENT);
        HFONT hFont = (HFONT)SendMessage(WM_GETFONT, 0, 0);
        if (NULL == hFont)
            hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
        HFONT hOldFont = (HFONT)pDC->SelectObject(hFont);
        pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcLeft, nFormat);
        pDC->SelectObject(hOldFont);
        pDC->SetBkMode(nMode);
    }

    if (lpItem->m_dwStyle & STBI_STYLE_DROPDOWN
            || lpItem->m_dwStyle & STBI_STYLE_WHOLEDROPDOWN)
    {
        if (lpItem->m_lpArrowImg != NULL && !lpItem->m_lpArrowImg->IsNull())
        {
            int cxArrow = lpItem->m_lpArrowImg->GetWidth();
            int cyArrow = lpItem->m_lpArrowImg->GetHeight();

            CRect rcArrow;
            CalcCenterRect(rcRight, cxArrow, cyArrow, rcArrow);
            rcArrow.left = rcRight.left;
            rcArrow.right = rcArrow.left + cxArrow;

            lpItem->m_lpArrowImg->Draw(pDC, rcArrow);
        }
    }
}