⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushbutton.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		Invalidate();
  }
  else
  {
    CRect rc;
    GetClientRect(&rc);
    if (!rc.PtInRect(point))
    {
      if (m_MouseOnButton == TRUE)
      {
        m_MouseOnButton = FALSE;
        Invalidate();
      }
      if (!(nFlags & MK_LBUTTON)) 
		  ReleaseCapture();
    }
  }
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::OnKillFocus(CWnd * pNewWnd)
{
  CButton::OnKillFocus(pNewWnd);
  if (m_MouseOnButton == TRUE)
  {
    m_MouseOnButton = FALSE;
    Invalidate();
  }
} // End of OnKillFocus
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
  CDC  *pdrawDC = CDC::FromHandle(lpDIS->hDC);
  CMemDC memDC(pdrawDC);
  CDC  *pDC = &memDC;
  BOOL bIsPressed  = (lpDIS->itemState & ODS_SELECTED);
  BOOL bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
  BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

  CRect itemRect = lpDIS->rcItem;
  if(m_hIcon!=NULL)
     m_pBKObject->Draw(pDC,itemRect);
  else
     m_pBKObject->Draw(pDC,0,0);
  if (bIsFocused)
  {
      CBrush br(RGB(0,0,0));  
      pDC->FrameRect(&itemRect, &br);
      itemRect.DeflateRect(1, 1);
  }
  COLORREF bgColor;
  if ((m_MouseOnButton == TRUE) || (bIsPressed))
    bgColor = GetActiveBgColor();
  else
    bgColor = GetInactiveBgColor();
  if (bIsPressed)
  {
	Line(itemRect.left, itemRect.bottom-1,itemRect.left, itemRect.top,COLOR_BLACK,pDC);
	Line(itemRect.left, itemRect.top,itemRect.right, itemRect.top,COLOR_BLACK,pDC);

    Line(itemRect.left+1, itemRect.bottom-1,itemRect.left+1, itemRect.top+1,COLOR_DARK_GRAY,pDC);
	Line(itemRect.left+1, itemRect.top+1,itemRect.right, itemRect.top+1,COLOR_DARK_GRAY,pDC);

	Line(itemRect.left, itemRect.bottom-1,itemRect.right-1, itemRect.bottom-1,COLOR_WHITE,pDC);
	Line(itemRect.right-1, itemRect.bottom-1,itemRect.right-1, itemRect.top-1,COLOR_WHITE,pDC);

	Line(itemRect.left+1, itemRect.bottom-2,itemRect.right-2, itemRect.bottom-2,COLOR_GRAY,pDC);
	Line(itemRect.right-2, itemRect.bottom-2,itemRect.right-2, itemRect.top,COLOR_GRAY,pDC);
  }
  else
  {
	Line(itemRect.left, itemRect.bottom-1,itemRect.left, itemRect.top,COLOR_WHITE,pDC);
	Line(itemRect.left, itemRect.top,itemRect.right, itemRect.top,COLOR_WHITE,pDC);

    Line(itemRect.left+1, itemRect.bottom-1,itemRect.left+1, itemRect.top+1,COLOR_GRAY,pDC);
	Line(itemRect.left+1, itemRect.top+1,itemRect.right, itemRect.top+1,COLOR_GRAY,pDC);

	Line(itemRect.left, itemRect.bottom-1,itemRect.right-1, itemRect.bottom-1,COLOR_BLACK,pDC);
	Line(itemRect.right-1, itemRect.bottom-1,itemRect.right-1, itemRect.top-1,COLOR_BLACK,pDC);

	Line(itemRect.left+1, itemRect.bottom-2,itemRect.right-2, itemRect.bottom-2,COLOR_DARK_GRAY,pDC);
	Line(itemRect.right-2, itemRect.bottom-2,itemRect.right-2, itemRect.top,COLOR_DARK_GRAY,pDC);
  }
  CRect captionRect = lpDIS->rcItem;
  if (m_hIcon != NULL)
    DrawTheIcon(pDC,&lpDIS->rcItem, &captionRect, bIsPressed, bIsDisabled);
  if (bIsPressed)
      captionRect.OffsetRect(1, 1);
  CRect centerRect = captionRect;
  if (m_bDrawFlatFocus == TRUE)
  {
    if (bIsFocused)
    {
      CRect focusRect = itemRect;
      focusRect.DeflateRect(3, 3);
      pDC->DrawFocusRect(&focusRect);
    }
  }
} // End of DrawItem
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::DrawTheIcon(CDC* pDC,RECT* rcItem, CRect* captionRect, BOOL IsPressed, BOOL IsDisabled)
{
  CRect iconRect = rcItem;

  switch (m_nAlign)
  {
    case ST_ALIGN_HORIZ:
         iconRect.left += ((iconRect.Width() - m_cxIcon)/2);
         iconRect.top += ((iconRect.Height() - m_cyIcon)/2);
         break;
    case ST_ALIGN_VERT:
         iconRect.left += ((iconRect.Width() - m_cxIcon)/2);
         iconRect.top += ((iconRect.Height() - m_cyIcon)/2);           
         break;
  }
  if (IsPressed) iconRect.OffsetRect(1, 1);
  pDC->DrawState(iconRect.TopLeft(), 
	               iconRect.Size(), 
				         (m_MouseOnButton == TRUE || IsPressed) ? m_hIcon: m_hIcon, 
				         (IsDisabled ? DSS_DISABLED : DSS_NORMAL), 
                 (CBrush*)NULL);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::PreSubclassWindow() 
{
  SetButtonStyle(GetButtonStyle() | BS_OWNERDRAW);
  CButton::PreSubclassWindow();
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetDefaultInactiveBgColor(BOOL bRepaint)
{
	m_crInactiveBg = ::GetSysColor(COLOR_BTNFACE); 
	if (bRepaint == TRUE) Invalidate();
} // End of SetDefaultInactiveBgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetInactiveBgColor(COLORREF crNew, BOOL bRepaint)
{
	m_crInactiveBg = crNew; 
	if (bRepaint == TRUE) Invalidate();
} // End of SetInactiveBgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
const COLORREF CPushButton::GetInactiveBgColor()
{
	return m_crInactiveBg;
} // End of GetInactiveBgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetDefaultInactiveFgColor(BOOL bRepaint)
{
	m_crInactiveFg = ::GetSysColor(COLOR_BTNTEXT); 
	if (bRepaint == TRUE) Invalidate();
} // End of SetDefaultInactiveFgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetInactiveFgColor(COLORREF crNew, BOOL bRepaint)
{
	m_crInactiveFg = crNew; 
	if (bRepaint == TRUE) Invalidate();
} // End of SetInactiveFgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
const COLORREF CPushButton::GetInactiveFgColor()
{
	return m_crInactiveFg;
} // End of GetInactiveFgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetDefaultActiveBgColor(BOOL bRepaint)
{
	m_crActiveBg = ::GetSysColor(COLOR_BTNFACE); 
	if (bRepaint == TRUE) Invalidate();
} // End of SetDefaultActiveBgColor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetActiveBgColor(COLORREF crNew, BOOL bRepaint)
{
	m_crActiveBg = crNew; 
	if (bRepaint == TRUE) Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
const COLORREF CPushButton::GetActiveBgColor()
{
	return m_crActiveBg;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetDefaultActiveFgColor(BOOL bRepaint)
{
	m_crActiveFg = ::GetSysColor(COLOR_BTNTEXT); 
	if (bRepaint == TRUE) Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetActiveFgColor(COLORREF crNew, BOOL bRepaint)
{
	m_crActiveFg = crNew; 
	if (bRepaint == TRUE) Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
const COLORREF CPushButton::GetActiveFgColor()
{
	return m_crActiveFg;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPushButton::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	if (m_hCursor != NULL)
	{
		::SetCursor(m_hCursor);
		return TRUE;
	}
	return CButton::OnSetCursor(pWnd, nHitTest, message);
} // End of OnSetCursor
////////////////////////////////////////
//
///////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -