?? coolcontrolsmanager.cpp
字號(hào):
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;
if ( dwStyle & TBS_LEFT )
;
else if ( dwStyle & TBS_BOTH )
rc.left -= 1;
else
rc.left -= 2;
rc.right = rc.left + h;
}
// Draw the channel rect
if ( m_nState & dsHoverMask )
Draw3dBorder( hDC, rc, COLOR_3DSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DDKSHADOW, COLOR_3DLIGHT );
else
Draw3dBorder( hDC, rc, COLOR_3DSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DFACE, COLOR_3DFACE );
// Draw the slider thumb
if ( !( dwStyle & TBS_NOTHUMB ) )
{
SetRectEmpty( &rc );
SendMessage( m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)&rc );
DrawThumb( hDC, rc );
}
ReleaseDC( m_hWnd, hDC );
}
//////////////////////////////////////////////////////////////////////////////
// CCMToolbar class
void CCoolControlsManager::CCMToolbar::DrawButton( HDC hDC, const RECT& rc, int nState )
{
if ( nState & bsChecked )
{
if ( nState & bsHover )
Draw3dBorder( hDC, rc,
COLOR_3DDKSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DSHADOW, COLOR_3DSHADOW );
else
Draw3dBorder( hDC, rc,
COLOR_3DSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DFACE, COLOR_3DFACE );
}
else
{
if ( nState & bsHover )
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::CCMToolbar::DrawControl( HDC hDC, const RECT& /*rc*/ )
{
if ( GetWindowLong( m_hWnd, GWL_STYLE ) & TBSTYLE_FLAT ) // Skip flat toolbars
return;
int nCount = SendMessage( m_hWnd, TB_BUTTONCOUNT, 0, 0L );
hDC = GetDC( m_hWnd ); // We will draw toolbar buttons on the client DC
POINT point;
GetCursorPos( &point );
ScreenToClient( m_hWnd, &point );
m_nOldItem = -1;
int nState = 0;
for ( int i = 0; i < nCount; i++ )
{
RECT rc;
TBBUTTON ti;
SendMessage( m_hWnd, TB_GETBUTTON, i, (LPARAM)&ti );
SendMessage( m_hWnd, TB_GETITEMRECT, i, (LPARAM)&rc );
if ( !( ti.fsStyle & TBSTYLE_SEP ) )
{
nState = ( ti.fsState & TBSTATE_CHECKED ) ? bsChecked : bsNormal;
if ( PtInRect( &rc, point ) == TRUE )
{
if ( ti.fsState & TBSTATE_ENABLED )
nState |= bsHover;
m_nOldItem = i;
}
DrawButton( hDC, rc, nState );
}
}
ReleaseDC( m_hWnd, hDC );
}
BOOL CCoolControlsManager::CCMToolbar::NeedRedraw( const POINT& point )
{
int nCount = SendMessage( m_hWnd, TB_BUTTONCOUNT, 0, 0L );
POINT pt = point;
ScreenToClient( m_hWnd, &pt );
int nItem = -1;
for ( int i = 0; i < nCount; i++ )
{
TBBUTTON ti;
SendMessage( m_hWnd, TB_GETBUTTON, i, (LPARAM)&ti );
if ( !( ti.fsStyle & TBSTYLE_SEP ) )
{
RECT rc;
SendMessage( m_hWnd, TB_GETITEMRECT, i, (LPARAM)&rc );
if ( PtInRect( &rc, pt ) )
{
nItem = i;
break;
}
}
}
if ( m_hWnd != m_hWndOld || ( m_hWnd == m_hWndOld && m_nOldItem != nItem ) )
return TRUE;
return FALSE;
}
LRESULT CCoolControlsManager::CCMToolbar::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case WM_PAINT:
case WM_NCPAINT:
m_nOldItem = -1; // Redraw the whole toolbar unconditionally
default:
return CCMControl::WindowProc( uMsg, wParam, lParam );
}
}
//////////////////////////////////////////////////////////////////////////////
// CCMTabControl class
void CCoolControlsManager::CCMTabControl::DrawTab( HDC hDC, const RECT& rect,
int nItem, int nState )
{
RECT rc = rect;
int nCurSel = SendMessage( m_hWnd, TCM_GETCURSEL, 0, 0L );
if ( nCurSel == -1 )
nCurSel = -2;
switch ( GetOrientation() )
{
case tabLeft:
if ( nState & bsChecked )
{
rc.top -= 2;
rc.bottom += 2;
rc.left -= 2;
rc.right += 1;
}
if ( nState & bsHover )
{
if ( nCurSel != nItem - 1 )
{
FillSolidRect( hDC, rc.left+2, rc.top, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+2, rc.top+1, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DLIGHT ) );
SetPixel( hDC, rc.left+1, rc.top+1, GetSysColor( COLOR_3DHIGHLIGHT ) );
}
FillSolidRect( hDC, rc.left, rc.top+2, 1, rc.bottom-rc.top-4, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+1, rc.top+2, 1, rc.bottom-rc.top-4, GetSysColor( COLOR_3DLIGHT ) );
if ( nCurSel != nItem + 1 )
{
FillSolidRect( hDC, rc.left+2, rc.bottom-1, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DDKSHADOW ) );
FillSolidRect( hDC, rc.left+2, rc.bottom-2, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DSHADOW ) );
SetPixel( hDC, rc.left+1, rc.bottom-2, GetSysColor( COLOR_3DDKSHADOW ) );
}
}
else
{
if ( nCurSel != nItem - 1 )
{
FillSolidRect( hDC, rc.left+2, rc.top, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+2, rc.top+1, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DFACE ) );
SetPixel( hDC, rc.left+1, rc.top+1, GetSysColor( COLOR_3DHIGHLIGHT ) );
}
FillSolidRect( hDC, rc.left, rc.top+2, 1, rc.bottom-rc.top-4, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+1, rc.top+2, 1, rc.bottom-rc.top-4, GetSysColor( COLOR_3DFACE ) );
if ( nCurSel != nItem + 1 )
{
FillSolidRect( hDC, rc.left+2, rc.bottom-1, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DSHADOW ) );
FillSolidRect( hDC, rc.left+2, rc.bottom-2, rc.right-rc.left-2, 1, GetSysColor( COLOR_3DFACE ) );
SetPixel( hDC, rc.left+1, rc.bottom-2, GetSysColor( COLOR_3DSHADOW ) );
}
}
break;
case tabTop:
if ( nState & bsChecked )
{
rc.top -= 2;
rc.bottom += 1;
rc.left -= 2;
rc.right += 2;
}
if ( nState & bsHover )
{
if ( nCurSel != nItem - 1 )
{
FillSolidRect( hDC, rc.left, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+1, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DLIGHT ) );
SetPixel( hDC, rc.left+1, rc.top+1, GetSysColor( COLOR_3DHIGHLIGHT ) );
}
FillSolidRect( hDC, rc.left+2, rc.top, rc.right-rc.left-4, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+2, rc.top+1, rc.right-rc.left-4, 1, GetSysColor( COLOR_3DLIGHT ) );
if ( nCurSel != nItem + 1 )
{
FillSolidRect( hDC, rc.right-1, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DDKSHADOW ) );
FillSolidRect( hDC, rc.right-2, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DSHADOW ) );
SetPixel( hDC, rc.right-2, rc.top+1, GetSysColor( COLOR_3DDKSHADOW ) );
}
}
else
{
if ( nCurSel != nItem - 1 )
{
FillSolidRect( hDC, rc.left, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+1, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DFACE ) );
SetPixel( hDC, rc.left+1, rc.top+1, GetSysColor( COLOR_3DHIGHLIGHT ) );
}
FillSolidRect( hDC, rc.left+2, rc.top, rc.right-rc.left-4, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
FillSolidRect( hDC, rc.left+2, rc.top+1, rc.right-rc.left-4, 1, GetSysColor( COLOR_3DFACE ) );
if ( nCurSel != nItem + 1 )
{
FillSolidRect( hDC, rc.right-1, rc.top+2, 1, rc.bottom-rc.top-2, GetSysColor( COLOR_3DSHADOW ) );
FillSolidRect( hDC, rc.right-2, rc.top
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -