Ejemplo n.º 1
0
void TexturePopup::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	if (!m_bAnimationIsDone && !CMFCToolBar::IsCustomizeMode ())
	{
		DrawFade (&dc);
	}
	else
	{
		DoPaint (&dc);
	}
	dc.FillSolidRect(mButtonRect, RGB(245,245,245));
	// ±ß¿ò
	CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
	dc.FrameRect(mButtonRect, &brBtnShadow);
	// ÎÄ×Ö
 	CFont font;
 	font.Attach(::GetStockObject(DEFAULT_GUI_FONT));
 	dc.SelectObject(font);
  	dc.TextOut(20, 67, "Ìæ»»");
}
Ejemplo n.º 2
0
void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
#ifdef ST_USE_MEMDC
  CDC  *pdrawDC = CDC::FromHandle(lpDIS->hDC);
  CMemDC memDC(pdrawDC);
  CDC  *pDC = &memDC;
#else	
  CDC* pDC = CDC::FromHandle(lpDIS->hDC);
#endif

  CPen *pOldPen;
  BOOL bIsPressed  = (lpDIS->itemState & ODS_SELECTED);
  BOOL bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
  BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

  CRect itemRect = lpDIS->rcItem;

  if (m_bIsFlat == FALSE)
  {
	if (bIsFocused)
	{
	  CBrush br(RGB(0,0,0));  
	  pDC->FrameRect(&itemRect, &br);
	  itemRect.DeflateRect(1, 1);
	}
  }

  // Prepare draw... paint button's area with background color
  COLORREF bgColor;
  if ((m_MouseOnButton == TRUE) || (bIsPressed))
	bgColor = GetActiveBgColor();
  else
	bgColor = GetInactiveBgColor();

  CBrush br(bgColor);
  pDC->FillRect(&itemRect, &br);

	// Disegno lo sfondo del bottone
//CBrush br(GetSysColor(COLOR_BTNFACE));  
//pDC->FillRect(&itemRect, &br);

  // Draw pressed button
  if (bIsPressed)
  {
	if (m_bIsFlat == TRUE)
	{
	  if (m_bDrawBorder == TRUE)
	  {
		CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // Bianco
		CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Grigio scuro

		// Disegno i bordi a sinistra e in alto
		// Dark gray line
		pOldPen = pDC->SelectObject(&penBtnShadow);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.left, itemRect.top);
		pDC->LineTo(itemRect.right, itemRect.top);
		// Disegno i bordi a destra e in basso
		// White line
		pDC->SelectObject(penBtnHiLight);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.top-1);
		//
		pDC->SelectObject(pOldPen);
	  }
	}
	else    
	{
	  CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
	  pDC->FrameRect(&itemRect, &brBtnShadow);
	}
  }
  else // ...else draw non pressed button
  {
	CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
	CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT));       // Light gray
	CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Dark gray
	CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black

	if (m_bIsFlat == TRUE)
	{
	  if (m_MouseOnButton == TRUE && m_bDrawBorder == TRUE)
	  {
		// Disegno i bordi a sinistra e in alto
		// White line
		pOldPen = pDC->SelectObject(&penBtnHiLight);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.left, itemRect.top);
		pDC->LineTo(itemRect.right, itemRect.top);
		// Disegno i bordi a destra e in basso
		// Dark gray line
		pDC->SelectObject(penBtnShadow);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.top-1);
		//
		pDC->SelectObject(pOldPen);
	  }
	}
	else
	{
	  // Disegno i bordi a sinistra e in alto
	  // White line
	  pOldPen = pDC->SelectObject(&penBtnHiLight);
	  pDC->MoveTo(itemRect.left, itemRect.bottom-1);
	  pDC->LineTo(itemRect.left, itemRect.top);
	  pDC->LineTo(itemRect.right, itemRect.top);
	  // Light gray line
	  pDC->SelectObject(pen3DLight);
	  pDC->MoveTo(itemRect.left+1, itemRect.bottom-1);
	  pDC->LineTo(itemRect.left+1, itemRect.top+1);
	  pDC->LineTo(itemRect.right, itemRect.top+1);
	  // Disegno i bordi a destra e in basso
	  // Black line
	  pDC->SelectObject(pen3DDKShadow);
	  pDC->MoveTo(itemRect.left, itemRect.bottom-1);
	  pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
	  pDC->LineTo(itemRect.right-1, itemRect.top-1);
	  // Dark gray line
	  pDC->SelectObject(penBtnShadow);
	  pDC->MoveTo(itemRect.left+1, itemRect.bottom-2);
	  pDC->LineTo(itemRect.right-2, itemRect.bottom-2);
	  pDC->LineTo(itemRect.right-2, itemRect.top);
	  //
	  pDC->SelectObject(pOldPen);
	}
  }

  // Read the button title
  CString sTitle;
  GetWindowText(sTitle);

  // If we don't want the title displayed
  if (m_bShowText == FALSE) sTitle.Empty();

  CRect captionRect = lpDIS->rcItem;

  // Draw the icon
  if (m_hIconIn != NULL)
  {
	DrawTheIcon(pDC, &sTitle, &lpDIS->rcItem, &captionRect, bIsPressed, bIsDisabled);
  }

  // Write the button title (if any)
  if (sTitle.IsEmpty() == FALSE)
  {
	// Disegno la caption del bottone
	// Se il bottone e' premuto muovo la captionRect di conseguenza
	if (bIsPressed)
	  captionRect.OffsetRect(1, 1);
	
	// ONLY FOR DEBUG 
	// Evidenzia il rettangolo in cui verra' centrata la caption 
	//CBrush brBtnShadow(RGB(255, 0, 0));
	//pDC->FrameRect(&captionRect, &brBtnShadow);

#ifdef ST_USE_MEMDC
	// Get dialog's font
	CFont *pCurrentFont = GetFont(); 
	CFont *pOldFont = pDC->SelectObject(pCurrentFont);
#endif
	if ((m_MouseOnButton == TRUE) || (bIsPressed)) 
	{
	  pDC->SetTextColor(GetActiveFgColor());
	  pDC->SetBkColor(GetActiveBgColor());
	} 
	else 
	{
	  pDC->SetTextColor(GetInactiveFgColor());
	  pDC->SetBkColor(GetInactiveBgColor());
	}
	// Center text
	CRect centerRect = captionRect;
	pDC->DrawText(sTitle, -1, captionRect, DT_SINGLELINE|DT_CALCRECT);
	captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2);
	/* RFU
	captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);
	captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);
	*/

	pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), 
				   TRUE, 0, (CBrush*)NULL);
#ifdef ST_USE_MEMDC
	pDC->SelectObject(pOldFont);
#endif
  }

  if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE))
  {
	// Draw the focus rect
	if (bIsFocused)
	{
	  CRect focusRect = itemRect;
	  focusRect.DeflateRect(3, 3);
	  pDC->DrawFocusRect(&focusRect);
	}
  }
} // End of DrawItem
Ejemplo n.º 3
0
///////////////////////////////////////////////////////////////////////////////
// Draw
void CXButton::Draw(CDC *pDC, CRect& rect)
{
	//XLISTCTRL_TRACE(_T("in CXButton::Draw:  <%s>\n"), m_strText);
	//TRACERECT(rect);

	if (m_hTheme == NULL)
	{
		// open theme for Button

		if (ThemeHelper.IsThemeLibAvailable())
		{
			//XLISTCTRL_TRACE(_T("opening theme data ~~~~~\n"));
			m_hTheme = ThemeHelper.OpenThemeData(m_pParent->m_hWnd, _T("Button"));
		}
	}

	CFont *pFont = m_pParent->GetFont();
	CFont *pOldFont = NULL;

	if (pFont)
		pOldFont = pDC->SelectObject(pFont);

	CRect rectButton(rect);

	m_rect.CopyRect(rectButton);

	//dc.SetBkMode(TRANSPARENT);
	pDC->SetBkMode(OPAQUE);

	DWORD part = BP_PUSHBUTTON;

	BOOL bIsThemed = IsThemed(m_hTheme);

	if (bIsThemed)
	{
		DWORD state = m_bPressed ? PBS_PRESSED : PBS_NORMAL;

		if (state == PBS_NORMAL)
		{
			if (!m_bEnabled)
				state = PBS_DISABLED;
			if (m_bMouseOver)
				state = PBS_HOT;
		}
		ThemeHelper.DrawThemeBackground(m_hTheme, pDC->m_hDC, part, state, &rectButton, NULL);
	}
	else
	{
		CBrush brBackground(GetSysColor(COLOR_BTNFACE));

		pDC->FillRect(&rectButton, &brBackground);

		// draw pressed button
		if (m_bPressed)
		{
			CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
			pDC->FrameRect(&rectButton, &brBtnShadow);
		}
		else	// ...else draw non pressed button
		{
			UINT uState = DFCS_BUTTONPUSH |
				  (m_bMouseOver ? DFCS_HOT : 0) |
				  ((m_bPressed) ? DFCS_PUSHED : 0);

			pDC->DrawFrameControl(&rectButton, DFC_BUTTON, uState);
		}
	}

	BOOL bHasText = !m_strText.IsEmpty();

	UINT uTextAlignment = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_WORDBREAK;

	// write the button title (if any)
	if (bHasText)
	{
		// draw the button's title -
		// if button is pressed then "press" title also
		if (m_bPressed && !bIsThemed)
			rectButton.OffsetRect(1, 1);

		if (bIsThemed)
		{
			ThemeHelper.DrawThemeText(m_hTheme, pDC->m_hDC, part, m_bEnabled ? PBS_NORMAL : PBS_DISABLED,
							m_strText, uTextAlignment, 0, &rectButton);
		}
		else
		{
			pDC->SetBkMode(TRANSPARENT);

			if (!m_bEnabled)
			{
				rectButton.OffsetRect(1, 1);
				pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
				pDC->DrawText(m_strText, -1, &rectButton, uTextAlignment);
				rectButton.OffsetRect(-1, -1);
				pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
				pDC->DrawText(m_strText, -1, &rectButton, uTextAlignment);
			}
			else
			{
				pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
				pDC->SetBkColor(::GetSysColor(COLOR_BTNFACE));
				pDC->DrawText(m_strText, -1, &rectButton, uTextAlignment);
			}
		}
	}

	if (pOldFont)
		pDC->SelectObject(pOldFont);
}
Ejemplo n.º 4
0
void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
    CDC*    pDC = CDC::FromHandle(lpDIS->hDC);

    CPen    *pOldPen;

    // Checkbox or Radiobutton style ?
    if (m_bIsCheckBox == TRUE)
    {
        m_bIsPressed  =  (lpDIS->itemState & ODS_SELECTED) || (m_nCheck != 0);
        //m_bIsPressed = TRUE;
    }
    // Normal button OR other button style ...
    else
    {
        m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);
    }

    m_bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
    m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

    CRect itemRect = lpDIS->rcItem;

    pDC->SetBkMode(TRANSPARENT);

    if (m_bIsFlat == FALSE)
    {
        if (m_bIsFocused || (GetDefault() == TRUE))
        {
            CBrush br(RGB(0,0,0));  
            pDC->FrameRect(&itemRect, &br);
            itemRect.DeflateRect(1, 1);
        } // if
    } // if

    // Prepare draw... paint button background

    // Draw transparent?
    if (m_bDrawTransparent == TRUE)
    {
        PaintBk(pDC);
    }
    else
    {
        OnDrawBackground(pDC, &itemRect);
    }

    // Draw pressed button
    if (m_bIsPressed)
    {
		CRect captionRect1 = lpDIS->rcItem;
        if (m_bIsFlat == TRUE)
        {
            if (m_bDrawBorder)
            {
                OnDrawBorder(pDC, &itemRect);
		
            }
        }
        else    
        {
            CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
            pDC->FrameRect(&itemRect, &brBtnShadow);
        }
    }
    else // ...else draw non pressed button
    {
        CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
        CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT));       // Light gray
        CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Dark gray
        CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black

        if (m_bIsFlat == TRUE)
        {
            if (m_bMouseOnButton && m_bDrawBorder)
            {
                OnDrawBorder(pDC, &itemRect);
            }
        }
        else
        {
            // Draw top-left borders
            // White line
            pOldPen = pDC->SelectObject(&penBtnHiLight);
            pDC->MoveTo(itemRect.left, itemRect.bottom-1);
            pDC->LineTo(itemRect.left, itemRect.top);
            pDC->LineTo(itemRect.right, itemRect.top);
            // Light gray line
            pDC->SelectObject(pen3DLight);
            pDC->MoveTo(itemRect.left+1, itemRect.bottom-1);
            pDC->LineTo(itemRect.left+1, itemRect.top+1);
            pDC->LineTo(itemRect.right, itemRect.top+1);
            // Draw bottom-right borders
            // Black line
            pDC->SelectObject(pen3DDKShadow);
            pDC->MoveTo(itemRect.left, itemRect.bottom-1);
            pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
            pDC->LineTo(itemRect.right-1, itemRect.top-1);
            // Dark gray line
            pDC->SelectObject(penBtnShadow);
            pDC->MoveTo(itemRect.left+1, itemRect.bottom-2);
            pDC->LineTo(itemRect.right-2, itemRect.bottom-2);
            pDC->LineTo(itemRect.right-2, itemRect.top);
            //
            pDC->SelectObject(pOldPen);
        }
    }

    // Read the button's title
    CString sTitle;
    GetWindowText(sTitle);

    CRect captionRect = lpDIS->rcItem;

    // Draw the icon
    if (m_csIcons[0].hIcon != NULL)
    {
        DrawTheIcon(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
    }

    if (m_csBitmaps[0].hBitmap != NULL)
    {
        pDC->SetBkColor(RGB(255,255,255));
        DrawTheBitmap(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
    } // if

    // Write the button title (if any)
    if (sTitle.IsEmpty() == FALSE)
    {
        // Draw the button's title
        // If button is pressed then "press" title also
        if (m_bIsPressed && m_bIsCheckBox == FALSE)
        {
            //将偏移1像素的粗体显示效果去除。
            captionRect.OffsetRect(0, 0);
        }
    
        // ONLY FOR DEBUG 
        //CBrush brBtnShadow(RGB(255, 0, 0));
        //pDC->FrameRect(&captionRect, &brBtnShadow);

        /*
        if ((m_bMouseOnButton == TRUE) || (bIsPressed)) 
        {
            pDC->SetTextColor(GetActiveFgColor());
            pDC->SetBkColor(GetActiveBgColor());
        } 
        else 
        {
            pDC->SetTextColor(GetInactiveFgColor());
            pDC->SetBkColor(GetInactiveBgColor());
        }
        */
        // Center text
        CRect centerRect = captionRect;
        pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);
        captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, 
            (centerRect.Height() - captionRect.Height())/2);
        /* RFU
        captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);
        captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);
        */

        pDC->SetBkMode(TRANSPARENT);
        /*
        pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), 
                        TRUE, 0, (CBrush*)NULL);
        */
        if (m_bIsDisabled)
        {
            captionRect.OffsetRect(1, 1);
            pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
            captionRect.OffsetRect(-1, -1);
            pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
        }
        else
        {
            if (m_bMouseOnButton || m_bIsPressed) 
            {
                pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_IN]);
                pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_IN]);
            }
            else 
            {
                pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]);
                pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]);
            }

            if(m_bBigDaddy)
            {
                if(m_bIsFlat == TRUE)
                {
                    if (m_bDrawBorder)
                    {
                        OnDrawBorder(pDC, &itemRect);
                    }
                }
                else
                {
                    CBrush brBtnShadow(RGB(255,255,0));
                    pDC->FrameRect(&itemRect, &brBtnShadow);
                }
            }
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
        }
    }

    if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE))
    {
        // Draw the focus rect
        if (m_bIsFocused)
        {
            CRect focusRect = itemRect;
            focusRect.DeflateRect(3, 3);
            pDC->DrawFocusRect(&focusRect);
        } // if
    } // if
} // End of DrawItem
Ejemplo n.º 5
0
void CCoolButton::DrawItem(LPDRAWITEMSTRUCT lpDIS) 
{
	// TODO: Add your code to draw the specified item
	CDC * pDC=CDC::FromHandle(lpDIS->hDC);
	
	unsigned int  IsPressed =(lpDIS->itemState&ODS_SELECTED);
	unsigned int  IsFocused =(lpDIS->itemState&ODS_FOCUS);
	unsigned int  IsDisabled =(lpDIS->itemState&ODS_DISABLED);

	CRect itemRect = lpDIS->rcItem;

#ifndef XS_FLAT_BUTTON
	if(IsFocused)
	{
		CBrush br(RGB(0,0,0));
		pDC->FrameRect(&itemRect,&br);
		itemRect.DeflateRect(1,1);
	}
#endif
	//Fill with bkcolor
	CBrush br(GetSysColor(COLOR_BTNFACE));
	pDC->FillRect(&itemRect,&br);

	//Is pressed?
	if(IsPressed)
	{
#ifdef XS_FLAT_BUTTON
		//浅边界笔
		CPen penBtnHiLight(PS_SOLID,0,GetSysColor(COLOR_BTNHILIGHT));
		//阴影笔
		CPen penBtnShadow(PS_SOLID,0,GetSysColor(COLOR_BTNSHADOW));
		
		//绘边界阴影
		pDC->SelectObject(penBtnShadow);
		pDC->MoveTo(itemRect.left,itemRect.bottom-1);
		pDC->LineTo(itemRect.left,itemRect.top);
		pDC->LineTo(itemRect.right,itemRect.top);
		//绘浅边界
		pDC->SelectObject(penBtnHiLight);
		pDC->MoveTo(itemRect.left,itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1,itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1,itemRect.top-1);
#else
		CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
		pDC->FrameRect(&itemRect,&brBtnShadow);
#endif
	}
	else//没按下
	{
		CPen penBtnHiLight(PS_SOLID,0,GetSysColor(COLOR_BTNHILIGHT));
		CPen pen3DLight(PS_SOLID,0,GetSysColor(COLOR_3DLIGHT));
		CPen penBtnShadow(PS_SOLID,0,GetSysColor(COLOR_BTNSHADOW));
		CPen pen3DDKShadow(PS_SOLID,0,GetSysColor(COLOR_3DDKSHADOW));

#ifdef XS_FLAT_BUTTON
		if(m_MouseOnButton==TRUE)
		{
			pDC->SelectObject(penBtnHiLight);
			pDC->MoveTo(itemRect.left,itemRect.bottom-1);
			pDC->LineTo(itemRect.left,itemRect.top);
			pDC->LineTo(itemRect.right,itemRect.top);
			//
			pDC->SelectObject(penBtnShadow);
			pDC->MoveTo(itemRect.left,itemRect.bottom-1);
			pDC->LineTo(itemRect.right-1,itemRect.bottom-1);
			pDC->LineTo(itemRect.right-1,itemRect.top-1);
		}
#else
		pDC->SelectObject(penBtnHiLight);
		pDC->MoveTo(itemRect.left,itemRect.bottom-1);
		pDC->LineTo(itemRect.left,itemRect.top);
		pDC->LineTo(itemRect.right,itemRect.top);

		pDC->SelectObject(pen3DLight);
		pDC->MoveTo(itemRect.left+1,itemRect.bottom-1);
		pDC->LineTo(itemRect.left+1,itemRect.top+1);
		pDC->LineTo(itemRect.right,itemRect.top+1);

		pDC->SelectObject(pen3DDKShadow);
		pDC->MoveTo(itemRect.left,itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1,itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1,itemRect.top-1);

		pDC->SelectObject(penBtnShadow);
		pDC->MoveTo(itemRect.left+1,itemRect.bottom-2);
		pDC->LineTo(itemRect.right-2,itemRect.bottom-2);
		pDC->LineTo(itemRect.right-2,itemRect.top);
#endif
	}

#ifndef XS_FLAT_BUTTON
	//
	if(IsFocused)
	{
		CRect focusRect = itemRect;
		focusRect.DeflateRect(3,3);
		pDC->DrawFocusRect(&focusRect);
	}
#endif
	
	//获取文本
	CString title;
	GetWindowText(title);

	//绘制图标
	if(m_hIcon!=NULL)
	{
		CRect iconRect = lpDIS->rcItem;
		//根据标题是否存在来设置不同的图标位置
		if(title.IsEmpty()==TRUE)
		{
			iconRect.left+=((iconRect.Width()-m_cxIcon)/2);
		}
		else
		{
			iconRect.left+=6;
		}
		iconRect.top+=((iconRect.Height()-m_cyIcon)/2);
	
		if(IsPressed)iconRect.OffsetRect(1,1);


		pDC->DrawIcon(iconRect.TopLeft(),m_hIcon);
	}
	//绘标题
	CRect captionRect = lpDIS->rcItem;
	captionRect.left+=m_cxIcon;
	
	if(title.IsEmpty()==FALSE)
	{
		pDC->SetBkMode(TRANSPARENT);
		captionRect.OffsetRect(0,-1);
		
		if(IsPressed)
			captionRect.OffsetRect(1,1);

		if(IsDisabled)
		{
			captionRect.OffsetRect(1,1);
			pDC->SetTextColor(GetSysColor(COLOR_BTNHILIGHT));
			pDC->DrawText(title,-1,captionRect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
			captionRect.OffsetRect(-1,-1);
			pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW));
			pDC->DrawText(title,-1,captionRect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
		}
		else
		{
			pDC->DrawText(title,-1,captionRect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
		}
	}
}
Ejemplo n.º 6
0
void CProgressCtrlST::OnPaint() 
{
	// If there is no bitmap loaded
	if (m_hBitmap == NULL) 
	{
		CProgressCtrl::OnPaint();
		return;
	} // if

	CRect		rcCtrl;
	DWORD		dwStyle			= 0;
	BOOL		bVertical		= FALSE;
	float		f				= 0;
	int			nPercentage		= 0;
	HDC			hdcMem			= NULL;
	HDC			hdcTemp			= NULL;
	HBITMAP		hOldBitmap		= NULL;
	HBITMAP		hbmpTemp		= NULL;
	HBITMAP		hOldTempBitmap	= NULL;
	CPaintDC	dc(this);

	GetClientRect(rcCtrl);

	dwStyle = GetStyle();
	bVertical = (dwStyle & PBS_VERTICAL) == PBS_VERTICAL;

	// Has border ?
	if ((dwStyle & WS_BORDER) == WS_BORDER)
	{
		CBrush brBtnShadow(RGB(0, 0, 0));
		dc.FrameRect(rcCtrl, &brBtnShadow);
		rcCtrl.DeflateRect(1, 1);
	} // if

	rcCtrl.DeflateRect(1, 1);

	hdcMem = ::CreateCompatibleDC(dc.m_hDC);

	// Select bitmap
	hOldBitmap = (HBITMAP)::SelectObject(hdcMem, m_hBitmap);

	// Create temporary DC & bitmap
	hdcTemp = ::CreateCompatibleDC(dc.m_hDC);

	hbmpTemp = ::CreateCompatibleBitmap(hdcMem, rcCtrl.Width(), rcCtrl.Height());
	hOldTempBitmap = (HBITMAP)::SelectObject(hdcTemp, hbmpTemp);

	// Calculate control's percentage to draw
	nPercentage = (int)((100.0/m_nRange)*(abs(m_nLower)+m_nPos));

	// Adjust rectangle to draw on screen
	if (bVertical)
	{
		f = ((float)(rcCtrl.Height())/100)*nPercentage;
		if ((rcCtrl.bottom - (int)f) < rcCtrl.top)
			rcCtrl.top += 1;
		else
			rcCtrl.top = rcCtrl.bottom - (int)f;
	} // if
	else
	{
		f = ((float)(rcCtrl.Width())/100)*nPercentage;
		if ((rcCtrl.left + (int)f) > rcCtrl.right)
			rcCtrl.right -= 1;
		else
			rcCtrl.right = rcCtrl.left + (int)f;
	} // else

	// Tile the bitmap into the temporary rectangle
	TileBitmap(hdcTemp, hdcMem, rcCtrl);

	// Copy from temporary DC to screen (only the percentage rectangle)
	if (rcCtrl.IsRectEmpty() == FALSE)
		::BitBlt(dc.m_hDC, rcCtrl.left, rcCtrl.top, rcCtrl.Width(), rcCtrl.Height(), hdcTemp, 0, 0, SRCCOPY);


	CRect	rcFullCtrl;
	GetClientRect(rcFullCtrl);

	OnDrawText(&dc, nPercentage, rcFullCtrl, rcCtrl, bVertical);
	// Restore old selected bitmaps
	::SelectObject(hdcTemp, hOldTempBitmap);
	::SelectObject(hdcMem, hOldBitmap);

	::DeleteObject( hbmpTemp );
    ::DeleteDC( hdcTemp );
	::DeleteDC( hdcMem );
} // End of OnPaint
Ejemplo n.º 7
0
void CListBoxST::DrawItem(LPDRAWITEMSTRUCT pDIStruct)
{
  CDC*			pDC = CDC::FromHandle(pDIStruct->hDC);
  BOOL			bIsSelected = FALSE;
  BOOL			bIsFocused = FALSE;
  BOOL			bIsDisabled = FALSE;
  COLORREF		crNormal = GetSysColor(COLOR_WINDOW);
  COLORREF		crSelected = GetSysColor(COLOR_HIGHLIGHT);
  COLORREF		crText = GetSysColor(COLOR_WINDOWTEXT);
  COLORREF		crColor = RGB(0, 0, 0);
  CString			sText;					// List box item text
  STRUCT_LBDATA*	lpLBData = NULL;
  
  lpLBData = (STRUCT_LBDATA*)CListBox::GetItemDataPtr(pDIStruct->itemID);
  if (lpLBData == NULL || lpLBData == (LPVOID)-1L)	return;
  
  bIsSelected = (pDIStruct->itemState & ODS_SELECTED);
  bIsFocused = (pDIStruct->itemState & ODS_FOCUS);
  bIsDisabled = ((pDIStruct->itemState & ODS_DISABLED) || ((lpLBData->dwFlags & TEST_BIT0) == TEST_BIT0));
  
  CRect rcItem = pDIStruct->rcItem;
  CRect rcIcon = pDIStruct->rcItem;
  CRect rcText = pDIStruct->rcItem;
  CRect rcCenteredText = pDIStruct->rcItem;
  
  pDC->SetBkMode(TRANSPARENT);
  
  // ONLY FOR DEBUG 
  CBrush brBtnShadow(RGB(0, 0, 255));
//  pDC->FrameRect(&rcItem, &brBtnShadow);
//  pDC->Rectangle(&rcItem);
  
  // Calculate rcIcon
  if (m_pImageList)
  {
    rcIcon.right = rcIcon.left + m_szImage.cx + CX_BORDER*3;
    rcIcon.bottom = rcIcon.top + m_szImage.cy + CY_BORDER*3;
  } // if
  else rcIcon.SetRect(0, 0, 0, 0);
  
  // Calculate rcText
  rcText.left = rcIcon.right;
  
  // Calculate rcCenteredText
  // Get list box item text
  CListBox::GetText(pDIStruct->itemID, sText);
  rcCenteredText = rcText;
  pDC->DrawText(sText, -1, rcCenteredText, DT_WORDBREAK | DT_EXPANDTABS| DT_CALCRECT | lpLBData->nFormat);
  rcCenteredText.OffsetRect(0, (rcText.Height() - rcCenteredText.Height())/2);
  
  // Draw rcIcon background
  if (m_pImageList)
  {
    if (bIsSelected && (m_byRowSelect == ST_FULLROWSELECT) && !bIsDisabled)
      crColor = crSelected;
    else
      crColor = crNormal;
    
    OnDrawIconBackground(pDIStruct->itemID, pDC, &rcItem, &rcIcon, bIsDisabled, bIsSelected, crColor);
  } // if
  
  // Draw rcText/rcCenteredText background
  if (bIsDisabled)
  {
    pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
    crColor = crNormal;
  } // if
  else
  {
    if (bIsSelected)
    {
      pDC->SetTextColor(0x00FFFFFF & ~crText);
      crColor = crSelected;
    } // if
    else
    {
      pDC->SetTextColor(crText);
      crColor = crNormal;
    } // else
  } // else
  
  if (m_byRowSelect == ST_TEXTSELECT)
    //pDC->FillSolidRect(&rcCenteredText, crColor);
    OnDrawTextBackground(pDIStruct->itemID, pDC, &rcItem, &rcCenteredText, bIsDisabled, bIsSelected, crColor);
  else
    //pDC->FillSolidRect(&rcText, crColor);
    OnDrawTextBackground(pDIStruct->itemID, pDC, &rcItem, &rcText, bIsDisabled, bIsSelected, crColor);
  
  // Draw the icon (if any)
  if (m_pImageList)
    OnDrawIcon(pDIStruct->itemID, pDC, &rcItem, &rcIcon, lpLBData->nImage, bIsDisabled, bIsSelected);
  
  // Draw text
  pDC->DrawText(sText, -1, rcCenteredText, DT_WORDBREAK | DT_EXPANDTABS | lpLBData->nFormat);
  
  // Draw focus rectangle
  if (bIsFocused && !bIsDisabled)
  {
    switch (m_byRowSelect)
    {
    case ST_FULLROWSELECT:
      pDC->DrawFocusRect(&rcItem);
      break;
    case ST_FULLTEXTSELECT:
      pDC->DrawFocusRect(&rcText);
      break;
    case ST_TEXTSELECT:
    default:
      pDC->DrawFocusRect(&rcCenteredText);
      break;
    } // switch
  } // if
} // End of DrawItem