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

📄 coolcontrolsmanager.cpp

📁 打印数据生成和模拟
💻 CPP
📖 第 1 页 / 共 5 页
字号:

//////////////////////////////////////////////////////////////////////////////
// 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;
			
			FillSolidRect( hDC, rc, GetSysColor( COLOR_3DFACE ) );
			
			HPEN hOldPen = (HPEN)SelectObject( hDC, penHighlight );
			MoveToEx( hDC, rc.right - 2, rc.top, NULL );
			LineTo( hDC, rc.left + n - 1, rc.top );
			LineTo( hDC, rc.left, rc.top + n - 1 );         
			
			SelectObject( hDC, penDkShadow );
			LineTo( hDC, rc.left + n - 1, rc.bottom - 1 );
			LineTo( hDC, rc.right - 1, rc.bottom - 1 );
			LineTo( hDC, rc.right - 1, rc.top - 1 );
			
			SelectObject( hDC, penLight );
			MoveToEx( hDC, rc.right - 3, rc.top + 1, NULL );
			LineTo( hDC, rc.left + n - 1, rc.top + 1 );
			LineTo( hDC, rc.left + 1, rc.top + n - 1 );
			
			SelectObject( hDC, penShadow );         
			LineTo( hDC, rc.left + n - 1, rc.bottom - 2 );
			LineTo( hDC, rc.right - 2, rc.bottom - 2 );
			LineTo( hDC, rc.right - 2, rc.top );
			
			SelectObject( hDC, hOldPen );         
		}
		else // TBS_RIGHT
		{
			n = ( rc.bottom - rc.top ) / 2 + 1;
			
			FillSolidRect( hDC, rc, GetSysColor( COLOR_3DFACE ) );
			
			HPEN hOldPen = (HPEN)SelectObject( hDC, penHighlight );
			MoveToEx( hDC, rc.left, rc.bottom - 2, NULL );
			LineTo( hDC, rc.left, rc.top );
			LineTo( hDC, rc.right - n, rc.top );
			LineTo( hDC, rc.right - 1, rc.top + n - 1 );
			
			SelectObject( hDC, penDkShadow );          
			MoveToEx( hDC, rc.left, rc.bottom - 1, NULL );
			LineTo( hDC, rc.right - n, rc.bottom - 1 );
			LineTo( hDC, rc.right, rc.top + n - 2 );         
			
			SelectObject( hDC, penLight );
			MoveToEx( hDC, rc.left + 1, rc.bottom - 3, NULL );
			LineTo( hDC, rc.left + 1, rc.top + 1 );
			LineTo( hDC, rc.right - n, rc.top + 1 );
			LineTo( hDC, rc.right - 2, rc.top + n - 1 );
			
			SelectObject( hDC, penShadow );
			MoveToEx( hDC, rc.left + 1, rc.bottom - 2, NULL );
			LineTo( hDC, rc.right - n, rc.bottom - 2 );
			LineTo( hDC, rc.right - 1, rc.top + n - 2 );         
			
			SelectObject( hDC, hOldPen );
		}      
	}
	else
	{
		if ( dwStyle & TBS_TOP )
		{      
			n = ( rc.right - rc.left ) / 2 + 1;
			
			FillSolidRect( hDC, rc, GetSysColor( COLOR_3DFACE ) );
			
			HPEN hOldPen = (HPEN)SelectObject( hDC, penHighlight );
			MoveToEx( hDC, rc.left + n - 2, rc.top + 1, NULL );
			LineTo( hDC, rc.left, rc.top + n - 1 );
			LineTo( hDC, rc.left, rc.bottom - 1 );
			
			SelectObject( hDC, penDkShadow );          
			LineTo( hDC, rc.right - 1, rc.bottom - 1 );
			LineTo( hDC, rc.right - 1, rc.top + n - 1 );
			LineTo( hDC, rc.left + n - 2, rc.top - 1 );
			
			SelectObject( hDC, penLight );
			MoveToEx( hDC, rc.left + n - 2, rc.top + 2, NULL );
			LineTo( hDC, rc.left + 1, rc.top + n - 1 );
			LineTo( hDC, rc.left + 1, rc.bottom - 2 );
			
			SelectObject( hDC, penShadow );
			LineTo( hDC, rc.right - 2, rc.bottom - 2 );
			LineTo( hDC, rc.right - 2, rc.top + n - 1 );
			LineTo( hDC, rc.left + n - 2, rc.top );
			
			SelectObject( hDC, hOldPen );
		}
		else // TBS_BOTTOM
		{
			n = ( rc.right - rc.left ) / 2 + 1;
			
			FillSolidRect( hDC, rc, GetSysColor( COLOR_3DFACE ) );
			
			HPEN hOldPen = (HPEN)SelectObject( hDC, penHighlight );
			MoveToEx( hDC, rc.left + n - 2, rc.bottom - 2, NULL );
			LineTo( hDC, rc.left, rc.bottom - n );
			LineTo( hDC, rc.left, rc.top );
			LineTo( hDC, rc.right - 1, rc.top );
			
			SelectObject( hDC, penDkShadow );          
			LineTo( hDC, rc.right - 1, rc.bottom - n );
			LineTo( hDC, rc.left + n - 2, rc.bottom );
			
			SelectObject( hDC, penLight );
			MoveToEx( hDC, rc.left + n - 2, rc.bottom - 3, NULL );
			LineTo( hDC, rc.left + 1, rc.bottom - n );
			LineTo( hDC, rc.left + 1, rc.top + 1 );
			LineTo( hDC, rc.right - 2, rc.top + 1 );
			
			SelectObject( hDC, penShadow );
			LineTo( hDC, rc.right - 2, rc.bottom - n );
			LineTo( hDC, rc.left + n - 2, rc.bottom - 1 );
			
			SelectObject( hDC, hOldPen );
		}
	}
	
	DeleteObject( penHighlight );
	DeleteObject( penLight );
	DeleteObject( penDkShadow );
	DeleteObject( penShadow );
}

void CCoolControlsManager::CCMTrackbar::DrawControl( HDC hDC, const RECT& /*rect*/ )
{  
	hDC = GetDC( m_hWnd );
	DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE );
	
	RECT rc;   
	SendMessage( m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)&rc );   
	
	// BUG!: Windows incorrectly calculates the channel rectangle for
	// sliders with TBS_VERT style, so we have to calculate the rectangle
	// in different manner. This bug appears on all Windows platforms!
	if ( dwStyle & TBS_VERT )
	{  
		int w = ( rc.right - rc.left );
		int h = ( rc.bottom - rc.top );
		rc.top = rc.left;
		rc.bottom = rc.left + w;
		
		RECT r;
		SendMessage( m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)&r );         
		
		rc.left = r.left + ( ( r.right - r.left ) / 2 + 1 ) - h / 2;

⌨️ 快捷键说明

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