📄 extpaintmanager.cpp
字号:
// static CCriticalSection statCsQueryMsimg32;
// statCsQueryMsimg32.Lock();
// stat_hModuleMsimg32 = ::GetModuleHandle( _T("Msimg32.dll") );
// if( stat_hModuleMsimg32 != NULL )
// {
// ASSERT( pMsimg32_TransparentBlt == NULL );
// pMsimg32_TransparentBlt = (pMsimg32_TransparentBlt_t)
// ::GetProcAddress( stat_hModuleMsimg32, _T("TransparentBlt") );
// }
// statCsQueryMsimg32.Unlock();
// }
// if( pMsimg32_TransparentBlt != NULL )
// {
// VERIFY(
// pMsimg32_TransparentBlt(
// hdcDest, // handle to destination DC
// nXOriginDest, // x-coord of destination upper-left corner
// nYOriginDest, // y-coord of destination upper-left corner
// nWidthDest, // width of destination rectangle
// hHeightDest, // height of destination rectangle
// hdcSrc, // handle to source DC
// nXOriginSrc, // x-coord of source upper-left corner
// nYOriginSrc, // y-coord of source upper-left corner
// nWidthSrc, // width of source rectangle
// nHeightSrc, // height of source rectangle
// crTransparent // color to make transparent
// )
// );
// return;
// }
CDC dcdst, dcsrc;
dcdst.Attach( hdcDest );
dcsrc.Attach( hdcSrc );
CExtMemoryDC dcmm( &dcdst ), dcmsk( &dcdst, NULL, CExtMemoryDC::MDCOPT_TO_MEMORY|CExtMemoryDC::MDCOPT_FORCE_BLACK );
if( ( nWidthDest != nWidthSrc || hHeightDest != nHeightSrc ) && nWidthDest >= 0 && hHeightDest >= 0 )
dcmm.StretchBlt( 0, 0, nWidthDest, hHeightDest, &dcsrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY );
else dcmm.BitBlt( 0, 0, nWidthSrc, nHeightSrc, &dcsrc, nXOriginSrc, nYOriginSrc, SRCCOPY );
int nRealWidthDest = (nWidthDest < 0) ? nWidthSrc : nWidthDest;
int nRealHeightDest = (hHeightDest < 0) ? nHeightSrc : hHeightDest;
dcmm.SetBkColor( crTransparent );
dcmsk.BitBlt( 0, 0, nRealWidthDest, nRealHeightDest, &dcmm, 0, 0, SRCCOPY );
dcmm.SetBkColor( RGB(0,0,0) );
dcmm.SetTextColor( RGB(255,255,255) );
dcmm.BitBlt( 0, 0, nRealWidthDest, nRealHeightDest, &dcmsk, 0, 0, SRCAND );
dcdst.SetBkColor( RGB(255,255,255) );
dcdst.SetTextColor( RGB(0,0,0) );
dcdst.BitBlt( nXOriginDest, nYOriginDest, nRealWidthDest, nRealHeightDest, &dcmsk, 0, 0, SRCAND );
dcdst.BitBlt( nXOriginDest, nYOriginDest, nRealWidthDest, nRealHeightDest, &dcmm, 0, 0, SRCPAINT );
dcmm.__Flush( FALSE );
dcmsk.__Flush( FALSE );
dcdst.Detach();
dcsrc.Detach();
}
// generate DIB for UI light brush (when BPP <=8)
HBITMAP CExtPaintManager::stat_GenLBDIB()
{
CWindowDC dcAlign( NULL );
CDC dc;
if( !dc.CreateCompatibleDC( &dcAlign ) )
{
ASSERT( FALSE );
return NULL;
}
CBitmap bmp;
if( !bmp.CreateCompatibleBitmap( &dcAlign, 16, 16 ) )
{
ASSERT( FALSE );
return NULL;
}
CBitmap * pOldBmp = dc.SelectObject( &bmp );
COLORREF clr0 = ::GetSysColor( COLOR_BTNFACE );
COLORREF clr1 = ::GetSysColor( COLOR_BTNHIGHLIGHT );
for( int nY = 0; nY < 16; nY++ )
{
for( int nX = 0; nX < 16; nX++ )
{
COLORREF clr = (nY&0x01)
? ( (nX&0x01) ? clr0 : clr1 )
: ( (nX&0x01) ? clr1 : clr0 )
;
dc.SetPixel( nX, nY, clr );
}
}
dc.SelectObject( pOldBmp );
return (HBITMAP)bmp.Detach();
}
void CExtPaintManager::stat_PaintGradientRect(
CDC & dc,
const CRect & rcPaintGradient,
COLORREF clrLeft,
COLORREF clrRight,
bool bHorz, // = false
UINT nCountOfSteps // = 256
)
{
if( rcPaintGradient.left >= rcPaintGradient.right
|| rcPaintGradient.top >= rcPaintGradient.bottom
)
return;
ASSERT( nCountOfSteps > 0 && nCountOfSteps <= 256 );
UINT nWidth = rcPaintGradient.Width();
UINT nHeight = rcPaintGradient.Height();
if( bHorz )
{
if( nCountOfSteps > nHeight )
nCountOfSteps = nHeight;
}
else
{
if( nCountOfSteps > nWidth )
nCountOfSteps = nWidth;
}
int nBitsPerPixel = stat_GetBPP();
if( nBitsPerPixel <= 8 )
{
UINT nCalcStepSize =
bHorz
? nHeight / nCountOfSteps
: nWidth / nCountOfSteps
;
static const UINT nLowColorStepMinSize = 4;
if( nCalcStepSize < nLowColorStepMinSize )
nCountOfSteps =
bHorz
? nHeight / nLowColorStepMinSize
: nWidth / nLowColorStepMinSize
;
} // if( nBitsPerPixel <= 8 )
CRect rcItem( rcPaintGradient );
for( UINT nStep = 0, nBackStep = nCountOfSteps;
nStep < nCountOfSteps;
nStep++, nBackStep--
)
{
COLORREF clrItem =
RGB(
( GetRValue(clrLeft)*nBackStep
+ GetRValue(clrRight)*nStep
) / nCountOfSteps,
( GetGValue(clrLeft)*nBackStep
+ GetGValue(clrRight)*nStep
) / nCountOfSteps,
( GetBValue(clrLeft)*nBackStep
+ GetBValue(clrRight)*nStep
) / nCountOfSteps
);
if( bHorz )
{
rcItem.top =
rcPaintGradient.bottom -
MulDiv( nStep, nHeight, nCountOfSteps )
;
rcItem.top--;
if( nStep == nCountOfSteps
&& rcItem.top < rcPaintGradient.top
)
{
rcItem.top = rcPaintGradient.top;
if( rcItem.top >= rcItem.bottom )
break;
}
ASSERT( rcItem.Height() >= 1 );
if( nBitsPerPixel <= 8 )
{
CBrush br( clrItem );
dc.FillRect( rcItem, &br );
} // if( nBitsPerPixel <= 8 )
else
{
dc.FillSolidRect( rcItem, clrItem );
} // else from if( nBitsPerPixel <= 8 )
rcItem.bottom = rcItem.top;
}
else
{
rcItem.right =
MulDiv( nStep, nWidth, nCountOfSteps )
+ rcPaintGradient.left
;
rcItem.right++;
if( nStep == nCountOfSteps
&& rcItem.right > rcPaintGradient.right
)
{
rcItem.right = rcPaintGradient.right;
if( rcItem.right <= rcItem.left )
break;
}
ASSERT( rcItem.Width() >= 1 );
if( nBitsPerPixel <= 8 )
{
CBrush br( clrItem );
dc.FillRect( rcItem, &br );
} // if( nBitsPerPixel <= 8 )
else
{
dc.FillSolidRect( rcItem, clrItem );
} // else from if( nBitsPerPixel <= 8 )
rcItem.left = rcItem.right;
}
}
}
void CExtPaintManager::SyncSysColors()
{
ASSERT( this != NULL );
// init fonts
HFONT hDefaultGuiFont =
(HFONT)::GetStockObject(DEFAULT_GUI_FONT);
if( hDefaultGuiFont == NULL )
hDefaultGuiFont =
(HFONT)::GetStockObject(SYSTEM_FONT);
ASSERT( hDefaultGuiFont != NULL );
if( m_FontNormal.GetSafeHandle() )
m_FontNormal.Detach();
m_FontNormal.Attach( hDefaultGuiFont );
static LPCTSTR sVertFontFaceForNt4 = _T("Arial");
LOGFONT lf;
VERIFY( m_FontNormal.GetLogFont(&lf) );
lf.lfWeight = 900;
if( m_FontBold.GetSafeHandle() )
m_FontBold.DeleteObject();
VERIFY( m_FontBold.CreateFontIndirect(&lf) );
VERIFY( m_FontNormal.GetLogFont(&lf) );
lf.lfCharSet = SYMBOL_CHARSET;
lf.lfWeight = 0;
lf.lfHeight = ::GetSystemMetrics(SM_CYMENUCHECK) - 1;
_tcscpy( lf.lfFaceName, _T("Marlett") );
if( m_FontMarlett.GetSafeHandle() )
m_FontMarlett.DeleteObject();
VERIFY( m_FontMarlett.CreateFontIndirect(&lf) );
VERIFY( m_FontNormal.GetLogFont(&lf) );
lf.lfEscapement = __VERT_FONT_ESCAPEMENT__;
if( m_FontNormalVert.GetSafeHandle() )
m_FontNormalVert.DeleteObject();
if( g_PaintManager.m_bIsWinNT4 || g_PaintManager.m_bIsWin9x )
_tcscpy( lf.lfFaceName, sVertFontFaceForNt4 );
VERIFY( m_FontNormalVert.CreateFontIndirect(&lf) );
lf.lfEscapement = __VERT_FONT_ESCAPEMENT_X__;
if( m_FontNormalVertX.GetSafeHandle() )
m_FontNormalVertX.DeleteObject();
if( g_PaintManager.m_bIsWinNT4 || g_PaintManager.m_bIsWin9x )
_tcscpy( lf.lfFaceName, sVertFontFaceForNt4 );
VERIFY( m_FontNormalVertX.CreateFontIndirect(&lf) );
VERIFY( m_FontBold.GetLogFont(&lf) );
lf.lfEscapement = __VERT_FONT_ESCAPEMENT__;
if( m_FontBoldVert.GetSafeHandle() )
m_FontBoldVert.DeleteObject();
if( g_PaintManager.m_bIsWinNT4 || g_PaintManager.m_bIsWin9x )
_tcscpy( lf.lfFaceName, sVertFontFaceForNt4 );
VERIFY( m_FontBoldVert.CreateFontIndirect(&lf) );
lf.lfEscapement = __VERT_FONT_ESCAPEMENT_X__;
if( m_FontBoldVertX.GetSafeHandle() )
m_FontBoldVertX.DeleteObject();
if( g_PaintManager.m_bIsWinNT4 || g_PaintManager.m_bIsWin9x )
_tcscpy( lf.lfFaceName, sVertFontFaceForNt4 );
VERIFY( m_FontBoldVertX.CreateFontIndirect(&lf) );
/// init colors
int i;
COLORREF clrDefaultExtendColor =
::GetSysColor(COLOR_3DFACE);
for( i = m_colors.GetSize();
i <= __ExtMfc_MAX_SYS_COLOR_VAL;
i++
)
{
m_colors.Add( clrDefaultExtendColor );
}
HBRUSH hDefaultExtendBrush =
::GetSysColorBrush(COLOR_3DFACE);
for( i = m_brushes.GetSize();
i <= __ExtMfc_MAX_SYS_COLOR_VAL;
i++
)
{
m_brushes.Add( hDefaultExtendBrush );
}
//m_colors.clear();
//m_brushes.clear();
for( i = __ExtMfc_MIN_SYS_COLOR_VAL;
i <= __ExtMfc_MAX_SYS_COLOR_VAL;
i++
)
{
m_colors[i] = ::GetSysColor(i);
m_brushes[i] = ::GetSysColorBrush(i);
}
ASSERT( m_colors.GetSize() >= __ExtMfc_MAX_SYS_COLOR_VAL+1 );
ASSERT( m_brushes.GetSize() >= __ExtMfc_MAX_SYS_COLOR_VAL+1 );
if( m_brushLight.GetSafeHandle() != NULL )
m_brushLight.DeleteObject();
int nBitsPerPixel = stat_GetBPP();
if(nBitsPerPixel > 8)
{
COLORREF clrBtnFace = GetColor(COLOR_3DFACE);
COLORREF clrBtnHilite = GetColor(COLOR_3DHILIGHT);
COLORREF clrLight = RGB (
GetRValue(clrBtnFace) + ((GetRValue(clrBtnHilite) -
GetRValue(clrBtnFace)) / 2 ),
GetGValue(clrBtnFace) + ((GetGValue(clrBtnHilite) -
GetGValue(clrBtnFace)) / 2),
GetBValue(clrBtnFace) + ((GetBValue(clrBtnHilite) -
GetBValue(clrBtnFace)) / 2)
);
m_brushLight.CreateSolidBrush( clrLight );
}
else
{
HBITMAP hbmGray = stat_GenLBDIB();
ASSERT( hbmGray != NULL) ;
CBitmap bmp;
bmp.Attach( hbmGray );
m_brushLight.CreatePatternBrush( &bmp );
}
}
// get any system color based brush
HBRUSH CExtPaintManager::GetBrush(
int nColorIndex
)
{
int nBrushesCount = m_brushes.GetSize();
if(
!(
__ExtMfc_MIN_SYS_COLOR_VAL <= nColorIndex
&&
nColorIndex < nBrushesCount
)
)
{
ASSERT( FALSE );
nColorIndex = COLOR_3DFACE;
}
HBRUSH hBrush = m_brushes[nColorIndex];
return hBrush;
}
COLORREF CExtPaintManager::GetColor(int nColorIndex)
{
ASSERT( this != NULL );
if( nColorIndex >= __ExtMfc_COLOR_MAP_BASE )
{
int nColorIndex2 = 0;
if( m_mapColorTranslate.Lookup(
nColorIndex,
nColorIndex2
)
)
nColorIndex = nColorIndex2;
else
{
ASSERT( FALSE );
nColorIndex = COLOR_3DFACE;
}
}
int nColorCount = m_colors.GetSize();
if(
!(
__ExtMfc_MIN_SYS_COLOR_VAL <= nColorIndex
&&
nColorIndex < nColorCount // <= __ExtMfc_MAX_SYS_COLOR_VAL
)
)
{
ASSERT( FALSE );
nColorIndex = COLOR_3DFACE;
}
COLORREF clr = m_colors[nColorIndex];
return clr;
}
int CExtPaintManager::InstallColor(
COLORREF clr,
int nColorIndex // = -1
)
{
ASSERT( this != NULL );
int nColorCount = m_colors.GetSize();
if( nColorIndex < 0 || nColorIndex >= nColorCount )
{
nColorIndex = m_colors.Add( clr );
}
else
m_colors[nColorIndex] = clr;
return nColorIndex;
}
void CExtPaintManager::InitTranslatedColors()
{
ASSERT( this != NULL );
m_mapColorTranslate.RemoveAll();
m_mapColorTranslate[CLR_3DFACE_OUT] = COLOR_3DFACE;
m_mapColorTranslate[CLR_3DFACE_IN] = COLOR_3DFACE;
m_mapColorTranslate[CLR_3DFACE_DISABLED] = COLOR_3DFACE;
m_mapColorTranslate[CLR_3DLIGHT_OUT] = COLOR_3DLIGHT;
m_mapColorTranslate[CLR_3DLIGHT_IN] = COLOR_3DLIGHT;
m_mapColorTranslate[CLR_3DLIGHT_DISABLED] = COLOR_3DLIGHT;
m_mapColorTranslate[CLR_3DHILIGHT_OUT] = COLOR_3DHILIGHT;
m_mapColorTranslate[CLR_3DHILIGHT_IN] = COLOR_3DHILIGHT;
m_mapColorTranslate[CLR_3DHILIGHT_DISABLED] = COLOR_3DHILIGHT;
m_mapColorTranslate[CLR_3DSHADOW_OUT] = COLOR_3DSHADOW;
m_mapColorTranslate[CLR_3DSHADOW_IN] = COLOR_3DSHADOW;
m_mapColorTranslate[CLR_3DSHADOW_DISABLED] = COLOR_3DSHADOW;
m_mapColorTranslate[CLR_3DDKSHADOW_OUT] = COLOR_3DDKSHADOW;
m_mapColorTranslate[CLR_3DDKSHADOW_IN] = COLOR_3DDKSHADOW;
m_mapColorTranslate[CLR_3DDKSHADOW_DISABLED] = COLOR_3DDKSHADOW;
m_mapColorTranslate[CLR_TEXT_OUT] = COLOR_BTNTEXT;
m_mapColorTranslate[CLR_TEXT_IN] = COLOR_BTNTEXT;
m_mapColorTranslate[CLR_TEXT_DISABLED] = COLOR_3DSHADOW;
}
static const UINT stat_pixels_dock_btn_empty[] =
{
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_btn_close[] =
{
0,0,0,0,0,0,0,0,0,
0,1,1,0,0,0,0,1,1,
0,0,1,1,0,0,1,1,0,
0,0,0,1,1,1,1,0,0,
0,0,0,0,1,1,0,0,0,
0,0,0,1,1,1,1,0,0,
0,0,1,1,0,0,1,1,0,
0,1,1,0,0,0,0,1,1,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_btn_close_dc2k[] =
{
0,0,0,0,0,0,0,0,0,
0,1,1,0,0,0,1,1,0,
0,0,1,1,0,1,1,0,0,
0,0,0,1,1,1,0,0,0,
0,0,0,1,1,1,0,0,0,
0,0,1,1,0,1,1,0,0,
0,1,1,0,0,0,1,1,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_btn_thin_close[] =
{
0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,1,0,
0,0,1,0,0,0,1,0,0,
0,0,0,1,0,1,0,0,0,
0,0,0,0,1,0,0,0,0,
0,0,0,1,0,1,0,0,0,
0,0,1,0,0,0,1,0,0,
0,1,0,0,0,0,0,1,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_btn_arrow_up[] =
{
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,
0,0,0,1,1,1,0,0,0,
0,0,1,1,1,1,1,0,0,
0,1,1,1,1,1,1,1,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_btn_hollow_up[] =
{
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,
0,0,0,1,0,1,0,0,0,
0,0,1,0,0,0,1,0,0,
0,1,0,0,0,0,0,1,0,
1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_btn_arrow_up_l[] =
{
0,0,0,0,1,0,0,0,0,
0,0,0,1,1,1,0,0,0,
0,0,1,1,1,1,1,0,0,
0,1,1,1,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,
0,0,1,1,1,1,1,0,0,
0,0,1,1,1,1,1,0,0,
0,0,1,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_wnd_minimize[] =
{
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_wnd_restore[] =
{
0,0,1,1,1,1,1,1,0,
0,0,1,0,0,0,0,1,0,
1,1,1,1,1,1,0,1,0,
1,1,1,1,1,1,0,1,0,
1,0,0,0,0,1,1,1,0,
1,0,0,0,0,1,0,0,0,
1,0,0,0,0,1,0,0,0,
1,1,1,1,1,1,0,0,0,
0,0,0,0,0,0,0,0,0,
};
static const UINT stat_pixels_dock_wnd_maximize[] =
{
1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,
};
static const UINT stat_pixels_dock_wnd_keep[] =
{
0,0,1,1,1,1,1,0,0,
0,0,1,0,0,1,1,0,0,
0,0,1,0,0,1,1,0,0,
0,0,1,0,0,1,1,0,0,
0,0,1,0,0,1,1,0,0,
0,1,1,1,1,1,1,1,0,
0,0,0,0,1,0,0,0,0,
0,0,0,0,1,0,0,0,0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -