?? chameleonctl.cpp
字號:
}
long CChameleonCtrl::GetAcceleratKey()
{
return (long)m_ucAccessKey;
}
/////////////////////////////////////////////////////////////////////////////
//
// 重繪函數(shù)
// 參數(shù): pdcDraw 繪圖場景
// nStatus 按鈕狀態(tài),0,正常;1,按下
// bForce 是否強(qiáng)制重畫
// 返回值: 0 正確
//
/////////////////////////////////////////////////////////////////////////////
int CChameleonCtrl::Redraw( int nStatus, bool bForce, CDC * pdcDraw )
{
BOOL bDefault;
bool bReleaseDC = false;
CString strCaption = InternalGetText();
CFont * pfntOld;
if( !bForce )
{
//如果當(dāng)前按鈕狀態(tài)未變化,文字也未變化,則取消不必要的重畫
if( m_nStatus == nStatus && m_strText == strCaption )
{
return 0;
}
}
//按鈕區(qū)域為空則退出
if( m_nHeight == 0 || m_nWidth == 0 )
{
return 0;
}
//保存按鈕狀態(tài)、文字
m_nStatus = nStatus;
m_strText = strCaption;
//獲取按鈕是否為Default按鈕
GetAmbientProperty( DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL, &bDefault );
//如果未傳入DC,則獲取控件DC
if( pdcDraw == NULL )
{
pdcDraw = GetDC();
bReleaseDC = true;
}
//選入STOCK FONT
pfntOld = SelectStockFont( pdcDraw );
//設(shè)置繪畫所需的各種表面顏色
SetColor();
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight, m_ulFace );
if( m_bEnabled )
{
if( m_nStatus == 0 )
{
//正常狀態(tài)
if( m_lButtonType == 1 )
{
//Windows16
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
DrawFrame( pdcDraw->m_hDC, m_ulHighLight, m_ulShadow,
m_ulHighLight, m_ulShadow, -1 );
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight,
m_ulDarkShadow, true );
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 2 )
{
//Windows32
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
if( bDefault && m_bShowFocusRect )
{
DrawFrame( pdcDraw->m_hDC, m_ulHighLight, m_ulDarkShadow,
m_ulLight, m_ulShadow, -1 );
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight,
m_ulDarkShadow, true );
}
else
{
DrawFrame( pdcDraw->m_hDC, m_ulHighLight, m_ulDarkShadow,
m_ulLight, m_ulShadow, 0 );
}
}
else if( m_lButtonType == 3 )
{
//WindowsXP
float fStep;
fStep = 25 / (float)m_nHeight;
for( int nCount = 1; nCount <= m_nHeight; nCount++ )
{
DrawLine( pdcDraw->m_hDC, 0, nCount, m_nWidth,
nCount, ShiftColor( m_ulXPFace, (int)(-fStep * nCount), true ) );
}
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight, 0x733C00, true );
SetPixel( pdcDraw->m_hDC, 1, 1, 0x7B4D10 );
SetPixel( pdcDraw->m_hDC, 1, m_nHeight - 2, 0x7B4D10 );
SetPixel( pdcDraw->m_hDC, m_nWidth - 2, 1, 0x7B4D10 );
SetPixel( pdcDraw->m_hDC, m_nWidth - 2, m_nHeight - 2, 0x7B4D10 );
if( m_bMouseOver )
{
DrawRectangle( pdcDraw->m_hDC, 1, 2,
m_nWidth - 2, m_nHeight - 4, 0x31B2FF, true );
DrawLine( pdcDraw->m_hDC, 2, m_nHeight - 2,
m_nWidth - 2, m_nHeight - 2, 0x96E7 );
DrawLine( pdcDraw->m_hDC, 2, 1, m_nWidth - 2, 1, 0xCEF3FF );
DrawLine( pdcDraw->m_hDC, 1, 2, m_nWidth - 1, 2, 0x8CDBFF );
DrawLine( pdcDraw->m_hDC, 2, 3, 2, m_nHeight - 3, 0x6BCBFF );
DrawLine( pdcDraw->m_hDC, m_nWidth - 3,
3, m_nWidth - 3, m_nHeight - 3, 0x6BCBFF );
}
else if( ( m_bFocus || bDefault ) && m_bShowFocusRect )
{
DrawRectangle( pdcDraw->m_hDC, 1, 2,
m_nWidth - 2, m_nHeight - 4, 0xE7AE8C, true );
DrawLine( pdcDraw->m_hDC, 2, m_nHeight - 2,
m_nWidth - 2, m_nHeight - 2, 0xEF826B );
DrawLine( pdcDraw->m_hDC, 2, 1, m_nWidth - 2, 1, 0xFFE7CE );
DrawLine( pdcDraw->m_hDC, 1, 2, m_nWidth - 1, 2, 0xF7D7BD );
DrawLine( pdcDraw->m_hDC, 2, 3, 2, m_nHeight - 3, 0xF0D1B5 );
DrawLine( pdcDraw->m_hDC, m_nWidth - 3, 3,
m_nWidth - 3, m_nHeight - 3, 0xF0D1B5 );
}
else
{
DrawLine( pdcDraw->m_hDC, 2, m_nHeight - 2,
m_nWidth - 2, m_nHeight - 2, ShiftColor( m_ulXPFace, -0x30, true ) );
DrawLine( pdcDraw->m_hDC, 1, m_nHeight - 3,
m_nWidth - 2, m_nHeight - 3, ShiftColor( m_ulXPFace, -0x20, true ) );
DrawLine( pdcDraw->m_hDC, m_nWidth - 2, 2,
m_nWidth - 2, m_nHeight - 2, ShiftColor( m_ulXPFace, -0x24, true ) );
DrawLine( pdcDraw->m_hDC, m_nWidth - 3, 3,
m_nWidth - 3, m_nHeight - 3, ShiftColor( m_ulXPFace, -0x18, true ) );
DrawLine( pdcDraw->m_hDC, 2, 1,
m_nWidth - 2, 1, ShiftColor( m_ulXPFace, 0x10, true ) );
DrawLine( pdcDraw->m_hDC, 1, 2,
m_nWidth - 2, 2, ShiftColor( m_ulXPFace, 0x0A, true ) );
DrawLine( pdcDraw->m_hDC, 1, 2, 1, m_nHeight - 2,
ShiftColor( m_ulXPFace, -0x05, true ) );
DrawLine( pdcDraw->m_hDC, 2, 3, 2, m_nHeight - 3,
ShiftColor( m_ulXPFace, -0x0A, true ) );
}
}
else if( m_lButtonType == 4 )
{
//Mac
DrawRectangle( pdcDraw->m_hDC, 1, 1,
m_nWidth - 2, m_nHeight - 2, m_ulLight );
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight,
m_ulDarkShadow, true );
SetPixel( pdcDraw->m_hDC, 1, 1, m_ulDarkShadow );
SetPixel( pdcDraw->m_hDC, 1, m_nHeight - 2, m_ulDarkShadow );
SetPixel( pdcDraw->m_hDC, m_nWidth - 2, 1, m_ulDarkShadow );
SetPixel( pdcDraw->m_hDC, m_nWidth - 2, m_nHeight - 2, m_ulDarkShadow );
DrawLine( pdcDraw->m_hDC, 1, 2, 2, 0, m_ulFace );
DrawLine( pdcDraw->m_hDC, 3, 2, m_nWidth - 3, 2, m_ulHighLight );
DrawLine( pdcDraw->m_hDC, 2, 2, 2, m_nHeight - 3, m_ulHighLight );
SetPixel( pdcDraw->m_hDC, 3, 3, m_ulHighLight );
DrawLine( pdcDraw->m_hDC, m_nWidth - 3, 1,
m_nWidth - 3, m_nHeight - 3, m_ulFace );
DrawLine( pdcDraw->m_hDC, 1, m_nHeight - 3,
m_nWidth - 3, m_nHeight - 3, m_ulFace );
SetPixel( pdcDraw->m_hDC, m_nWidth - 4, m_nHeight - 4, m_ulFace );
DrawLine( pdcDraw->m_hDC, m_nWidth - 2, 2,
m_nWidth - 2, m_nHeight - 2, m_ulShadow );
DrawLine( pdcDraw->m_hDC, 2, m_nHeight - 2,
m_nWidth - 2, m_nHeight - 2, m_ulShadow );
SetPixel( pdcDraw->m_hDC, m_nWidth - 3, m_nHeight - 3, m_ulShadow );
}
else if( m_lButtonType == 5 )
{
//Java
DrawRectangle( pdcDraw->m_hDC, 1, 1, m_nWidth - 1, m_nHeight - 1,
ShiftColor( m_ulFace, 0x0C ) );
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
DrawRectangle( pdcDraw->m_hDC, 1, 1, m_nWidth - 1, m_nHeight - 1,
m_ulHighLight, true );
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth - 1, m_nHeight - 1,
ShiftColor( m_ulShadow, -0x1A ), true );
SetPixel( pdcDraw->m_hDC, 1, m_nHeight - 2,
ShiftColor( m_ulShadow, 0x1A ) );
SetPixel( pdcDraw->m_hDC, m_nWidth - 2, 1,
ShiftColor( m_ulShadow, 0x1A ) );
if( m_bFocus && m_bShowFocusRect )
{
DrawRectangle( pdcDraw->m_hDC, m_recText.left - 2, m_recText.top -1,
m_recText.Width() + 4, m_recText.Height() + 2, 0xCC9999, true );
}
}
else if( m_lButtonType == 6 )
{
//Netscape6
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
DrawFrame( pdcDraw->m_hDC, ShiftColor( m_ulLight, 0x08 ),
m_ulShadow, ShiftColor( m_ulLight, 0x08 ), m_ulShadow, 0 );
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 7 )
{
//SimpleFlat
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
DrawFrame( pdcDraw->m_hDC, m_ulHighLight, m_ulShadow, 0, 0, 0, true );
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 8 )
{
//FlatHight
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
if( m_bMouseOver )
{
DrawFrame( pdcDraw->m_hDC, m_ulHighLight, m_ulShadow, 0, 0, 0, true );
}
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 9 )
{
//OfficeXP
if( m_bMouseOver )
{
DrawRectangle( pdcDraw->m_hDC, 1, 1, m_nWidth, m_nHeight,
m_ulOfficeXPF );
}
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
if( m_bMouseOver )
{
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight,
m_ulOfficeXPB, true );
}
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 10 )
{
/*
//Transparent
CRect recClient;
POINT pntPos;
CDC * pdcParent;
pntPos.x = 0;
pntPos.y = 0;
GetClientRect( recClient );
pdcParent = GetParent()->GetDC();
CBitmap * pbmpOld;
BITMAP uBmp;
memset( &uBmp, 0, sizeof(BITMAP) );
pbmpOld = pdcParent->GetCurrentBitmap();
pbmpOld->GetBitmap( &uBmp );
memset( &uBmp, 0, sizeof(BITMAP) );
pbmpOld = pdcDraw->GetCurrentBitmap();
pbmpOld->GetBitmap( &uBmp );
MapWindowPoints( GetParent(), &pntPos, 1 );
pdcDraw->BitBlt( 0, 0, recClient.Width(), recClient.Height(),
pdcParent, pntPos.x, pntPos.y, SRCCOPY );
pdcDraw->SelectObject( pbmpOld );
GetParent()->ReleaseDC( pdcParent );
*/
}
else if( m_lButtonType == 11 )
{
//Hover
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
if( m_bMouseOver )
{
DrawFrame( pdcDraw->m_hDC, m_ulHighLight, m_ulDarkShadow,
m_ulLight, m_ulShadow, 0, false );
}
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 12 )
{
//KDE2
CFont fntBold;
CFont * pfntCur;
CFont * pfntOld = NULL;
float fStep;
if( m_bMouseOver )
{
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight, m_ulLight );
}
else
{
fStep = 58 / (float)m_nHeight;
for( int nCount = 1; nCount <= m_nHeight; nCount++ )
{
DrawLine( pdcDraw->m_hDC, 0, nCount, m_nWidth, nCount,
ShiftColor( m_ulHighLight, (int)(-fStep * nCount) ) );
}
}
if( bDefault )
{
LOGFONT uLogFont;
pfntCur = pdcDraw->GetCurrentFont();
pfntCur->GetLogFont( &uLogFont );
uLogFont.lfWeight = FW_BOLD;
if( fntBold.CreateFontIndirect( &uLogFont ) )
{
pfntOld = pdcDraw->SelectObject( &fntBold );
}
}
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
if( bDefault )
{
if( pfntOld != NULL )
{
pdcDraw->SelectObject( pfntOld );
}
}
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight,
ShiftColor( m_ulShadow, -0x32 ), true );
DrawRectangle( pdcDraw->m_hDC, 1, 1, m_nWidth - 2, m_nHeight - 2,
ShiftColor( m_ulFace, -0x09 ), true );
DrawRectangle( pdcDraw->m_hDC, 2, 2, m_nWidth - 4, 2, m_ulHighLight );
DrawRectangle( pdcDraw->m_hDC, 2, 4, 2, m_nHeight - 6, m_ulHighLight );
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
}
else if( m_lButtonType == 13 )
{
//Graphic
int nPicWidth;
int nPicHeight;
CRect recRender;
CRect recWBounds;
if( m_bMouseOver )
{
GetPictureSize( 3, nPicWidth, nPicHeight );
if( nPicWidth != 0 && nPicHeight != 0 )
{
recRender.left = 0;
recRender.top = 0;
if( m_bStretch )
{
recRender.right = m_nWidth;
recRender.bottom = m_nHeight;
}
else
{
recRender.right = nPicWidth;
recRender.bottom = nPicHeight;
}
recWBounds.left = 0;
recWBounds.top = 0;
recWBounds.right = nPicWidth;
recWBounds.bottom = nPicHeight;
m_phdOverPicture.Render( pdcDraw, recRender, recWBounds );
}
}
else
{
GetPictureSize( 1, nPicWidth, nPicHeight );
if( nPicWidth != 0 && nPicHeight != 0 )
{
recRender.left = 0;
recRender.top = 0;
if( m_bStretch )
{
recRender.right = m_nWidth;
recRender.bottom = m_nHeight;
}
else
{
recRender.right = nPicWidth;
recRender.bottom = nPicHeight;
}
recWBounds.left = 0;
recWBounds.top = 0;
recWBounds.right = nPicWidth;
recWBounds.bottom = nPicHeight;
m_phdPicture.Render( pdcDraw, recRender, recWBounds );
}
}
if( m_bMouseOver )
{
DrawCaption( pdcDraw->m_hDC, 1 );
}
else
{
DrawCaption( pdcDraw->m_hDC, 0 );
}
}
}
else if( m_nStatus == 1 )
{
//Press狀態(tài)
if( m_lButtonType == 1 )
{
//Windows16
DrawCaption( pdcDraw->m_hDC, 2 );
DrawFrame( pdcDraw->m_hDC, m_ulShadow, m_ulHighLight,
m_ulShadow, m_ulHighLight, -1 );
DrawRectangle( pdcDraw->m_hDC, 0, 0, m_nWidth, m_nHeight,
m_ulDarkShadow, true );
DrawFocusR( pdcDraw->m_hDC, m_recFocusRect, m_ulText );
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -