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

📄 coolcontrolsmanager.cpp

📁 vc6.0实现的酒店管理系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void CCoolControlsManager::CCMRadioButton::DrawControl( HDC hDC, const RECT& rect )
{
   DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE );

   if ( dwStyle & BS_PUSHLIKE )
   {
      CCMPushButton::DrawControl( hDC, rect );
      return;
   }  

   const int nRadioSize = 12;
   RECT rc;
   
   if ( ( dwStyle & BS_VCENTER ) == BS_VCENTER )
      rc.top = rect.top + ( ( rect.bottom - rect.top ) - nRadioSize - 1 ) / 2;
   else if ( dwStyle & BS_TOP )
      rc.top = rect.top + 1;
   else if ( dwStyle & BS_BOTTOM )
      rc.top = rect.bottom - nRadioSize - 3;
   else  // Default
      rc.top = rect.top + ( ( rect.bottom - rect.top ) - nRadioSize - 1 ) / 2;
   
   if ( dwStyle & BS_LEFTTEXT )
      rc.left = rect.right - nRadioSize;
   else
      rc.left = rect.left + 1;

   rc.right = rc.left + nRadioSize;
   rc.bottom = rc.top + nRadioSize;

   POINT pt1[] = { 
                  { 1,9 },{ 1,8 },
                  { 0,7 },{ 0,6 },{ 0,5 },{ 0,4 },
                  { 1,3 },{ 1,2 },
                  { 2,1 },{ 3,1 },
                  { 4,0 },{ 5,0 },{ 6,0 },{ 7,0 },
                  { 8,1 },{ 9,1 },
                  { 0,0 }
               };  
               
   POINT pt2[] = { 
                  { 2,8 },
                  { 1,7 },{ 1,6 },{ 1,5 },{ 1,4 },
                  { 2,3 },{ 2,2 },
                  { 3,2 },
                  { 4,1 },{ 5,1 },{ 6,1 },{ 7,1 },
                  { 8,2 },{ 9,2 },
                  { 0,0 }
               };  


   POINT pt3[] = { 
                  { 2,9 },{ 3,9 },
                  { 4,10 },{ 5,10 },{ 6,10 },{ 7,10 },
                  { 8,9 },{ 9,9 },
                  { 9,8 },
                  { 10,7 },{ 10,6 },{ 10,5 },{ 10,4 },
                  { 9,3 },
                  { 0,0 }
               };  

   POINT pt4[] = { 
                  { 2,10 },{ 3,10 },
                  { 4,11 },{ 5,11 },{ 6,11 },{ 7,11 },
                  { 8,10 },{ 9,10 },
                  { 10,9 },{ 10,8 },
                  { 11,7 },{ 11,6 },{ 11,5 },{ 11,4 },
                  { 10,3 },{ 10,2 },
                  { 0,0 }
               };  

   if ( m_nState & dsHoverMask )
   {
      DrawFrame( pt1, COLOR_3DSHADOW,
                      hDC, rc.left, rc.top );
      DrawFrame( pt2, COLOR_3DDKSHADOW,
                      hDC, rc.left, rc.top );
      DrawFrame( pt3, COLOR_3DFACE,
                      hDC, rc.left, rc.top );
      DrawFrame( pt4, COLOR_WINDOW,
                      hDC, rc.left, rc.top );
   }
   else
   {
      if ( IsWindowEnabled( m_hWnd ) == TRUE ) 
      {  
         DrawFrame( pt1, COLOR_3DSHADOW,
                         hDC, rc.left, rc.top );
         DrawFrame( pt2, COLOR_WINDOW,
                         hDC, rc.left, rc.top );
         DrawFrame( pt3, COLOR_3DFACE,
                         hDC, rc.left, rc.top );
         DrawFrame( pt4, COLOR_WINDOW,
                         hDC, rc.left, rc.top );                  
      }
      else
      {
         DrawFrame( pt1, COLOR_3DSHADOW,
                         hDC, rc.left, rc.top );
         DrawFrame( pt2, COLOR_3DFACE,
                         hDC, rc.left, rc.top );
         DrawFrame( pt3, COLOR_3DFACE,
                         hDC, rc.left, rc.top );
         DrawFrame( pt4, COLOR_3DHIGHLIGHT,
                         hDC, rc.left, rc.top );
      }
   }   
}

//////////////////////////////////////////////////////////////////////////////
// CCMUpDown class

void CCoolControlsManager::CCMUpDown::DrawButton( HDC hDC, const RECT& rc )
{
   // If associated edit control is disabled
   // draw the up-down as disabled too
   BOOL bEnabled = IsWindowEnabled( m_hWnd );
   HWND hWnd = (HWND)SendMessage( m_hWnd, UDM_GETBUDDY, 0, 0L );
   if ( hWnd )
      bEnabled = IsWindowEnabled( hWnd );

   if ( bEnabled && m_nState & dsHoverMask )
      Draw3dBorder( hDC, rc, COLOR_3DFACE, COLOR_3DDKSHADOW,
                             COLOR_3DHIGHLIGHT, COLOR_3DSHADOW );
   else
      Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DSHADOW,
                             COLOR_3DFACE, COLOR_3DFACE );
}

void CCoolControlsManager::CCMUpDown::DrawControl( HDC hDC, const RECT& rect )
{         
   RECT rc = rect;
   CCMControl* pCtl = NULL;
   DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE );
   HWND hWnd = (HWND)SendMessage( m_hWnd, UDM_GETBUDDY, 0, 0L );
   if ( hWnd && ( dwStyle & UDS_ALIGNRIGHT || dwStyle & UDS_ALIGNLEFT ) )
   {
      if ( dwStyle & UDS_ALIGNLEFT )
         rc.left += 2;
      else   // UDS_ALIGNRIGHT
         rc.right -= 2;
      rc.top += 2;
      rc.bottom -= 2;
                 
      if ( g_ctrlManager.m_ctrlMap.Lookup( hWnd, (void*&)pCtl ) && 
           !( pCtl->GetState() & dsHoverMask ) )
      {
         COLORREF clr1 = GetSysColor( IsWindowEnabled( hWnd ) ? COLOR_3DHIGHLIGHT : COLOR_3DFACE );
         COLORREF clr2 = GetSysColor( IsWindowEnabled( hWnd ) ? COLOR_3DLIGHT : COLOR_3DFACE );

         FillSolidRect( hDC, rc.left, rc.top - 1,
                             rc.right, 1,
                             clr1 );
         FillSolidRect( hDC, rc.left, rc.bottom,
                             rc.right, 1,                                  
                             clr2 );

         if ( dwStyle & UDS_ALIGNLEFT )
            FillSolidRect( hDC, rc.left - 1, rc.top - 1,
                                1, rc.bottom,
                                clr1 );
         else
            FillSolidRect( hDC, rc.right, rc.top - 1,
                                1, rc.bottom,
                                clr2 );
      }
   }

   RECT r = rc;
   if ( dwStyle & UDS_HORZ )
   {
      r.right = r.left + ( rc.right - rc.left ) / 2;
      DrawButton( hDC, r );

      r.left = r.right + ( rc.right - rc.left ) % 2;
      r.right = rc.right;
      DrawButton( hDC, r );
   }
   else
   {
      r.bottom = r.top + ( rc.bottom - rc.top ) / 2;
      DrawButton( hDC, r );

      r.top = r.bottom + ( rc.bottom - rc.top ) % 2;
      r.bottom = rc.bottom;
      DrawButton( hDC, r );
   }

   if ( pCtl == NULL )  // Get parent (e.g. for datetime with up-down controls)
   {
      hWnd = GetParent( m_hWnd );
      g_ctrlManager.m_ctrlMap.Lookup( hWnd, (void*&)pCtl );
   }

   if ( pCtl && IsWindowEnabled( hWnd ) )   // Redraw parent or buddy if neccesary
   {
      if ( m_nState & dsHoverMask )
         pCtl->SetState( 0, dsHover );
      else
         pCtl->SetState( dsHover, 0 );
   }
}

//////////////////////////////////////////////////////////////////////////////
// CCMEditCombo class

void CCoolControlsManager::CCMEditCombo::PrepareDraw( HDC& hDC, RECT& rect )
{
   GetWindowRect( m_hWnd, &rect );
   InflateRect( &rect, 3, 3 );
   OffsetRect( &rect, -rect.left, -rect.top );
   // Draw onto that DC that is most suitable for given class   
   hDC = GetWindowDC( GetParent( m_hWnd ) );
}

//////////////////////////////////////////////////////////////////////////////
// CCMScrollBar class

void CCoolControlsManager::CCMScrollBar::DrawControl( HDC hDC, const RECT& rc )
{  
   DrawScrollBar( hDC, rc, 
             ( GetWindowLong( m_hWnd, GWL_STYLE ) & SBS_VERT ) ? SB_VERT : SB_HORZ,
             TRUE );
}

LRESULT CCoolControlsManager::CCMScrollBar::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch ( uMsg )
   {      
      // Scrollbar messages
      case SBM_SETPOS:
         if ( !lParam )  // redraw flag
            break;

      case SBM_SETSCROLLINFO:      
         if ( !wParam )  // redraw flag
            break;

      case SBM_SETRANGEREDRAW:
         CallWindowProc( m_oldWndProc, m_hWnd, uMsg, wParam, lParam );
         DrawBorder();
         return 0;

      default:
         return CCMControl::WindowProc( uMsg, wParam, lParam );
   }

   return CallWindowProc( m_oldWndProc, m_hWnd, uMsg, wParam, lParam );
}

//////////////////////////////////////////////////////////////////////////////
// CCMHeaderCtrl class

void CCoolControlsManager::CCMHeaderCtrl::DrawButton( HDC hDC, const RECT& rc, int nState )
{
   if ( nState & dsHoverMask )
      Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DDKSHADOW,
                             COLOR_3DLIGHT, COLOR_3DSHADOW );
   else
      Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DSHADOW,
                             COLOR_3DFACE, COLOR_3DFACE );      
}

void CCoolControlsManager::CCMHeaderCtrl::DrawControl( HDC hDC, const RECT& /*rc*/ )
{
   int nOldItem = m_nOldItem;
   m_nOldItem = -1;

   RECT rc;
   POINT point;
   GetCursorPos( &point );

   // This code fails if we will have standalone header control but such cases are rare...
   HWND hWnd = GetParent( m_hWnd ); 
   GetClientRect( GetParent( m_hWnd ), &rc );
   ScreenToClient( GetParent( m_hWnd ), &point );
   // Test if mouse pointer is within the client area of the list control
   BOOL bInView = PtInRect( &rc, point );    

   GetClientRect( m_hWnd, &rc );
   rc.right = 0;
   GetCursorPos( &point );
   ScreenToClient( m_hWnd, &point );
   hDC = GetDC( m_hWnd );
   
   int nState;
   int nCount = SendMessage( m_hWnd, HDM_GETITEMCOUNT, 0, 0L );   

   for ( int i = 0; i < nCount; i++ )
   {
    #if (_WIN32_IE >= 0x0300)
      HDITEM hi;
      hi.mask = HDI_ORDER;
      SendMessage( m_hWnd, HDM_GETITEM, i, (LPARAM)&hi );
      SendMessage( m_hWnd, HDM_GETITEMRECT, hi.iOrder, (LPARAM)&rc );
    #else
      SendMessage( m_hWnd, HDM_GETITEMRECT, i, (LPARAM)&rc );
    #endif
      nState = 0;
      if ( bInView & PtInRect( &rc, point ) )
      {
         nState = dsHover;
       #if (_WIN32_IE >= 0x0300)
         m_nOldItem = hi.iOrder;
       #else
         m_nOldItem = i;
       #endif
      }
      DrawButton( hDC, rc, nState );
   }

   int l = rc.right;
   GetClientRect( m_hWnd, &rc );
   rc.left = l;
   DrawButton( hDC, rc, 0 );

   // If header is a child of ListView, redraw the list so 
   // it will indicate proper state      
   CCMControl* pCtl;   
   if ( g_ctrlManager.m_ctrlMap.Lookup( hWnd, (void*&)pCtl ) )
   {
      if ( m_nOldItem >= 0 )
         pCtl->SetState( 0, dsHover );
      else if ( nOldItem >= 0 )
         pCtl->SetState( dsHover, 0 );
   }

   ReleaseDC( m_hWnd, hDC );
}

BOOL CCoolControlsManager::CCMHeaderCtrl::NeedRedraw( const POINT& point )
{
   RECT rc;
   GetClientRect( m_hWnd, &rc );
   rc.right = 0;

   POINT pt = point;
   ScreenToClient( m_hWnd, &pt );

   int nItem = -1;
   int nCount = SendMessage( m_hWnd, HDM_GETITEMCOUNT, 0, 0L );

   for ( int i = 0; i < nCount; i++ )
   {
      HDITEM hi;
      hi.mask = HDI_WIDTH;      
      SendMessage( m_hWnd, HDM_GETITEM, i, (LPARAM)&hi );
      rc.left = rc.right;
      rc.right = rc.left + hi.cxy;
      if ( PtInRect( &rc, pt ) )
      {
         nItem = i;
         break;
      }
   }

   if ( m_hWnd != m_hWndOld || ( m_hWnd == m_hWndOld && m_nOldItem != nItem ) )
      return TRUE;
   return FALSE;
}

//////////////////////////////////////////////////////////////////////////////
// CCMTrackbar class

void CCoolControlsManager::CCMTrackbar::DrawThumb( HDC hDC, const RECT& rc )
{
   DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE );

   if ( dwStyle & TBS_BOTH )
   {
      FillSolidRect( hDC, rc, GetSysColor( COLOR_3DFACE ) );
      if ( m_nState & dsHoverMask )
         Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DDKSHADOW,
                                COLOR_3DLIGHT, COLOR_3DSHADOW );
      else
         Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DSHADOW,
                                COLOR_3DFACE, COLOR_3DFACE );      
      return;
   }
   
   HPEN penHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
   HPEN penLight = CreatePen( PS_SOLID, 1, GetSysColor( m_nState & dsHoverMask ? COLOR_3DLIGHT : COLOR_3DFACE ) );
   HPEN penDkShadow = CreatePen( PS_SOLID, 1, GetSysColor( m_nState & dsHoverMask ? COLOR_3DDKSHADOW : COLOR_3DSHADOW ) );
   HPEN penShadow = CreatePen( PS_SOLID, 1, GetSysColor( m_nState & dsHoverMask ? COLOR_3DSHADOW : COLOR_3DFACE ) );

   int n;
   if ( dwStyle & TBS_VERT )
   {
      if ( dwStyle & TBS_LEFT )
      {    
         n = ( rc.bottom - rc.top ) / 2 + 1;

⌨️ 快捷键说明

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