📄 coolcontrolsmanager.cpp
字号:
{
rc1.top += nScrollSize + nThumbPos;
rc1.bottom = rc1.top + nThumbSize;
}
else // SB_HORZ
{
rc1.left += nScrollSize + nThumbPos;
rc1.right = rc1.left + nThumbSize;
}
if ( nThumbSize <= nScrollArea ) // Don't draw the thumb when it's larger than the scroll area
DrawScrollbarThumb( hDC, rc1 );
}
}
BOOL CCoolControlsManager::CCMControl::IsFocused()
{
return m_hWnd == GetFocus() ? TRUE : FALSE;
}
//////////////////////////////////////////////////////////////////////////////
// CCMEdit class
void CCoolControlsManager::CCMEdit::DrawControl( HDC hDC, const RECT& rc )
{
RECT rect = rc;
// Check if edit window has an associated up-down control.
// If so draw a border around both controls
HWND hWnd = GetNextWindow( m_hWnd, GW_HWNDNEXT );
if ( hWnd )
{
TCHAR szBuf[MAX_CLASSNAME];
// Retrieve window class name
GetClassName( hWnd, szBuf, MAX_CLASSNAME );
if ( lstrcmpi( szBuf, _T( "msctls_updown32" ) ) == 0 ) // Up-down is found
{
DWORD dwStyle = GetWindowLong( hWnd, GWL_STYLE );
if ( ( dwStyle & UDS_ALIGNRIGHT || dwStyle & UDS_ALIGNLEFT ) &&
SendMessage( hWnd, UDM_GETBUDDY, 0, 0L ) == (LONG)m_hWnd )
{
RECT rc;
GetWindowRect( hWnd, &rc );
const int nEdge = GetSystemMetrics( SM_CXEDGE );
if ( dwStyle & UDS_ALIGNRIGHT )
rect.right += ( rc.right - rc.left ) - nEdge;
else // UDS_ALIGNLEFT
rect.left -= ( rc.right - rc.left ) - nEdge;
HDC hDC = GetDC( hWnd ); // We must draw the lines onto spin control DC
COLORREF clr = GetSysColor( m_nState & dsHoverMask ? COLOR_3DDKSHADOW : COLOR_3DHIGHLIGHT );
if ( !IsWindowEnabled( m_hWnd ) )
clr = GetSysColor( COLOR_3DFACE );
FillSolidRect( hDC, 1, 1, rc.right - rc.left - nEdge - 1, 1, clr );
if ( dwStyle & UDS_ALIGNLEFT )
FillSolidRect( hDC, 1, 1, 1, rc.bottom - rc.top - nEdge - 1, clr );
ReleaseDC( hWnd, hDC );
}
}
}
if ( GetWindowLong( m_hWnd, GWL_STYLE ) & ES_READONLY )
m_nState |= dsDisabled;
else
m_nState &= ~dsDisabled;
CCMControl::DrawControl( hDC, rect );
}
LRESULT CCoolControlsManager::CCMEdit::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
case WM_ENABLE:
{
CallWindowProc( m_oldWndProc, m_hWnd, uMsg, wParam, lParam );
DrawBorder();
HWND hWnd = GetNextWindow( m_hWnd, GW_HWNDNEXT );
if ( hWnd )
{
TCHAR szBuf[MAX_CLASSNAME];
// Retrieve window class name
GetClassName( hWnd, szBuf, MAX_CLASSNAME );
if ( lstrcmpi( szBuf, _T( "msctls_updown32" ) ) == 0 && // Up-down is found
SendMessage( hWnd, UDM_GETBUDDY, 0, 0L ) == (LONG)m_hWnd )
SendMessage( hWnd, WM_PAINT, 0, 0L ); // Repaint up-down too
}
}
return 0;
default:
return CCMControl::WindowProc( uMsg, wParam, lParam );
}
}
//////////////////////////////////////////////////////////////////////////////
// CCMComboBox class
void CCoolControlsManager::CCMComboBox::DrawControl( HDC hDC, const RECT& rect )
{
// First, draw borders around the control
CCMControl::DrawControl( hDC, rect );
// Now, we have to draw borders around the drop-down arrow
RECT rc = rect;
InflateRect( &rc, -2, -2 );
rc.left = rc.right - GetSystemMetrics( SM_CXHSCROLL );
if ( IsWindowEnabled( m_hWnd ) == TRUE )
{
if ( 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 );
}
else
Draw3dBorder( hDC, rc, COLOR_3DFACE, COLOR_3DFACE,
COLOR_3DFACE, COLOR_3DFACE );
}
BOOL CCoolControlsManager::CCMComboBox::IsFocused()
{
// Special case for drop-down and simple ComboBoxes
// which contain child edit control and focus always
// goes to that edit window
if ( ( GetWindowLong( m_hWnd, GWL_STYLE ) & 0x03 ) == CBS_DROPDOWN )
{
HWND hWnd = GetTopWindow( m_hWnd );
if ( hWnd && hWnd == GetFocus() )
return TRUE;
}
return CCMControl::IsFocused();
}
LRESULT CCoolControlsManager::CCMComboBox::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
// Drop-down ComboBox receives neither WM_SETFOCUS nor WM_KILLFOCUS
// Instead, it receives these next two messages
case WM_LBUTTONUP: // For kill focus
if ( lParam == -1 )
DrawBorder();
break;
case WM_COMMAND:
if ( HIWORD( wParam ) == EN_SETFOCUS )
DrawBorder();
break;
default:
return CCMControl::WindowProc( uMsg, wParam, lParam );
}
return CallWindowProc( m_oldWndProc, m_hWnd, uMsg, wParam, lParam );
}
//////////////////////////////////////////////////////////////////////////////
// CCMDateTime class
void CCoolControlsManager::CCMDateTime::DrawControl( HDC hDC, const RECT& rc )
{
if ( GetWindowLong( m_hWnd, GWL_STYLE ) & DTS_UPDOWN )
CCMControl::DrawControl( hDC, rc );
else
CCMComboBox::DrawControl( hDC, rc );
}
//////////////////////////////////////////////////////////////////////////////
// CCMPushButton class
void CCoolControlsManager::CCMPushButton::DrawControl( HDC hDC, const RECT& rc )
{
BOOL bDefault = FALSE;
// Unfortunately BS_DEFPUSHBUTTON is defined as 0x00000001L,
// and BS_OWNERDRAW as 0x0000000BL (see winuser.h) so we cannot
// determine the default button for owner-draw controls
DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE ) & BS_OWNERDRAW;
if ( dwStyle != BS_OWNERDRAW )
{
if ( dwStyle == BS_DEFPUSHBUTTON && IsWindowEnabled( m_hWnd ) )
bDefault = TRUE;
}
int nCheck = SendMessage( m_hWnd, BM_GETCHECK, 0, 0 );
if ( m_nState & dsHoverMask )
{
if ( bDefault == TRUE )
{
Draw3dBorder( hDC, rc, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW,
COLOR_3DHIGHLIGHT, COLOR_3DDKSHADOW,
COLOR_3DLIGHT, COLOR_3DSHADOW );
}
else
{
if ( nCheck )
Draw3dBorder( hDC, rc, COLOR_3DDKSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DSHADOW, COLOR_3DLIGHT );
else
Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DDKSHADOW,
COLOR_3DLIGHT, COLOR_3DSHADOW,
COLOR_3DFACE, COLOR_3DFACE );
}
}
else
{
if ( bDefault == TRUE )
{
Draw3dBorder( hDC, rc, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW,
COLOR_3DHIGHLIGHT, COLOR_3DSHADOW,
COLOR_3DFACE, COLOR_3DFACE );
}
else
{
if ( nCheck )
Draw3dBorder( hDC, rc, COLOR_3DSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DFACE, COLOR_3DFACE );
else
Draw3dBorder( hDC, rc, COLOR_3DHIGHLIGHT, COLOR_3DSHADOW,
COLOR_3DFACE, COLOR_3DFACE,
COLOR_3DFACE, COLOR_3DFACE );
}
}
}
LRESULT CCoolControlsManager::CCMPushButton::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
// Button messages
case BM_SETCHECK:
case WM_SETTEXT:
CallWindowProc( m_oldWndProc, m_hWnd, uMsg, wParam, lParam );
DrawBorder();
return 0;
default:
return CCMControl::WindowProc( uMsg, wParam, lParam );
}
}
//////////////////////////////////////////////////////////////////////////////
// CCMCheckBox class
void CCoolControlsManager::CCMCheckBox::DrawControl( HDC hDC, const RECT& rect )
{
DWORD dwStyle = GetWindowLong( m_hWnd, GWL_STYLE );
if ( dwStyle & BS_PUSHLIKE )
{
CCMPushButton::DrawControl( hDC, rect );
return;
}
RECT rc;
// Checkmark square size, hard coded here because I couldn't find any
// method to obtain this value from the system.
// Maybe someone else knows how to do it? If so, please let me know!
const int nCheckSize = 13;
if ( ( dwStyle & BS_VCENTER ) == BS_VCENTER )
rc.top = rect.top + ( ( rect.bottom - rect.top ) - nCheckSize ) / 2;
else if ( dwStyle & BS_TOP )
rc.top = rect.top + 1;
else if ( dwStyle & BS_BOTTOM )
rc.top = rect.bottom - nCheckSize - 2;
else // Default
rc.top = rect.top + ( ( rect.bottom - rect.top ) - nCheckSize ) / 2;
if ( dwStyle & BS_LEFTTEXT )
rc.left = rect.right - nCheckSize;
else
rc.left = rect.left;
rc.right = rc.left + nCheckSize;
rc.bottom = rc.top + nCheckSize;
if ( m_nState & dsHoverMask )
{
Draw3dBorder( hDC, rc, COLOR_3DDKSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DSHADOW, COLOR_3DFACE );
}
else
{
if ( IsWindowEnabled( m_hWnd ) == TRUE )
{
int nState = SendMessage( m_hWnd, BM_GETCHECK, 0, 0L );
Draw3dBorder( hDC, rc, COLOR_3DSHADOW, COLOR_3DHIGHLIGHT,
nState == 2 ? COLOR_3DHIGHLIGHT : COLOR_WINDOW,
nState == 2 ? COLOR_3DHIGHLIGHT : COLOR_WINDOW );
}
else
Draw3dBorder( hDC, rc, COLOR_3DSHADOW, COLOR_3DHIGHLIGHT,
COLOR_3DFACE, COLOR_3DFACE );
}
}
//////////////////////////////////////////////////////////////////////////////
// CCMRadioButton class
void CCoolControlsManager::CCMRadioButton::DrawFrame( POINT* ptArr, int nColor,
HDC hDC, int xOff, int yOff )
{
for ( int i = 0; ; i++ )
{
if ( !ptArr[i].x && !ptArr[i].y )
return;
SetPixel( hDC, ptArr[i].x + xOff, ptArr[i].y + yOff, GetSysColor( nColor ) );
}
}
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 );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -