📄 creditstatic.cpp
字号:
if (!m_bProcessingBitmap)
{
UINT fontAlign = DT_TOP | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE;
char c;
c = '\0';
if (!m_szWork.IsEmpty())
c = m_szWork[m_szWork.GetLength()-1];
if(bCheck)
{
// get text width
CSize size = memDC.GetTextExtent((LPCTSTR)m_szWork, m_szWork.GetLength()- rmcode);
if(size.cx > n_MaxWidth)
{
n_MaxWidth = (size.cx > m_ScrollRect.Width())? m_ScrollRect.Width() : size.cx;
m_ClientRect.left = (m_ScrollRect.Width()-n_MaxWidth)/2;
m_ClientRect.right = m_ClientRect.left + n_MaxWidth;
if (!m_szWork.IsEmpty())
{
/*
if (c == m_Escapes[LEFT_ALIGN1])
{
m_ClientRect.left = 0;//(LONG)((m_ScrollRect.Width()-n_MaxWidth)*0.10);
m_ClientRect.right = m_ClientRect.left + size.cx;
fontAlign = DT_TOP | DT_NOPREFIX | DT_SINGLELINE;
} else if (c == m_Escapes[LEFT_ALIGN2])
{
m_ClientRect.left = 0;//(LONG)((m_ScrollRect.Width()-n_MaxWidth)*0.20);
m_ClientRect.right = m_ClientRect.left + size.cx;
fontAlign = DT_TOP | DT_NOPREFIX | DT_SINGLELINE;
}
*/
}
}
}
else
{
CSize size = memDC.GetTextExtent((LPCTSTR)m_szWork, m_szWork.GetLength()- rmcode);
if (c == m_Escapes[LEFT_ALIGN1])
{
m_ClientRect.left = (LONG)((m_ScrollRect.Width())*0.10);
m_ClientRect.right = m_ClientRect.left + size.cx;
fontAlign = DT_TOP | DT_NOPREFIX | DT_SINGLELINE;
} else if (c == m_Escapes[LEFT_ALIGN2])
{
m_ClientRect.left = (LONG)((m_ScrollRect.Width())*0.20);
m_ClientRect.right = m_ClientRect.left + size.cx;
fontAlign = DT_TOP | DT_NOPREFIX | DT_SINGLELINE;
}
}
CRect r(m_ClientRect);
r.top = r.bottom-m_nClip;
int x = memDC.DrawText((const char *)m_szWork,m_szWork.GetLength()-rmcode,&r, fontAlign);
m_bDrawText=FALSE;
}
else
{
// a bitmap is in the loop
if(bCheck) {
CSize size = memDC.GetTextExtent((LPCTSTR)m_szWork,m_szWork.GetLength()-rmcode);
if(m_size.cx > n_MaxWidth)
{
n_MaxWidth = (m_size.cx > m_ScrollRect.Width())? m_ScrollRect.Width():m_size.cx;
m_ClientRect.left = (m_ScrollRect.Width()-n_MaxWidth)/2;
m_ClientRect.right = m_ClientRect.left + n_MaxWidth;
}
}
CRect r( m_pt.x, m_pt.y-m_nClip, m_pt.x+ m_size.cx, m_pt.y);
DrawBitmap(&memDC, &memDC2, &r);
// memDC.BitBlt( m_pt.x, m_pt.y-m_nClip, m_size.cx, m_nClip,
// &memDC2, 0, 0, SRCCOPY );
if (m_nClip >= m_size.cy)
{
m_bmpWork.DeleteObject();
m_bProcessingBitmap = FALSE;
m_nClip=0;
m_szWork.Empty();
m_nCounter=1;
}
}
if (pOldMemDC2Bitmap != NULL) memDC2.SelectObject(pOldMemDC2Bitmap);
if (pOldFont != NULL) memDC.SelectObject(pOldFont);
memDC.SelectObject(pOldMemDCBitmap);
}
// ------------------------------ DrawCredit ----------------------------------
// Draws if no background bitmap used, if one is specified, this func
// does nothing.
void CCreditStatic::DrawCredit(CDC* pDC, CRect& m_ScrollRect)
{
if(m_BmpMain.m_hObject != NULL) //background bitmap ?
return;
CDC memDC,memDC2;
memDC.CreateCompatibleDC(pDC);
memDC2.CreateCompatibleDC(pDC);
COLORREF BackColor = (m_bTransparent && m_bitmap.m_hObject != NULL)? RGB(192,192,192) : m_Colors[BACKGROUND_COLOR];
CBitmap *pOldMemDCBitmap = NULL;
m_BmpMain.CreateCompatibleBitmap( pDC, m_ScrollRect.Width(), m_ScrollRect.Height() );
pOldMemDCBitmap = (CBitmap*)memDC.SelectObject(&m_BmpMain);
if(m_Gradient && m_bitmap.m_hObject == NULL)
FillGradient(&memDC, &m_ScrollRect, &m_ScrollRect, m_Colors[BACKGROUND_COLOR]);
else
memDC.FillSolidRect(&m_ScrollRect, BackColor);
POSITION pos = m_ArrCredit.GetHeadPosition();
int height = 0;
while(pos != NULL && height <= m_ScrollRect.Height())
{
CString m_szWork = m_ArrCredit.GetNext(pos);
CFont m_fntArial;
CFont *pOldFont = NULL;
CBitmap *pOldMemDC2Bitmap = NULL;
CDC memDC2;
memDC2.CreateCompatibleDC(pDC);
//*********************************************************************
// FONT SELECTION
BOOL bSuccess = FALSE;
BOOL bIsBitmap = FALSE;
UINT fontAlign = DT_TOP | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE;
BOOL bUnderline;
BOOL bItalic;
int rmcode = 0;
CBitmap bitmap;
if (!m_szWork.IsEmpty()) {
char c = m_szWork[m_szWork.GetLength()-1];
if(c == m_Escapes[TOP_LEVEL_GROUP])
{
rmcode = 1;
bItalic = FALSE;
bUnderline = FALSE;
m_nCurrentFontHeight = m_TextHeights[TOP_LEVEL_GROUP];
bSuccess = m_fntArial.CreateFont(m_TextHeights[TOP_LEVEL_GROUP], 0, 0, 0,
FW_BOLD, bItalic, bUnderline, 0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | 0x04 | FF_DONTCARE,
(LPSTR)"Arial");
memDC.SetTextColor(m_Colors[TOP_LEVEL_GROUP_COLOR]);
pOldFont = memDC.SelectObject(&m_fntArial);
}
else if(c == m_Escapes[GROUP_TITLE])
{
rmcode = 1;
bItalic = FALSE;
bUnderline = FALSE;
m_nCurrentFontHeight = m_TextHeights[GROUP_TITLE];
bSuccess = m_fntArial.CreateFont(m_TextHeights[GROUP_TITLE], 0, 0, 0,
FW_BOLD, bItalic, bUnderline, 0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | 0x04 | FF_DONTCARE,
(LPSTR)"Arial");
memDC.SetTextColor(m_Colors[GROUP_TITLE_COLOR]);
pOldFont = memDC.SelectObject(&m_fntArial);
}
else if(c == m_Escapes[TOP_LEVEL_TITLE])
{
rmcode = 1;
bItalic = FALSE;
// bUnderline = TRUE;
bUnderline = FALSE;
m_nCurrentFontHeight = m_TextHeights[TOP_LEVEL_TITLE];
bSuccess = m_fntArial.CreateFont(m_TextHeights[TOP_LEVEL_TITLE], 0, 0, 0,
FW_BOLD, bItalic, bUnderline, 0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | 0x04 | FF_DONTCARE,
(LPSTR)"Arial");
memDC.SetTextColor(m_Colors[TOP_LEVEL_TITLE_COLOR]);
pOldFont = memDC.SelectObject(&m_fntArial);
}
else if(c == m_Escapes[DISPLAY_BITMAP])
{
CString szBitmap = m_szWork.Left(m_szWork.GetLength()-1);
if(bitmap.LoadBitmap((const char *)szBitmap)) {
BITMAP m_bmpInfo;
bitmap.GetObject(sizeof(BITMAP), &m_bmpInfo);
m_size.cx = m_bmpInfo.bmWidth; // width of dest rect
m_size.cy = m_bmpInfo.bmHeight;
// upper left point of dest
m_pt.x = (m_ScrollRect.right -
((m_ScrollRect.Width())/2) - (m_size.cx/2));
m_pt.y = height;
pOldMemDC2Bitmap = memDC2.SelectObject(&bitmap);
bIsBitmap = TRUE;
}
else
c = ' ';
}
else if ((c == m_Escapes[LEFT_ALIGN1]) ||
(c == m_Escapes[LEFT_ALIGN2]) ||
(c == m_Escapes[NORMAL_CENTER]))
{ // default case, no formatting for this line
rmcode = 1;
bItalic = FALSE;
bUnderline = FALSE;
m_nCurrentFontHeight = m_TextHeights[NORMAL_CENTER];
bSuccess = m_fntArial.CreateFont(m_TextHeights[NORMAL_CENTER], 0, 0, 0,
FW_THIN, bItalic, bUnderline, 0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | 0x04 | FF_DONTCARE,
(LPSTR)"Arial");
memDC.SetTextColor(m_Colors[NORMAL_TEXT_COLOR]);
pOldFont = memDC.SelectObject(&m_fntArial);
fontAlign = DT_TOP | DT_NOPREFIX | DT_SINGLELINE;
}
}
memDC.SetBkMode(TRANSPARENT);
if (!bIsBitmap)
{
CRect r(m_ScrollRect);
r.top = height;
CSize size;
if(m_szWork.GetLength()-rmcode != 0)
{
int x = memDC.DrawText((const char *)m_szWork,m_szWork.GetLength()-rmcode, &r, fontAlign);
size = memDC.GetTextExtent((LPCTSTR)m_szWork,m_szWork.GetLength()-rmcode);
}
else
size = memDC.GetTextExtent((LPCTSTR)"W",1);
height += size.cy;
}
else
{
CRect r( m_pt.x, m_pt.y, m_pt.x + m_size.cx, m_pt.y + m_size.cy);
DrawBitmap(&memDC, &memDC2, &r);
// memDC.BitBlt( m_pt.x, m_pt.y, m_size.cx, m_size.cy, &memDC2, 0, 0, SRCCOPY );
height += m_size.cy;
}
if (pOldMemDC2Bitmap != NULL) memDC2.SelectObject(pOldMemDC2Bitmap);
if (pOldFont != NULL) memDC.SelectObject(pOldFont);
}
memDC.SelectObject(pOldMemDCBitmap);
}
void CCreditStatic::OnDestroy()
{
CStatic::OnDestroy();
m_ArrCredit.RemoveAll();
if(TimerOn)
ASSERT(KillTimer(DISPLAY_TIMER_ID));
}
BOOL CCreditStatic::SetBkImage(UINT nIDResource)
{
return SetBkImage( (LPCTSTR)nIDResource );
}
BOOL CCreditStatic::SetBkImage(LPCTSTR lpszResourceName)
{
// If this is not the first call then Delete GDI objects
if( m_bitmap.m_hObject != NULL )
m_bitmap.DeleteObject();
if( m_pal.m_hObject != NULL )
m_pal.DeleteObject();
HBITMAP hBmp = (HBITMAP)::LoadImage( AfxGetInstanceHandle(),
lpszResourceName, IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION );
if( hBmp == NULL )
return FALSE;
m_bitmap.Attach( hBmp );
BITMAP bm;
m_bitmap.GetBitmap( &bm );
m_cxBitmap = bm.bmWidth;
m_cyBitmap = bm.bmHeight;
// Create a logical palette for the bitmap
DIBSECTION ds;
BITMAPINFOHEADER &bmInfo = ds.dsBmih;
m_bitmap.GetObject( sizeof(ds), &ds );
int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << bmInfo.biBitCount;
// Create a halftone palette if colors > 256.
CClientDC dc(NULL); // Desktop DC
if( nColors > 256 )
m_pal.CreateHalftonePalette( &dc );
else
{
// Create the palette
RGBQUAD *pRGB = new RGBQUAD[nColors];
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOldMemDCBitmap = memDC.SelectObject( &m_bitmap );
::GetDIBColorTable( memDC, 0, nColors, pRGB );
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries = nColors;
for( int i=0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = pRGB[i].rgbRed;
pLP->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
pLP->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
}
m_pal.CreatePalette( pLP );
memDC.SelectObject(pOldMemDCBitmap);
delete[] pLP;
delete[] pRGB;
}
// Invalidate();
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -