void CMySliderCtrl::OnPaint() {
    // without this first check it gets the background(s)
    // before they've been painted
    static BOOL first = TRUE;
    if (first) {
        first = FALSE;
        return;
    }

    CPaintDC pDC(this);
    PaintBk(&pDC);
    DrawTheBitmap(&pDC, m_ChannelRect, 0);
    DrawTheBitmap(&pDC, m_ThumbRect, 3);
}
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
void CButtonST::DrawItem(UINT ctrlID, LPDRAWITEMSTRUCT lpDIS)
{
	CDCHandle pDC = lpDIS->hDC;

	CPenHandle	pOldPen;

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

	m_bIsFocused  = (lpDIS->itemState & ODS_FOCUS) != 0;
	m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED) != 0;
	
	CRect itemRect = lpDIS->rcItem;

	pDC.SetBkMode(TRANSPARENT);

	if (!m_bIsFlat)
		{
		if (m_bIsFocused || GetDefault())
			{
			CBrush br;
			br.CreateSolidBrush(RGB(0,0,0));  
			pDC.FrameRect(&itemRect, br);
			itemRect.DeflateRect(1, 1);
			}
		}

	// Prepare draw... paint button background

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

	// Draw pressed button
	if (m_bIsPressed)
		{
		if (m_bIsFlat)
			{
			if (m_bDrawBorder)
				{
				OnDrawBorder(pDC, &itemRect);
				}
			}
		else    
			{
			CBrush brBtnShadow;
			brBtnShadow.CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
			pDC.FrameRect(&itemRect, brBtnShadow);
			}
		}
	else // ...else draw non pressed button
		{
		CPen penBtnHiLight; // White
		CPen pen3DLight;       // Light gray
		CPen penBtnShadow;   // Dark gray
		CPen pen3DDKShadow; // Black

		penBtnHiLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNHILIGHT)); // White
		pen3DLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DLIGHT));       // Light gray
		penBtnShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNSHADOW));   // Dark gray
		pen3DDKShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DDKSHADOW)); // Black

		if (m_bIsFlat)
			{
			if (m_bMouseOnButton && m_bDrawBorder)
				{
				pDC.Draw3dRect(itemRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
				}
			}
		else
			{
			// Draw top-left borders
			// White line
			pOldPen = pDC.SelectPen(penBtnHiLight);
			pDC.MoveTo(itemRect.left, itemRect.bottom-1);
			pDC.LineTo(itemRect.left, itemRect.top);
			pDC.LineTo(itemRect.right, itemRect.top);
			// Light gray line
			pDC.SelectPen(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.SelectPen(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.SelectPen(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.SelectPen(pOldPen);
			}
		}

	// Read the button's title
	CString sTitle;
	int nLen = GetWindowTextLength();
	int nRetLen = GetWindowText(sTitle.GetBufferSetLength(nLen), nLen + 1);

	CRect captionRect = lpDIS->rcItem;

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

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

	// Write the button title (if any)
	if (!sTitle.IsEmpty())
		{
		// Draw the button's title
		// If button is pressed then "press" title also
		if (m_bIsPressed && !m_bIsCheckBox)
			{
			captionRect.OffsetRect(1, 1);
			}
		// 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);
		pDC.SetBkMode(TRANSPARENT);
		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]);
				}
			pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
			}
		}
	if (!m_bIsFlat || (m_bIsFlat && m_bDrawFlatFocus))
		{
		// Draw the focus rect
		if (m_bIsFocused)
			{
			CRect focusRect = itemRect;
			focusRect.DeflateRect(3, 3);
			pDC.DrawFocusRect(&focusRect);
			}
		}
}