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

📄 buttonstyle.cpp

📁 魔法单词记忆——DAO访问ACCESS数据库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   CWnd *pWnd;
   CWnd *pParent;

	CButton::OnMouseMove(nFlags, point);

   // If the mouse enter the button with the left button pressed
   // then do nothing
   if ( nFlags & MK_LBUTTON && m_MouseOnButton == FALSE )
      return;

   // If button is not flat then do nothing
   if ( m_bIsFlat == FALSE )
      return;

   pWnd = GetActiveWindow();
   pParent = GetOwner();

   if ( ( GetCapture() != this ) && (
        #ifndef ST_LIKEIE
           pWnd != NULL &&
        #endif
           pParent != NULL ) )
   {
      m_MouseOnButton = TRUE;
      SetCapture();
      Invalidate();
   }
   else
   {
      CRect rc;
      GetClientRect( &rc );

      if ( !rc.PtInRect( point ) )
      {
         if ( m_MouseOnButton == TRUE )
         {
            m_MouseOnButton = FALSE;
            Invalidate();
         }

         // If user is NOT pressing left button then release capture!
         if ( ! ( nFlags & MK_LBUTTON ) )
            ReleaseCapture();
      }
   }

}

BOOL CButtonStyle::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// If a cursor was specified when use it!
   if ( m_hCursor != NULL )
   {
      ::SetCursor( m_hCursor);
      return TRUE;
   }

	return CButton::OnSetCursor(pWnd, nHitTest, message);
}

BOOL CButtonStyle::SetButtonCursor(int nCursorID)
{
   HINSTANCE hInstResource;

   if ( m_hCursor != NULL )   ::DestroyCursor( m_hCursor );

   m_hCursor = NULL;

   if ( nCursorID != -1 )
   {
      hInstResource = AfxFindResourceHandle( MAKEINTRESOURCE( nCursorID ), RT_GROUP_CURSOR );
      m_hCursor = (HCURSOR) ::LoadImage( hInstResource, MAKEINTRESOURCE( nCursorID ), IMAGE_CURSOR, 0, 0, 0 );

      if ( m_hCursor == NULL )
         return FALSE;
   }

   return TRUE;
}

void CButtonStyle::SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint)
{
   m_bDrawFlatFocus = bDrawFlatFocus;

   if ( bRepaint == TRUE )
      Invalidate();
}

BOOL CButtonStyle::GetFlatFocus()
{
   return m_bDrawFlatFocus;
}

void CButtonStyle::SetDefActiveFgColor(BOOL bRepaint)
{
   m_crActiveFg = ::GetSysColor( COLOR_BTNTEXT );

   if ( bRepaint == TRUE )
      Invalidate();
}

void CButtonStyle::SetActiveFgColor(COLORREF crNew, BOOL bRepaint)
{
   m_crActiveFg = crNew;

   if ( bRepaint == TRUE )
      Invalidate();
}

const COLORREF CButtonStyle::GetActiveFgColor()
{
   return m_crActiveFg;
}

void CButtonStyle::SetDefActiveBgColor(BOOL bRepaint)
{
   m_crActiveBg = ::GetSysColor( COLOR_BTNFACE );

   if ( bRepaint == TRUE )
      Invalidate();
}

void CButtonStyle::SetActiveBgColor(COLORREF crNew, BOOL bRepaint)
{
   m_crActiveBg = crNew;
   
   if ( bRepaint == TRUE )
      Invalidate();
}

const COLORREF CButtonStyle::GetActiveBgColor()
{
   return m_crActiveBg;
}

void CButtonStyle::SetDefInactiveFgColor(BOOL bRepaint)
{
   m_crInactiveFg = ::GetSysColor( COLOR_BTNTEXT );

   if ( bRepaint == TRUE )
      Invalidate();
}

void CButtonStyle::SetInactiveFgColor(COLORREF crNew, BOOL bRepaint)
{
   m_crInactiveFg = crNew;

   if ( bRepaint == TRUE )
      Invalidate();
}

const COLORREF CButtonStyle::GetInactiveFgColor()
{
   return m_crInactiveFg;
}

void CButtonStyle::SetDefInactiveBgColor(BOOL bRepaint)
{
   m_crInactiveBg = ::GetSysColor( COLOR_BTNFACE );
   
   if ( bRepaint == TRUE )
      Invalidate();
}

void CButtonStyle::SetInactiveBgColor(COLORREF crNew, BOOL bRepaint)
{
   m_crInactiveBg = crNew;

   if ( bRepaint == TRUE )
      Invalidate();
}

const COLORREF CButtonStyle::GetInactiveBgColor()
{
   return m_crInactiveBg;
}

void CButtonStyle::SetShowText(BOOL bShow)
{
   m_bShowText = bShow;
   Invalidate();
}

BOOL CButtonStyle::GetShowText()
{
   return m_bShowText;
}

void CButtonStyle::SetAlign(int nAlign)
{
   switch ( nAlign )
   {
   case ST_ALIGN_HORIZ:
      m_nAlign = ST_ALIGN_HORIZ;
      break;

   case ST_ALIGN_VERT:
      m_nAlign = ST_ALIGN_VERT;
      break;
   }
   Invalidate();
}

int CButtonStyle::GetAlign()
{
   return m_nAlign;
}

void CButtonStyle::SetFlat(BOOL bState)
{
   m_bIsFlat = bState;
   Invalidate();
}

BOOL CButtonStyle::GetFlat()
{
   return m_bIsFlat;
}

void CButtonStyle::DrawBorder(BOOL bEnable)
{
   m_bDrawBorder = bEnable;
}

void CButtonStyle::SetIcon(int nIconInId, int nIconOutId, BYTE cx, BYTE cy)
{
   HINSTANCE hInstResource = AfxFindResourceHandle( MAKEINTRESOURCE( nIconInId ),RT_GROUP_ICON );

   // Set icon when the mouse is IN the button
   m_hIconIn = (HICON) ::LoadImage( hInstResource, MAKEINTRESOURCE( nIconInId ), IMAGE_ICON, 0, 0, 0 );

   // Set icon when the mouse is OUT the button
   m_hIconOut = (nIconOutId == NULL ) ? m_hIconIn : (HICON) ::LoadImage( hInstResource, MAKEINTRESOURCE( nIconOutId ), IMAGE_ICON, 0, 0, 0 );

   m_cxIcon = cx;
   m_cyIcon = cy;
}

const short CButtonStyle::GetVersionI()
{
   return 23;
}

const char* CButtonStyle::GetVersionC()
{
   return "2.3";
}

void CButtonStyle::DrawTheIcon(CDC *pDC, CString *title, RECT *rcItem, CRect *captionRect, BOOL IsPressed, BOOL IsDisabled)
{
   CRect iconRect = rcItem;
   
   switch ( m_nAlign )
   {
   case ST_ALIGN_HORIZ:
      if ( title->IsEmpty() )
      {
         // Center the icon horizontally
         iconRect.left += ( ( iconRect.Width() - m_cxIcon ) / 2 );
      }
      else
      {
         // L'icona deve vedersi subito dentro il focus rect
         iconRect.left += 3;  
         captionRect->left += m_cxIcon + 3;
      }      
      // Center the icon vertically
      iconRect.top += ((iconRect.Height() - m_cyIcon)/2);
      break;
   
   case ST_ALIGN_VERT:
      // Center the icon horizontally
      iconRect.left += ( ( iconRect.Width() - m_cxIcon ) / 2 );
      
      if ( title->IsEmpty() )
      {
         // Center the icon vertically
         iconRect.top += ( ( iconRect.Height() - m_cyIcon ) / 2 );
      }
      else
      {
         captionRect->top += m_cyIcon;
      }
      break;
   }
   
   // If button is pressed then press the icon also
   if ( IsPressed )
      iconRect.OffsetRect( 1, 1 );
   
   // Ole'!
   pDC->DrawState( iconRect.TopLeft(), iconRect.Size(), 
                   ( m_MouseOnButton == TRUE || IsPressed ) ? m_hIconIn : m_hIconOut,
                   ( IsDisabled ? DSS_DISABLED : DSS_NORMAL ), (CBrush*) NULL );
}

⌨️ 快捷键说明

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